[Java] 登陆界面设计 →→→→→进入此内容的聊天室

来自 , 2020-10-08, 写在 Java, 查看 141 次.
URL http://www.code666.cn/view/a64c94ba
  1. //登陆界面
  2. package com.view;
  3.  
  4. import java.awt.Color;
  5. /**
  6.  * 登陆
  7.  * @author Administrator
  8.  *
  9.  */
  10. public class InTo extends JFrame implements ActionListener,MouseListener{
  11.  
  12.         /**
  13.          * 成员变量
  14.          */
  15.         private static final long serialVersionUID = 1L;
  16.         //北部
  17.         private JLabel topImg ;
  18.         //中部
  19.         private JPanel panel1;
  20.         private JLabel nameLab,pswLab;
  21.         private JTextField nameTex;
  22.         private JPasswordField pswTex;
  23.         JLabel forgetLab;
  24.         private JLabel insertLab;
  25.         private JButton intoBut;
  26.         //监听处理
  27.         private AdminDao admin;
  28.         private JLabel alertLab;
  29.        
  30.  
  31.         /**
  32.          * 入口
  33.          */
  34.         public static void main(String[] args) {
  35.                
  36.                 try {
  37.                         // String lookAndFeel =
  38.                         // UIManager.getCrossPlatformLookAndFeelClassName();
  39.                         UIManager.setLookAndFeel(new BernsteinLookAndFeel());
  40.                         //UIManager.setLookAndFeel(new McWinLookAndFeel());
  41.                         //UIManager.setLookAndFeel(new MetalLookAndFeel());
  42.  
  43.                 } catch (Exception e) {
  44.                 }
  45.                 new InTo();
  46.  
  47.         }
  48.  
  49.         /**
  50.          * 初始化
  51.          */
  52.         public InTo() {
  53.                 admin=new AdminDao();
  54.                
  55.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  56.                 setTitle("鑫鑫图书管理登陆");
  57.                 this.setUndecorated(true);//去掉窗口的装饰
  58.                 this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);////设置为简单对话窗口
  59.                 setIconImage(Toolkit.getDefaultToolkit().getImage("QQ图标/a.png"));
  60.                 setSize(450, 340);
  61.                 this.setLocationRelativeTo(null);
  62.                 getContentPane().setLayout(null);
  63.                
  64.                 JLabel alert = new JLabel("<html><font face='行楷' size=5 color=red><b>鑫 鑫 图 书 管 理 系 统</b></font><br/><font color=white>DA BING TU SHU GUAN LI XING TONG</html>");
  65.                 alert.setBounds(221, -11, 300, 83);
  66.                 getContentPane().add(alert);
  67.                
  68.                 topImg= new JLabel(new ImageIcon("image/图书馆登陆.jpg"));
  69.                 topImg.setBounds(0, 0, 450, 120);
  70.                 getContentPane().add(topImg);
  71.                
  72.                 panel1 = new JPanel();
  73.                 panel1.setBounds(0, 120, 450, 220);
  74.                 panel1.setLayout(null);
  75.                
  76.                 nameLab = new JLabel("用户名:");
  77.                 nameLab.setFont(MySetFont.f6);
  78.                 nameLab.setBounds(46, 10, 69, 35);
  79.                 panel1.add(nameLab);
  80.                
  81.                 nameTex = new JTextField();
  82.                 nameTex.setBounds(135, 10, 155, 35);
  83.                 panel1.add(nameTex);
  84.                 nameTex.addActionListener(this);//监听2
  85.                 nameTex.setColumns(10);
  86.                
  87.                 pswLab = new JLabel("密码:");
  88.                 pswLab.setFont(MySetFont.f6);
  89.                 pswLab.setBounds(46, 60, 69, 35);
  90.                 panel1.add(pswLab);
  91.                
  92.                 pswTex = new JPasswordField();
  93.                 pswTex.setBounds(135, 60, 155, 35);
  94.                 pswTex.addActionListener(this);//监听2
  95.                 panel1.add(pswTex);
  96.                
  97.                 forgetLab = new JLabel("忘记密码");
  98.                 forgetLab.setForeground(Color.red);
  99.                 forgetLab.setFont(MySetFont.f3);
  100.                 forgetLab.setHorizontalAlignment(SwingConstants.CENTER);
  101.                 forgetLab.setBounds(300, 10, 108, 35);
  102.                 forgetLab.addMouseListener(this);//监听1
  103.                 panel1.add(forgetLab);
  104.                
  105.                 insertLab = new JLabel("注册账号");
  106.                 insertLab.setHorizontalAlignment(SwingConstants.CENTER);
  107.                 insertLab.setBounds(300, 60, 108, 35);
  108.                 insertLab.setFont(MySetFont.f3);
  109.                 insertLab.setForeground(Color.blue);
  110.                 insertLab.addMouseListener(this);//监听1
  111.                 panel1.add(insertLab);
  112.                
  113.                 alertLab = new JLabel();
  114.                 alertLab.setHorizontalAlignment(SwingConstants.LEFT);
  115.                 alertLab.setForeground(Color.RED);
  116.                 alertLab.setFont(MySetFont.f3);
  117.                 alertLab.setBounds(135, 95, 273, 35);
  118.                 panel1.add(alertLab);
  119.                
  120.                 intoBut = new JButton("<html>登&nbsp;&nbsp;陆</html>");
  121.                 intoBut.setFont(MySetFont.f3);
  122.                 intoBut.setBounds(135, 140, 155, 37);
  123.                 intoBut.addMouseListener(this);//监听1
  124.                 intoBut.addActionListener(this);
  125.                 panel1.add(intoBut);
  126.                
  127.                 getContentPane().add(panel1);
  128.                
  129.        
  130.                
  131.                 this.setVisible(true);
  132.        
  133.         }
  134.         /////////////////////////////////////////////////鼠标监听1
  135.         @Override
  136.         public void mouseClicked(MouseEvent de) {
  137.                 //点击
  138.                 if(de.getSource()==forgetLab){
  139.                         new InTo_Forget();
  140.                         this.dispose();
  141.                 }else if(de.getSource()==insertLab){
  142.                         //注册
  143.                         this.dispose();
  144.                 }
  145.                
  146.         }
  147.  
  148.         @Override
  149.         public void mouseEntered(MouseEvent de) {
  150.                 // 进入
  151.                 if(de.getSource()==forgetLab){
  152.                         forgetLab.setFont(MySetFont.f1);
  153.                 }else if(de.getSource()==insertLab){
  154.                         insertLab.setFont(MySetFont.f1);
  155.                 }else if(de.getSource()==intoBut){
  156.                         intoBut.setForeground(Color.red);
  157.                 }
  158.                
  159.         }
  160.  
  161.         @Override
  162.         public void mouseExited(MouseEvent de) {
  163.                 // 移除
  164.                 if(de.getSource()==forgetLab){
  165.                         forgetLab.setFont(MySetFont.f3);
  166.                 }else if(de.getSource()==insertLab){
  167.                         insertLab.setFont(MySetFont.f3);
  168.                 }else if(de.getSource()==intoBut){
  169.                         intoBut.setForeground(Color.black);
  170.                 }
  171.                
  172.         }
  173.  
  174.         @Override
  175.         public void mousePressed(MouseEvent arg0) {
  176.                 // TODO Auto-generated method stub
  177.                
  178.         }
  179.  
  180.         @Override
  181.         public void mouseReleased(MouseEvent arg0) {
  182.                 // TODO Auto-generated method stub
  183.                
  184.         }
  185.         //////////////////////////////////////////////基本监听2
  186.         @Override
  187.         public void actionPerformed(ActionEvent de) {
  188.                 String name=nameTex.getText();
  189.                 String psw=new String(pswTex.getPassword());
  190.                
  191.                 if(de.getSource()==nameTex){
  192.                        
  193.                         pswTex.requestFocus();//获得焦点
  194.                        
  195.                 }else if(de.getSource()==pswTex){
  196.                        
  197.                         doPD(name,psw);
  198.                        
  199.                 }else if(de.getSource()==intoBut){
  200.                         doPD(name,psw);
  201.                 }
  202.         }
  203.        
  204.         /**
  205.          * 登陆的判断
  206.          */
  207.         public void doPD(String name,String psw){
  208.                 AdminPoJo pojo=new AdminPoJo();
  209.                 if(StringUtil.isNotNull(name)&&StringUtil.isNotNull(psw)){
  210.                         pojo.setName(name);
  211.                         pojo.setPassword(psw);
  212.                         AdminPoJo pojo1=admin.doInTo(pojo);
  213.                         if(pojo1!=null){
  214.                                 //ok登陆
  215.                                 alertLab.setText("ok");
  216.                                 new Menu();
  217.                                 this.dispose();
  218.                         }else{
  219.                                 //no
  220.                                 alertLab.setText("登陆失败");
  221.                         }
  222.                 }else{
  223.                         //填写
  224.                         alertLab.setText("填写");
  225.                 }
  226.         }
  227. }
  228.  

回复 "登陆界面设计"

这儿你可以回复上面这条便签

captcha