JAVA图形界面程序,不能关闭窗口
帮我查看一下哪里出的问题importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassLo...
帮我查看一下哪里出的问题
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoginWindow extends Frame implements ActionListener {
TextField userID, password;
LoginWindow() {
super("用户登录窗口");
setLayout(new GridLayout(3,1));
Panel p1=new Panel();
Label label1 = new Label("用户名: ");
userID = new TextField(12);
p1.add(label1);
p1.add(userID);
Panel p2=new Panel();
Label label2 = new Label("密 码: ");
password = new TextField(12);
password.setEchoChar('*');
p2.add(label2);
p2.add(password);
Panel p3=new Panel();
Button submit = new Button(" 提 交 ");
Button reset = new Button(" 重 置 ");
submit.addActionListener(this);
reset.addActionListener(this);
p3.add(submit);
p3.add(reset);
add(p1);
add(p2);
add(p3);
addWindowListener(new WindowMonitor());
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(" 提 交 ")) {
if(userID.getText().equals("software") && password.getText().equals("87818998")) {
Frame f = new Frame("新窗口");
f.setSize(400,300);
f.setVisible(true);
f.addWindowListener(new WindowMonitor());
}
else {
JOptionPane.showMessageDialog(null, "帐号、密码不正确!");
}
}
if(e.getActionCommand().equals(" 重 置 ")) {
userID.setText("");
password.setText("");
}
}
public static void main(String argc[]) {
LoginWindow myframe = new LoginWindow();
myframe.pack();
myframe.setVisible(true);
}
}
class WindowMonitor extends WindowAdapter {
public void WindowClosing(WindowEvent e) {
System.exit(0);
}
} 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoginWindow extends Frame implements ActionListener {
TextField userID, password;
LoginWindow() {
super("用户登录窗口");
setLayout(new GridLayout(3,1));
Panel p1=new Panel();
Label label1 = new Label("用户名: ");
userID = new TextField(12);
p1.add(label1);
p1.add(userID);
Panel p2=new Panel();
Label label2 = new Label("密 码: ");
password = new TextField(12);
password.setEchoChar('*');
p2.add(label2);
p2.add(password);
Panel p3=new Panel();
Button submit = new Button(" 提 交 ");
Button reset = new Button(" 重 置 ");
submit.addActionListener(this);
reset.addActionListener(this);
p3.add(submit);
p3.add(reset);
add(p1);
add(p2);
add(p3);
addWindowListener(new WindowMonitor());
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(" 提 交 ")) {
if(userID.getText().equals("software") && password.getText().equals("87818998")) {
Frame f = new Frame("新窗口");
f.setSize(400,300);
f.setVisible(true);
f.addWindowListener(new WindowMonitor());
}
else {
JOptionPane.showMessageDialog(null, "帐号、密码不正确!");
}
}
if(e.getActionCommand().equals(" 重 置 ")) {
userID.setText("");
password.setText("");
}
}
public static void main(String argc[]) {
LoginWindow myframe = new LoginWindow();
myframe.pack();
myframe.setVisible(true);
}
}
class WindowMonitor extends WindowAdapter {
public void WindowClosing(WindowEvent e) {
System.exit(0);
}
} 展开
2个回答
展开全部
最后那里,
windowClosing 第一个字母 w 是小写的!
windowClosing 第一个字母 w 是小写的!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |