当前位置:和仁网 >其它 > 正文

eclipse GUI开发,怎么做?

2020-07-19 0

在窗1按单击事件中,创建窗体2对象,并设置窗体2可见,:
public void actionPerformed(java.awt.event.ActionEvent e) {
chuangti2 ct2=new chuangti2();
ct2.setVisible(true);
}

另:如果希望进入窗体2的同时注销窗体1的话,可在窗体2的windowOpened方法中注销窗体1,如下:
public void windowOpened(java.awt.event.WindowEvent e) {
aaa.chuangti1.ct1.dispose();
}

搞不掂的话可以问我得是这样的:
(注意,是第一个窗体的。)

private void Form1_Load(object sender, EventArgs e)
{
Form2 obj =new Form2();
//new一例对象 注里是你要打开的窗体的类名(Form2)。
obj.show();//其实就只要加这两句,其他的都有现成的。

}import java.awt.*;
import java.awt.event.*;
public class TestUser {
public static void main (String[] args) {
new User().launchFrame();
}
}

class User extends Frame {
TextField t1,t2;
public void launchFrame() {
t1 = new TextField (10);
t2 = new TextField (10);
t2.setEchoChar(*);
Button bu = new Button ("确");
bu.addActionListener (new Monitor8());
Label l1 = new Label ("用户名");
Label l2 = new Label ("密码");
setLayout (new GridLayout (3,2));
add (l1);
add (t1);
add (l2);
add (t2);
add (bu);
addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible (false);
System.exit(0);
}
} );
pack ();
setLocation (300,300);
setVisible (true);
}
class Monitor8 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String n1 = t1.getText();
int n2 = Integer.parseInt (t2.getText());
final Frame f = new Frame("登录成功");
if ((n1.equals("M")&&(n2==3))) {
Label l3 = new Label ("权限C");
f.add (l3);
f.setBounds(500,500,200,70);
f.setVisible(true);
f. addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f.setVisible (false);

}
} );
}
else if ((n1.equals("a")&&(n2==2))) {
Label l4 = new Label ("权限为P");
f.add (l4);
f.setBounds(500,500,200,70);
f.setVisible(true);
f. addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f.setVisible (false);

}
} );

}
else {
final Frame f1 = new Frame("登录");
f1.setBounds(500,500,200,70);
f1.setVisible(true);
f1. addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f1.setVisible (false);

}
} );
}
}
}
}先new第一个窗体show出来
然后将第一个窗体dispose
再new第二个窗体show出来,就这么简单
本周热门
本月热门