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运行点学生按钮没有任何反应
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);