1) Frame 클래스를 확장하여 응용 프로그램을 생성
*
import java.awt.*;
import java.awt.event.*;public class FrameExtender extends Frame {
public FrameExtender() {
addWindowListener(new WinCloser ());
setTitle("Just a Frame");
setBounds(100, 100, 200, 200);
setVisible(true);
}
public static void main(String args[]) {
FrameExtender fe = new FrameExtender();
}
}class WinCloser extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}*
2) main()메소드에서 Frame객체를 생성
*
import java.awt.*;
import java.awt.event.*;public class FrameInstantiater {
public FrameInstantiater() { }
public static void main(String[] args) {
Frame frame1= new Frame();
frame1.addWindowListener(new WinCloser());
frame1.setTitle("An Instantiated Frame");
frame1.setBounds(100,100,300,300);
frame1.setVisible(true);
}
}class WinCloser extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}*
3) 직접 Frame에 GUI객체를 첨부하는 Frame의 add()메소드를 사용
(프레임에 객체를 위치시키는 가장 간단한 방법)
*
import java.awt.*;
import java.awt.event.*;public class TextFieldInstantiater {
public TextFieldInstantiater() { }
public static void main(String[] args) {
Frame frame1= new Frame();
//텍스트 필드의 생성과 삽입
TextField tf1 = new TextField("Directly on the Frame");
TextField tf2 = new TextField("On the of the old text");
frame1.add(tf1); //위치지정 없음
frame1.add(tf2);
frame1.addWindowListener(new WinCloser());
frame1.setTitle("An Instantiated Frame");
frame1.setBounds(100,100,300,300);
frame1.setVisible(true);
}
}class WinCloser extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}*