当前位置: 代码迷 >> J2SE >> 帮忙看看为什么跳不到另一个界面解决方案
  详细解决方案

帮忙看看为什么跳不到另一个界面解决方案

热度:9   发布时间:2016-04-24 00:52:22.0
帮忙看看为什么跳不到另一个界面
Java code
import java.awt.Button;import java.awt.FlowLayout;import java.awt.Frame;import java.awt.Label;import java.awt.TextArea;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class Image1 {        public void init1(){                Frame f =new Frame("学生考评系统");    Button b1=new Button("教师");    Button b2=new Button("学生");    Button b3=new Button("退出");        b2.addActionListener((ActionListener) new StudentListener());        Label l=new Label("欢迎来到学生考评系统,请选择用户");    f.setLayout(new FlowLayout(FlowLayout.LEFT,20,5));        f.add(l);    f.add(b1);    f.add(b2);    f.add(b3);    f.setBounds(470,230,250,120);        f.pack();    f.setVisible(true);            }        class StudentListener implements ActionListener    {        @Override        public void actionPerformed(ActionEvent e)         {                        new Image2().init2();        }            }        class Image2 {            public void init2()        {            Frame f=new Frame("学生用户");            Label l=new Label("请输入学号");            TextArea t=new TextArea();            f.setLayout(new FlowLayout(FlowLayout.LEFT,20,5));                        f.add(l);            f.add(t);            f.pack();                    }            }    public static void main(String[] args)    {        new Image1().init1();            }    }


我想要点击学生按钮时跳到另一个界面,用eclipse运行点学生按钮没有任何反应

------解决方案--------------------
你没有把窗口设成可见
在init2里面最后加上这句就可以了
f.setVisible(true);
  相关解决方案