import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.*;
import javax.swing.*;
public class JFrameTest extends JFrame implements WindowListener, ActionListener{
public JFrameTest(){
//JFrame f = new JFrame();
setTitle("윈도우 타이틀");
setSize(500, 400); //윈도우창 크기 지정
addWindowListener(this);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = super.getContentPane();//컨테이너를 가져와서 컨테이너에 컴포넌트 담는다
c.setLayout(new FlowLayout()); //FlowLayout : 배치방식 지정
JButton butn = new JButton();
butn.addActionListener(this); //버튼 눌렀을 때 이루어지는 것을 action event라고 한다.
//actionlistener 추가
butn.setText("버튼");
//위 두줄과 JButton butn = new JButton("버튼"); 은 같다.
c.add(butn); //button 넣어준다.
JLabel label = new JLabel();
label.setText("라벨");
c.add(label); //label 넣어준다.
setVisible(true);
}
public static void main(String[] ar){
new JFrameTest();
}
//윈도우 변화 이벤트에 따라 호출 (Ctrl+1)
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("버튼 눌렀당ㅇㅇ");
// TODO Auto-generated method stub
}
}