JoptionPane 대화 상자 데모

2201 단어 프레임swing
package Assis;

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

public class OptionPaneDemo extends JFrame implements ActionListener {
	private static final long serialVersionUID = 1L;
	//         
	JButton btnMessage = new JButton("       ");
	JButton btnConfirm = new JButton("       ");
	JButton btnInput = new JButton("       ");
	JButton btnOption = new JButton("       ");

	public OptionPaneDemo() {
		//         
		super("JOptionPaneDemo Demo");
		//               
		btnMessage.addActionListener(this);
		btnConfirm.addActionListener(this);
		btnInput.addActionListener(this);
		btnOption.addActionListener(this);
		//              FlowLayout
		getContentPane().setLayout(new FlowLayout());
		//                
		getContentPane().add(btnMessage);
		getContentPane().add(btnConfirm);
		getContentPane().add(btnInput);
		getContentPane().add(btnOption);
		//       
		pack();
		setVisible(true);
	}

	//        
	public static void main(String[] args) {
		OptionPaneDemo frame = new OptionPaneDemo();
		//            (      )
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

	//       
	public void actionPerformed(ActionEvent e) {
		Object objCommand = e.getSource();

		if (objCommand == btnMessage)
			JOptionPane.showMessageDialog(this, "         ");
		else if (objCommand == btnConfirm)
			JOptionPane.showConfirmDialog(this, "         ");
		else if (objCommand == btnInput)
			JOptionPane.showInputDialog(this, "         ");
		else {
			Object[] options = { "  ", "  " };
			JOptionPane.showOptionDialog(this, "        ", "       ",
					JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null,
					options, options[0]);
		}

	}
}

좋은 웹페이지 즐겨찾기