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 大头剑客 阅读(165) 评论(0)  编辑  收藏 所属分类: 学习笔记


只有注册用户登录后才能发表评论。


网站导航:
 
<2025年2月>
2627282930311
2345678
9101112131415
16171819202122
2324252627281
2345678

导航

统计

公告

写字楼里写字间,写字间里程序员;
程序人员写程序,又拿程序换酒钱;
酒醒只在网上坐,酒醉还来网下眠;
酒醉酒醒日复日,网上网下年复年;
但愿老死电脑间,不愿鞠躬老板前;
奔驰宝马贵者趣,公交自行程序员;
别人笑我忒疯癫,我笑自己命太贱;
不见满街漂亮妹,哪个归得程序员.
不管前面是地雷阵还是万丈深渊,
我都将勇往直前,义无反顾,
鞠躬尽瘁,死而后已。
—— 朱镕基总理

常用链接

留言簿(1)

随笔档案

文章分类

文章档案

学习园地

最新随笔

搜索

积分与排名

最新评论