java中如何连接两个Frame
我用JBuilder想做一个简单的登录系统,做了两个Frame(Frame1和Frame2),现在想在Frame1的画面中点击按钮然后转到Frame2的画面,不知如何实现...
我用JBuilder想做一个简单的登录系统,做了两个Frame(Frame1和Frame2),现在想在Frame1的画面中点击按钮然后转到Frame2的画面,不知如何实现,请朋友们帮帮忙!最好举个例子,谢谢了!!!
展开
4个回答
展开全部
当你输入用户名为M,密码为3时,会有显示;用户名为a,密码为2时,会有显示;否则的话,(以上2种情况除外,会弹出2个Frame)
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);
}
} );
}
}
}
}
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);
}
} );
}
}
}
}
展开全部
简单 用户名密码都对了 让Frame1设置为不可看见 另一个可见 就这样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1L说得很明白了,就是在按钮事件里生成一个新frame,把相关的参数传递在新frame中,然后新frame设置可见,旧frame注销或隐藏
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在Frame1的事件中去new一个Frame2的对象
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询