[java]代码库
//挂机
package com.view;
import java.awt.Color;
/**
* 挂机界面
* @author Administrator
*
*/
public class SystemHook extends JDialog implements ActionListener{
/**
* 成员变量
*/
private static final long serialVersionUID = 1L;
private JPasswordField passwordField;
private JButton yesBut,delBut;
private JLabel keyLab;
//设置全局的锁
private String key;//可以不全为数字
private int status=0;//回车的当前状态0:set;1:get;
private Menu menu;
private JLabel alertLab;
private JLabel img1;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Menu getMenu() {
return menu;
}
public void setMenu(Menu menu) {
this.menu = menu;
}
// /**
// *new 测试
// */
// public static void main(String[] args) {
// try {
// SystemHook dialog = new SystemHook();
// dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
// dialog.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
/**
* 构造函数初始化
* @param b
* @param menu
*/
public SystemHook(Menu menu, boolean b) {
super(menu,b);
this.menu=menu;
this.setTitle("系统挂机");
setBounds(100, 100, 499, 331);
this.setLocationRelativeTo(null);
getContentPane().setLayout(null);
{
alertLab = new JLabel("<html><b><font color=white size=5 face='楷体'>系 统 修 改</font></b><br/><font color=white size=4>xi tong gua ji</font></html>");
alertLab.setBounds(32, 31, 162, 58);
getContentPane().add(alertLab);
JLabel topImage = new JLabel("");
topImage.setIcon(new ImageIcon("image/挂机top.jpg"));
topImage.setBorder(new TitledBorder(""));
topImage.setBounds(0, 0, 483, 113);
getContentPane().add(topImage);
}
keyLab= new JLabel("设置挂机锁:",JLabel.RIGHT);
keyLab.setBounds(61, 154, 117, 33);
getContentPane().add(keyLab);
passwordField = new JPasswordField();
passwordField.addActionListener(this);//监听1
passwordField.setBounds(188, 154, 193, 33);
getContentPane().add(passwordField);
yesBut= new JButton("挂机");
yesBut.addActionListener(this);//监听1
yesBut.setBounds(310, 250, 71, 33);
getContentPane().add(yesBut);
delBut = new JButton("取消");
delBut.addActionListener(this);//监听1
delBut.setBounds(402, 250, 71, 33);
getContentPane().add(delBut);
img1 = new JLabel(new ImageIcon("image/挂机ico.png"));
img1.setText("挂机中......");
img1.setBounds(186, 197, 125, 33);
img1.setVisible(false);
getContentPane().add(img1);
this.setVisible(true);
}
/**
* 注册监听器1
*/
@Override
public void actionPerformed(ActionEvent de) {
// TODO Auto-generated method stub
String type=de.getActionCommand();
String psw=new String(passwordField.getPassword());
if(type.equals("挂机")){
this.getPsw(psw);
}else if(de.getSource()==passwordField){
//回车0挂机;1解锁
if(status==0){
this.getPsw(psw);
}else if(status==1){
this.openKey(psw);
}
}else if(de.getSource()==delBut){
passwordField.setText("");//设为空
menu.setVisible(true);//显示系统界面
this.dispose();
}else if(type.equals("解锁")){
this.openKey(psw);
}
}
/**
* 解锁
* @param psw
*/
public void openKey(String psw) {
if(StringUtil.isNotNull(psw)){
if(psw.equals(key)){
menu.setVisible(true);//显示系统界面
status=0;//设为set锁回车
this.dispose();//关闭此窗口
}else{
JOptionPane.showMessageDialog(null, "你输入的解锁码不正确");
passwordField.setText("");//为空
}
}else{
JOptionPane.showMessageDialog(null, "请输入解锁码");
}
}
/**
* 设置密码
* @param psw
*/
public void getPsw(String psw) {
if(StringUtil.isNotNull(psw)){
if(psw.length()>=6){
key=psw;
yesBut.setText("解锁");
keyLab.setText("解锁密码:");
img1.setVisible(true);//显示挂机锁
yesBut.setForeground(Color.red);
passwordField.setText("");
status=1;//设为解锁回车
}else{
JOptionPane.showMessageDialog(null, "请设置密码至少6位");
}
}else{
JOptionPane.showMessageDialog(null, "请设置密码锁!");
}
}
}
中级程序员
by: 猴子的救兵 发表于:2017-09-14 17:19:34 顶(0) | 踩(0) 回复
这是什么的挂机
回复评论