62,614
社区成员
发帖
与我相关
我的任务
分享
import java.awt.*;
import java.awt.event.*;
class DialogWindow extends Frame implements ActionListener
{
Label account_number = new Label("Account number:");
Label password = new Label("Password:");
TextField account_number_TextField = new TextField("lyhdx77",15);
TextField password_TextField = new TextField("lyhdx77",15);
Button disembark = new Button("Disembark ");
String s_account_number = "lyhdx77";
String s_password = "lyhdx77";
DialogWindow()
{
super("登陆窗口");
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.setBounds(500, 500, 270, 200);
this.setLayout(new FlowLayout());
this.add(account_number);
this.add(account_number_TextField);
this.add(password);
this.add(password_TextField);
this.add(disembark);
disembark.addActionListener(this);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==disembark)
{
if(account_number_TextField.getText()==s_account_number && password_TextField.getText()==s_password)
{
this.setVisible(false);
RightAnswerDialog right_answer_dialog = new RightAnswerDialog(this,"账号密码正确",true);
}
if(account_number_TextField.getText()!=s_account_number || password_TextField.getText()!=s_password)
{
this.setVisible(false);
ErrorAnswerDialog error_answer_dialog = new ErrorAnswerDialog(this,"账号密码错误",true);
}
}
}
}
class RightAnswerDialog extends Dialog
{
RightAnswerDialog(Frame f,String s,boolean b)
{
super(f,s,b);
this.setLayout(new FlowLayout());
this.setBounds(400,400,300,200);
this.add(new Label("Right!"));
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.setVisible(true);
}
}
class ErrorAnswerDialog extends Dialog
{
ErrorAnswerDialog(Frame f,String s,boolean b)
{
super(f,s,b);
this.setLayout(new FlowLayout());
this.setBounds(400,400,300,200);
this.add(new Label("Error!"));
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.setVisible(true);
}
}
public class Test620
{
public static void main(String args[])
{
new DialogWindow();
}
}
import java.awt.*;
import java.awt.event.*;
class Test619 extends Frame implements ActionListener
{
Button button1 = new Button();
Button button2 = new Button();
public static void main(String args[])
{
new Test619();
}
public Test619()
{
super("移动按钮");
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.setBounds(500, 500, 500, 500);
this.setLayout(new FlowLayout());
this.add(button1);
this.add(button2);
button1.addActionListener(this);
button2.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
System.out.println("1");
}
if(e.getSource()==button2)
{
System.out.println("2");
}
}
}