U E D R , A S I H C RSS

Button/상욱

~cpp 

import javax.swing.*;
import java.awt.event.*;

public class Test extends JFrame implements ActionListener
{
	JButton button1;
	JButton button2;
	
	public Test() {
		super("Test");
		
		button1 = new JButton("BUTTON1");
		button1.addActionListener(this);
		
		button2 = new JButton("BUTTON2");
		button2.addActionListener(this);
		
		JPanel panel = new JPanel();
		panel.add(button1);
		panel.add(button2);
		
		getContentPane().add(panel);
		
	}
	public static void main(String[] args){
		
		JFrame f = new Test();
		f.setSize(250,70);
		f.setVisible(true);
	}

	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == button1) {
			JOptionPane.showMessageDialog(this, "Dialog 1", "1",
			JOptionPane.YES_NO_OPTION,null);
		}
		
		else if (ae.getSource() == button2) {
			JOptionPane.showMessageDialog(this, "Dialog 2", "2",
			JOptionPane.YES_NO_OPTION,null);		
		}
	}
};

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:40
Processing time 0.0094 sec