- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- import com.apm.ApmLogin.LoginListener;
- import com.apm.NewAcc.NewAccListener;
- public class AccountPassManagement {
- public static void main(String[] args) {
- Runnable apmlogin=new ApmLogin();
- Thread apmthread=new Thread(apmlogin);
- apmthread.start();
- }
- }
- class ApmLogin extends JFrame implements Runnable{
- JLabel jl1 = null, jl2 = null, jl3 = null;
- JLabel jl4, jl5;
- JPanel jp = null;
- JPanel jp2 = null;
- JTextField jtf = null,jtf2=null;
- JPasswordField jpf = null;
- JButton jb1, jb2;
- public void run(){
- jl1 = new JLabel(new ImageIcon("pictures/qq2012.jpg"));
- jl2 = new JLabel("姓名:", JLabel.CENTER);
- jl2.setFont(new Font("楷体", Font.BOLD, 16));
- jl3 = new JLabel("密码:", JLabel.CENTER);
- jl3.setFont(new Font("楷体", Font.BOLD, 16));
- jl4 = new JLabel("");
- jl5 = new JLabel("");
- jtf = new JTextField();
- jpf = new JPasswordField();
- LoginListener ll = new LoginListener();
- jb1 = new JButton("退出");
- jb1.setFont(new Font("楷体", Font.BOLD, 16));
- jb1.setActionCommand("退出");
- jb1.addActionListener(ll);
- jb2 = new JButton("登录");
- jb2.setFont(new Font("楷体", Font.BOLD, 16));
- jb2.setActionCommand("登录");
- jb2.addActionListener(ll);
- jp = new JPanel();
- jp.setLayout(new GridLayout(2, 3));
- jp.add(jl2);
- jp.add(jtf);
- jp.add(jl4);
- jp.add(jl3);
- jp.add(jpf);
- jp.add(jl5);
- jp2 = new JPanel();
- jp2.setLayout(new GridLayout(1, 3));
- jtf2 = new JTextField("");
- jp2.add(jb1);
- jp2.add(jtf2);
- jp2.add(jb2);
- this.add(jl1, BorderLayout.NORTH);
- this.add(jp, BorderLayout.CENTER);
- this.add(jp2, BorderLayout.SOUTH);
- this.setTitle("账户密码管理系统登录");
- this.setSize(400, 220);
- this.setLocation(400, 200);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setVisible(true);
- }
- // 对登录界面的事件处理,编写为内部类
- class LoginListener implements ActionListener {
- public void actionPerformed(ActionEvent arg0) {
- if (arg0.getActionCommand().equals("退出")) {
- System.exit(0);
- } else if (arg0.getActionCommand().equals("登录")) {
- if(jpf.getText().equals("123456")&&jtf.getText().equals("sa"))
- {
- Runnable apminterface= new ApmInterface();
- Thread apminterfaceThread=new Thread(apminterface);
- apminterfaceThread.start();
- }else {
- jtf2.setText("密码错误,重新输入!");
- jtf2.setFont(new Font("楷体",Font.BOLD,11));
- jtf2.setForeground(Color.RED);
- }
- }
- }
- }
- }
- //账户密码管理界面
- class ApmInterface extends JFrame implements Runnable{
- JLabel jl1 = null, jl2 = null;
- JPanel jp = null;
- JPanel jp2, jp3;
- JButton jb1 = null, jb2 = null;
- public void run(){
- jl1 = new JLabel("账户", JLabel.CENTER);
- jl1.setFont(new Font("楷体", Font.BOLD, 25));
- jl1.setForeground(Color.BLUE);
- jl2 = new JLabel("密码", JLabel.CENTER);
- jl2.setFont(new Font("楷体", Font.BOLD, 25));
- jl2.setForeground(Color.RED);
- jp = new JPanel();
- jp.setLayout(new GridLayout(1, 2));
- jp.add(jl1);
- jp.add(jl2);
- ApmIistener al = new ApmIistener();
- jb1 = new JButton("新建");
- jb1.setFont(new Font("楷体", Font.BOLD, 16));
- jb1.setActionCommand("新建");
- jb1.addActionListener(al);
- jb2 = new JButton("删除");
- jb2.setFont(new Font("楷体", Font.BOLD, 16));
- jb2.setActionCommand("删除");
- jb2.addActionListener(al);
- jp2 = new JPanel();
- jp2.setLayout(new GridLayout(1, 2));
- jp2.add(jb1);
- jp2.add(jb2);
- jp3 = new JPanel();
- this.add(jp, BorderLayout.NORTH);
- this.add(jp3, BorderLayout.CENTER);
- this.add(jp2, BorderLayout.SOUTH);
- this.setTitle("账户密码管理系统");
- this.setSize(600, 450);
- this.setLocation(200, 200);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setVisible(true);
- }
- // 事件处理类,编写为内部类
- }
- class ApmIistener implements ActionListener {
- public void actionPerformed(ActionEvent arg0) {
- if (arg0.getActionCommand().equals("新建")) {
- NewAcc na = new NewAcc();
- AccPass newap=new AccPass();
- } else if (arg0.getActionCommand().equals("删除")) {
- }
- }
- }
- //新建账户界面
- class NewAcc extends JFrame {
- JLabel jl1 = null, jl2 = null;
- JTextField jtf = null;
- JPasswordField jpf = null;
- JButton jb1 = null, jb2 = null;
- public NewAcc() {
- jl1 = new JLabel("Account:", JLabel.CENTER);
- jl1.setFont(new Font("楷体", Font.BOLD, 20));
- jl1.setForeground(Color.green);
- jl2 = new JLabel("Password:", JLabel.CENTER);
- jl2.setFont(new Font("楷体", Font.BOLD, 20));
- jl2.setForeground(Color.green);
- NewAccListener nal = new NewAccListener();
- jb1 = new JButton("Finish");
- jb1.setFont(new Font("楷体", Font.BOLD, 16));
- jb1.setActionCommand("Finish");
- jb1.addActionListener(nal);
- jb2 = new JButton("Cancel");
- jb2.setFont(new Font("楷体", Font.BOLD, 16));
- jb2.setActionCommand("Cancel");
- jb2.addActionListener(nal);
- jtf = new JTextField();
- jpf = new JPasswordField();
- this.setLayout(new GridLayout(3, 2,7,7));
- this.add(jl1);
- this.add(jtf);
- this.add(jl2);
- this.add(jpf);
- this.add(jb1);
- this.add(jb2);
- this.setTitle("Creat a new Account");
- this.setLocation(200, 200);
- this.setSize(300, 150);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setVisible(true);
- }
- // 账户创建界面的事件处理
- class NewAccListener implements ActionListener {
- public void actionPerformed(ActionEvent arg0) {
- if (arg0.getActionCommand().equals("Finish")) {
- }else if(arg0.getActionCommand().equals("Cancel"))
- {
- }
- }
- }
- }
- //账号类,用于存储账号和密码,类的名字由Account和Password前三个字母组合而成
- class AccPass {
- String acc = null, pass = null;
- public String getAcc() {
- return acc;
- }
- public void setAcc(String acc) {
- this.acc = acc;
- }
- public String getPass() {
- return pass;
- }
- public void setPass(String pass) {
- this.pass = pass;
- }
- public AccPass() {
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/211020136535.html
来源: http://www.codesnippet.cn/detail/211020136535.html