首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

初学java的一些弱智有关问题.麻烦

2011-12-28 
初学java的一些弱智问题..麻烦!在JBUILDER2006下运行下面的代码..为什么画面不会自动显示出来?要点下全屏

初学java的一些弱智问题..麻烦!
在JBUILDER2006下运行下面的代码..为什么画面不会自动显示出来?要点下全屏或拉下边框才能显示...
还有..为什么在点jButton3时.响应的动作会分两步执行??
谢谢!!
import   javax.swing.*;
import   com.borland.jbcl.layout.XYLayout;
import   com.borland.jbcl.layout.*;
import   java.awt.event.ActionEvent;
import   java.awt.event.ActionListener;
import   java.awt.*;
import   java.awt.event.MouseAdapter;

public   class   test2   extends   JFrame   {
        public   test2()   {
                try   {
                        jbInit();
                }   catch   (Exception   ex)   {
                        ex.printStackTrace();
                }
        }

        public   static   void   main(String[]   args)   {
                test2   test2   =   new   test2();
        }

        private   void   jbInit()   throws   Exception   {
                this.getContentPane().setLayout(xYLayout1);
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                show();
                setSize(800,   600);
                jButton1.setText( "jButton1 ");
                jButton1.addActionListener(new   test2_jButton1_actionAdapter(this));
                jButton1.addMouseListener(new   test2_jButton1_mouseAdapter(this));
                jButton3.addMouseListener(new   test2_jButton3_mouseAdapter(this));
                jButton3.addActionListener(new   test2_jButton3_actionAdapter(this));
                this.getContentPane().add(jButton1,   new   XYConstraints(5,   68,   138,   56));
                jButton4.setText( "jButton4 ");
                jButton3.setText( "jButton3 ");
                this.getContentPane().add(jButton2,   new   XYConstraints(5,   143,   98,   31));
                this.getContentPane().add(jButton3,   new   XYConstraints(5,   192,   135,   53));
                this.getContentPane().add(jButton4,   new   XYConstraints(5,   260,   96,   26));
                jButton2.setText( "jButton2 ");
                jButton4.setVisible(false);
        }

        XYLayout   xYLayout1   =   new   XYLayout();
        JButton   jButton1   =   new   JButton();
        JButton   jButton2   =   new   JButton();


        JButton   jButton3   =   new   JButton();
        JButton   jButton4   =   new   JButton();


        public   void   jButton1_actionPerformed(ActionEvent   e)   {
                  if(e.getActionCommand().equals( "jButton1 ")){
                          jButton3.setLocation(5,   192);
                          jButton2.setVisible(true);
                          jButton4.setVisible(false);
                  }

        }

        public   void   jButton3_actionPerformed(ActionEvent   e)   {
                if(e.getActionCommand().equals( "jButton3 ")){
                        jButton3.setLocation(5,   143);
                        jButton2.setVisible(false);
                        jButton4.setVisible(true);
                        jButton4.setLocation(5,   192);
                }
        }

}


class   test2_jButton1_mouseAdapter   extends   MouseAdapter   {
        private   test2   adaptee;
        test2_jButton1_mouseAdapter(test2   adaptee)   {
                this.adaptee   =   adaptee;
        }
}


class   test2_jButton1_actionAdapter   implements   ActionListener   {
        private   test2   adaptee;
        test2_jButton1_actionAdapter(test2   adaptee)   {
                this.adaptee   =   adaptee;
        }

        public   void   actionPerformed(ActionEvent   e)   {
                adaptee.jButton1_actionPerformed(e);
        }
}


class   test2_jButton3_mouseAdapter   extends   MouseAdapter   {
        private   test2   adaptee;
        test2_jButton3_mouseAdapter(test2   adaptee)   {
                this.adaptee   =   adaptee;
        }
}


class   test2_jButton3_actionAdapter   implements   ActionListener   {
        private   test2   adaptee;
        test2_jButton3_actionAdapter(test2   adaptee)   {
                this.adaptee   =   adaptee;
        }

        public   void   actionPerformed(ActionEvent   e)   {


                adaptee.jButton3_actionPerformed(e);
        }
}


[解决办法]
上面那个 把jbutton1和jButton4弄反了 应该是下面这个 不好意思哈
这个就可以了
============================
package test2;

/**
* <p> Title: </p>
*
* <p> Description: </p>
*
* <p> Copyright: Copyright (c) 2007 </p>
*
* <p> Company: </p>
*
* @author not attributable
* @version 1.0
*/
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import java.awt.event.MouseAdapter;

public class test2 extends JFrame {
public test2() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}

public static void main(String[] args) {
test2 test2 = new test2();
}

private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout1);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
this.setTitle( "***** ");
this.setVisible(true);
jButton1.setText( "jButton1 ");
jButton1.addActionListener(new test2_jButton1_actionAdapter(this));
jButton3.addActionListener(new test2_jButton3_actionAdapter(this));
this.getContentPane().add(jButton1, new XYConstraints(5, 68, 138, 56));
this.getContentPane().add(jButton2, new XYConstraints(5, 143, 98, 31));
this.getContentPane().add(jButton3, new XYConstraints(5, 192, 135, 53));

jButton4.setText( "jButton4 ");
jButton3.setText( "jButton3 ");
jButton2.setText( "jButton2 ");

}

XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();


public void jButton1_actionPerformed(ActionEvent e) {
jButton3.setLocation(5, 192);
this.getContentPane().add(jButton2, new XYConstraints(5, 143, 98, 31));
this.remove(jButton4);
this.validate();
this.repaint();
}

public void jButton3_actionPerformed(ActionEvent e) {
this.getContentPane().add(jButton4, new XYConstraints(5, 260, 96, 26));
this.remove(jButton2);
this.validate();
this.repaint();
jButton3.setLocation(5, 143);
jButton4.setLocation(5, 192);
}

}


class test2_jButton1_actionAdapter implements ActionListener {
private test2 adaptee;
test2_jButton1_actionAdapter(test2 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}

class test2_jButton3_actionAdapter implements ActionListener {
private test2 adaptee;
test2_jButton3_actionAdapter(test2 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}

热点排行