2024年5月9日发(作者:)
用户登录的代码:
//
import .*;
import .*;
import .*;
class MyJPanel extends JPanel implements ActionListener{
private int count=0;
private JLabel label1,label2;
private JTextField text;
private JPasswordField pass;
private JButton button1,button2;
MyJPanel(){
label1=new JLabel("用户名");
label2=new JLabel("密码");
button1=new JButton("确定");
button2=new JButton("取消");
text=new JTextField(20);
pass=new JPasswordField(20);
monic(_O);//设置按钮快捷键
monic(_C);
ionCommand("entry");
ionCommand("cancel");
ionListener(this);//注册按钮事件
ionListener(this);//注册按钮事件
setBackground();//设定面板背景色
add(label1);
add(text);
add(label2);
add(pass);
add(button1);
add(button2);
}
public void actionPerformed(ActionEvent e){
if (ionCommand().equals("entry")){
count++; //计数
String username,password;
if (count<3) {
username=t();
password=t();
if (("abcd")&&("123456")){
t("用户名及密码正确!");
t("");
}
else{
t("");
t("");
}
}
else
(0);//退出程序
}
else
(0);//退出程序
}
}
public class LoginFrame extends JFrame {
public static void main(String[] args) {
MyJPanel jp=new MyJPanel();//定义面板
der(TitledBorder("输入用户名和密码"));//设定边界
JFrame frame=new JFrame("用户登录");
e(300,150);
tentPane(jp);//在框架中加载面板
aultCloseOperation(_ON_CLOSE);//设置框架关闭按钮
事件
ible(true);
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/news/1715216109a2583807.html
评论列表(0条)