Swing中的標準對話框
/**?* @(#)TestJOptionPane.java
?*
?* TestJOptionPane application
?*
?* @author
?* @version 1.00 2007/1/22
?*/
?import javax.swing.*;
?import javax.swing.event.*;
?import java.awt.event.*;
public class TestJOptionPane extends JFrame
{
?String strValue=null;
??? public TestJOptionPane()
??? {
??? ?JOptionPane.showMessageDialog(/*this*/null,"程序已開始運行...","運行",JOptionPane.DEFAULT_OPTION);
??? ?JTextArea jta=new JTextArea();
??? ?JScrollPane jsp=new JScrollPane();
??? ?jsp.getViewport().add(jta);
??? ?this.getContentPane().add(jsp);
??? ?this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
??? ?strValue=JOptionPane.showInputDialog(null,"請輸入姓名:");
??? ?//jta.setText(strValue);
??? ?jta.append(strValue);
??? ?addWindowListener(new WindowAdapter()
??? ?{
??? ??public void windowClosing(WindowEvent e)
??? ??{
??? ???if(JOptionPane.OK_OPTION==JOptionPane.showConfirmDialog(TestJOptionPane.this,"確認要退出程序嗎?","Exit",JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE))
??? ???{
??? ????e.getWindow().dispose();
??? ???}
??? ???
??? ??}
??? ?});
??? ?
??? }
??? public static void main(String[] args)
??? {
??? ?
??? ?// TODO, add your application code
??? ?System.out.println("Hello World!");
??? ?TestJOptionPane mainFrame=new TestJOptionPane();
??? ?mainFrame.setTitle("TestJOptionPane");
??? ?mainFrame.setBounds(300,200,400,400);
??? ?mainFrame.setVisible(true);
??? }
}
posted on 2007-01-22 01:32 大頭劍客 閱讀(169) 評論(0) 編輯 收藏 所屬分類: 學習筆記