我在同一个package里定义了两个application Window,分别是s和a。我现在在s中定义一个按钮,想点击这个按钮后,a就显示,是怎么弄的啊,谢谢。

解决方案 »

  1.   

    SWT是吗
    点击按钮的时候添加widgetSelected事件响应
    在里面new出来a就可以了
    不过a定义成Dialog
    这样可以a开的时候s是阻塞的,而且a关闭的时候返回一些东西
      

  2.   

    2楼正解 先添加按扭的响应事件 事件代码中new出另一个窗口
      

  3.   

    setVisible~和s中显示一个button是一样的
      

  4.   

    点击s中的按钮时,new一个a,然后show之
      

  5.   

    在s里:
    ===========================
    public class s extends javax.swing.JFrame {public s() {
            initComponents();
        }private void initComponents() {
       jButton1 = new javax.swing.JButton();
    }jButton1.setText("Show a");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         
                JFrame frame = new a(); //如果不是JFrame就换成你的那个类
                j.setLocationByPlatform(true);
                j.setLocationRelativeTo(null);
                j.setVisible(true);
            
        }     public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new s.setVisible(true);
                }
            });
        }