프레임을 이용하기 위해서는 Frame 클래스 상속 받아야합니다.
자바와 gui의 관련된 개념에 대한 설명은 다음링크를 참조하시기 바랍니다.
Copy public class MyWindow1 extends Frame
Copy Button button1;
Button button2;
Panel panel;
Copy button1 . addActionListener ( new ActionListener() {
public void actionPerformed ( ActionEvent e) {
System . out . println ( e . getSource ());
}
});
setLayout(layout유형); layout유형은 다음의 유형들과 같습니다.
SungjukFrame.java - 기본사항 코딩
Copy package StudentManagerProject;
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class SungjukFrame extends Frame implements WindowListener{
Label idLabel,nameLabel,hpLabel;
TextField idTextField,nameTextField,hpTextField;
Button confirmButton;
Panel infoInputPanel;
public SungjukFrame() {
idLabel=new Label("학번");
nameLabel=new Label("이름");
hpLabel=new Label("전화번호");
idTextField=new TextField(10);
nameTextField=new TextField(10);
hpTextField=new TextField(10);
confirmButton=new Button("확인");
infoInputPanel=new Panel();
infoInputPanel.setLayout(new GridLayout(4,2,10,10));
infoInputPanel.add(idLabel);
infoInputPanel.add(idTextField);
infoInputPanel.add(nameLabel);
infoInputPanel.add(nameTextField);
infoInputPanel.add(hpLabel);
infoInputPanel.add(hpTextField);
infoInputPanel.add(confirmButton);
add(infoInputPanel);
idLabel.setAlignment(Label.CENTER);
nameLabel.setAlignment(Label.CENTER);
hpLabel.setAlignment(Label.CENTER);
infoInputPanel.setBackground(Color.yellow);
setBounds(100,100,500,200);
setVisible(true);
//리스너 등록
addWindowListener(this);
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
}