package GUI;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class IndepClasssListener extends JFrame {
public IndepClasssListener() {
setTitle("Action 이벤트 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JButton btn = new JButton("Action");
btn.addActionListener(new MyActionListener());
c.add(btn);
setSize(350,150);
setVisible(true);
}
public static void main(String[] args) {
new IndepClasssListener();
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
if(b.getText().equals("Action"))
b.setText("액션");
else
b.setText("Action");
}
}
}