566
No
class FrameTest
package java8;
import javax.swing.JFrame;
public class FrameTest {
//프레임 객체 생성
public static void main(String[] args) {
JFrame f =new JFrame("프레임 연습");
//프레임의 사이즈 설정
f.setSize(300, 200);
//프레임 닫기 동작
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//프레임을 화면에 표시
f.setVisible(true);
}
}
class MyFrameTest
package java8;
import java.awt.FlowLayout;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class MyFrameTest extends JFrame{
//생성자
public MyFrameTest(){
//현재 와면의 배치방법 변경
setLayout(new FlowLayout());
// 버튼 추가
JButton button1=new JButton("button");
add(button1);
//레이블 추가
JLabel label1=new JLabel("버튼을 클릭하세요");
add(label1);
//이름이 없는 클래스 - 무명 (익명) 클래스
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//레이블.setText("레이블의 내용");
label1.setText("버튼이 눌렀습니다");
}
});
setSize(300, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("프레임 테스트");
setVisible(true);
}
public static void main(String[] args) {
//객체가 생성되면서 인스턴트 호출
new MyFrameTest();
}
}
class InterfaceExam
package java8;
interface A {
public void print();
}
public class InterfaceExam {
public static void main(String[] args) {
A a =new A(){
public void print(){
System.out.println("익명 객체");
};
};
a.print();
}
}
댓글 ( 4)
댓글 남기기