📄 fram2.java
字号:
/***************************************************************************/
/*********************本窗口用于登陆校园卡服务界面可验证密码******************/
/**************************************************************************/
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.text.*;
public class Fram2 extends JFrame implements ActionListener //校园卡登陆界面窗口类
{
private JLabel jlabel1,jlabel2; //声明私有一系列组件
private JTextField textfield1;
private JPasswordField passwordfield;
private Button1 button1,button2,button3,button4;
Fram2()
{
super("校园卡登陆界面"); //调用父类方法
jlabel1=new JLabel("卡 号"); //定义标签对象
jlabel2=new JLabel("密 码");
jlabel1.setFont(new Font("宋体",Font.BOLD,20)); //定义标签对象
jlabel2.setFont(new Font("宋体",Font.BOLD,20));
jlabel1.setBackground(Color.white); //设置标签主件背景颜色
jlabel1.setBackground(Color.white);
jlabel1.setForeground(new Color(50,40,200)); //设置标签主件前景颜色
jlabel2.setForeground(new Color(50,40,200));
textfield1=new JTextField(10); //定义字段组件对象
passwordfield=new JPasswordField(10); //定义显示密码专用字段区
button1=new Button1("确 定");
button2=new Button1("返 回");
button3=new Button1("退 出");
button4=new Button1("重 输");
button1.setToolTipText("进入服务界面"); //显示按钮提示标签
Container container=getContentPane(); //得到容器对象
container.setBackground(new Color(117,224,227)); //得到容器对象
container.setLayout(new FlowLayout(FlowLayout.LEFT,10,20)); //设置布局样式
container.add(jlabel1);container.add(textfield1);
container.add(jlabel2);container.add(passwordfield);
container.add(button1);container.add(button2);container.add(button3);container.add(button4); //将各种 组件 放在容器中
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
setSize(450,400);
setVisible(false);
}
public void actionPerformed(ActionEvent e) //定义监视器响应函数
{
if(e.getSource()==button1) //响应登陆
{
if((Integer.parseInt(textfield1.getText()))!=J02323.card.cardno)
{
JOptionPane.showMessageDialog(null,"卡号不对"); //提示对话筐
}
else if(!(passwordfield.getText().equals(J02323.card.getPassword())))
{
JOptionPane.showMessageDialog(null,"密码错误"); //提示对话筐
}
else
{ this.setVisible(false);
J02323.fram4.setVisible(true);
}
}
else if(e.getSource()==button2) //响应返回
{
this.setVisible(false);
J02323.fram1.setVisible(true);
}
else if(e.getSource()==button4) //响应清空
{
textfield1.setText("");
passwordfield.setText("");
}
else //响应退出
{
dispose();
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -