import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ActionListenerTest extends JFrame implements ActionListener
{
Container cp;
JButton btn_OK;
JButton btn_NO;
JLabel lbl;
public ActionListenerTest(String title)
{
super(title);
cp = getContentPane();
initMember();
makeGUI();
this.setBounds(300,200,200,100);
this.setVisible(true);
}
// 멤버 초기화
public void initMember()
{
btn_OK = new JButton("확인");
btn_NO = new JButton("취소");
lbl = new JLabel("===액션이벤트 테스트===");
}
// GUI 설정
public void makeGUI()
{
cp.add(lbl, BorderLayout.NORTH);
JPanel pnl = new JPanel(new FlowLayout());
pnl.add(btn_OK);
pnl.add(btn_NO);
cp.add(pnl);
// 액션 리스너 추가
btn_OK.addActionListener(this);
btn_NO.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if ( ae.getSource()==btn_OK )
{
JOptionPane.showMessageDialog(this, "확인버튼을 눌렀음");
} else if ( ae.getSource()==btn_NO )
{
JOptionPane.showMessageDialog(this, "취소버튼을 눌렀음");
}
}
public static void main(String[] args)
{
new ActionListenerTest("액션 리스너 예제");
}
}
'JAVA/JSP > Source' 카테고리의 다른 글
servlet + ibatis + ajax sample (0) | 2008.07.25 |
---|---|
JOptionPane (0) | 2008.07.15 |
그림판 (0) | 2008.07.15 |
substance look&feel colorchart (0) | 2008.07.14 |
substance look&feel 사용예 (0) | 2008.07.14 |