Java 9일차 ActionListener 테스트3 (외부이벤트)

EvetnTest3.java

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class EventTest3 extends JFrame
{
static JTextArea ta;
JButton button;

public EventTest3()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,300);
setVisible(true);

ta = new JTextArea();

button = new JButton("클릭");

InheritanceEventTest ie =new InheritanceEventTest();
button.addActionListener(ie);

add(ta);
add("North", button);
}

public static void main(String[] args)
{
new EventTest3();
}
}

InheritanceEventTest.java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class InheritanceEventTest implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
EventTest3.ta.append("외부이벤트"+'\n');
}
}


댓글 없음: