项目结构:

  

Constant.java

package com.mstf.test;

import java.io.Serializable;

public class Constant implements Serializable {
public static final long serialVersionUID = 1L;
// 超链接
public static final String URI1 = "第一个需要打开的网址";
public static final String URI2 = "第二个需要打开的网址";
// 帐号和密码
public static final String userName = "admin";
public static final String passWord = "123456";
}

  Test.java

package com.mstf.test;

import java.awt.Desktop;
import java.awt.EventQueue; import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit; public class Test extends JFrame { private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField text_userName;
private JTextField text_passWord; /**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test frame = new Test();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} /**
* Create the frame.
*/
public Test() {
setIconImage(Toolkit.getDefaultToolkit().getImage(Test.class.getResource("/images/favicon.png")));
setTitle("雨落秋垣-后台登录");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null); JLabel labe_l1 = new JLabel("用户名:");
labe_l1.setForeground(Color.RED);
labe_l1.setBounds(86, 86, 54, 15);
contentPane.add(labe_l1); JLabel label_2 = new JLabel("密 码:");
label_2.setForeground(Color.RED);
label_2.setBounds(86, 130, 54, 15);
contentPane.add(label_2); text_userName = new JTextField();
text_userName.setForeground(Color.DARK_GRAY);
text_userName.setBounds(144, 83, 166, 21);
contentPane.add(text_userName);
text_userName.setColumns(10); text_passWord = new JPasswordField();
text_passWord.setForeground(Color.DARK_GRAY);
text_passWord.setBounds(145, 127, 165, 21);
contentPane.add(text_passWord);
text_passWord.setColumns(10); JButton login = new JButton("登录后台");
login.setForeground(Color.RED);
login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// 登录按钮的方法
if (text_userName.getText().trim().equals(Constant.userName)
&& text_passWord.getText().trim().equals(Constant.passWord)) {
JOptionPane.showMessageDialog(contentPane, "登陆成功!", "标题", JOptionPane.WARNING_MESSAGE);
StartBrowse(Constant.URI1);
System.exit(0);
} else {
JOptionPane.showMessageDialog(contentPane, "用户名或者密码错误!!", "标题", JOptionPane.WARNING_MESSAGE);
// 帐号密码错误,自动清空帐号和密码
text_userName.setText("");
text_passWord.setText("");
}
}
});
login.setBounds(70, 194, 93, 23);
contentPane.add(login); JButton regeist = new JButton("查看权限");
regeist.setForeground(Color.BLUE);
regeist.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 注册按钮的方法
if (text_userName.getText().trim().equals(Constant.userName)
&& text_passWord.getText().trim().equals(Constant.passWord)) {
JOptionPane.showMessageDialog(contentPane, "登陆成功!", "标题", JOptionPane.WARNING_MESSAGE);
StartBrowse(Constant.URI2);
System.exit(0);
} else {
JOptionPane.showMessageDialog(contentPane, "您未登录!!", "标题", JOptionPane.WARNING_MESSAGE);
// 帐号密码错误,自动清空帐号和密码
text_userName.setText("");
text_passWord.setText("");
}
}
});
regeist.setBounds(255, 194, 93, 23);
contentPane.add(regeist); JLabel lblHttpsceetgovtop = new JLabel("官方网站: https://ceet-gov.top");
lblHttpsceetgovtop.setForeground(Color.RED);
lblHttpsceetgovtop.setBounds(116, 236, 222, 15);
contentPane.add(lblHttpsceetgovtop); JLabel label = new JLabel("雨落秋垣-后台管理系统");
label.setForeground(Color.MAGENTA);
label.setFont(new Font("宋体", Font.PLAIN, 36));
label.setBounds(23, 23, 378, 39);
contentPane.add(label);
} /**
* 用默认的浏览器,打开指定超链接
*
* @param uri
*/
public void StartBrowse(String uri) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(uri));
} catch (IOException e1) {
e1.printStackTrace();
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
}
}

  

最新文章

  1. 关于npm
  2. getElementsByTagName获得的不是数组的问题!
  3. ASP.NET MVC(三)
  4. Android Context完全解析
  5. lvs keepalived 安装配置详解
  6. EasyUI Accordion下的Panel面板初始化时全部折叠
  7. 有关hadoop分布式配置详解
  8. php设计模式:工厂模式
  9. 升级到 ExtJS 5的过程记录
  10. ActionBarSherlock的使用--------(一)配置
  11. E - Triangle
  12. Unity 利用UGUI打包图集,动态加载sprite资源
  13. 浅谈Tarjan算法
  14. 工控随笔_19_西门子_WinCC的VBS脚本_08_常量和流程控制_01
  15. GNU Screen Usage
  16. openssl可以实现:秘钥证书管理、对称加密和非对称加密
  17. FIFO的使用总结
  18. android 三种定时器的写法
  19. Python FTP文件传输
  20. Linux history命令详解

热门文章

  1. poj2385(dp)
  2. 最全Pycharm教程(29)——再探IDE,速成手冊
  3. rails数据库操作rake db一点心得
  4. vue keep-alive保存路由状态2 (高级用法,接上篇)
  5. crontab任务调度
  6. iReport5.6.0使用说明
  7. (转载)你真的理解Android AIDL中的in,out,inout么?
  8. ModelDriven机制及其运用
  9. 之前的大数相加存在bug,这个ac通过了
  10. js的调试和优化