[Java] QQ聊天系统 →→→→→进入此内容的聊天室

来自 , 2020-04-09, 写在 Java, 查看 96 次.
URL http://www.code666.cn/view/10c272d0
  1. package limengjie;
  2.  
  3.  
  4.  
  5. import java.awt.Color;
  6.  
  7. import java.awt.Font;
  8.  
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.sql.Connection;
  14. import java.sql.PreparedStatement;
  15. import java.sql.ResultSet;
  16. import java.sql.SQLException;
  17. import java.sql.Statement;
  18.  
  19. import javax.swing.ImageIcon;
  20. import javax.swing.JButton;
  21. import javax.swing.JFrame ;
  22. import javax.swing.JLabel;
  23. import javax.swing.JPanel;
  24. import javax.swing.JPasswordField;
  25. import javax.swing.JTextField;
  26.  
  27.  
  28.  
  29. public class JqqF extends JFrame implements MouseListener {
  30.  
  31.         private static final long serialVersionUID = 1L;
  32.  
  33.         public static void main(String args[]) {
  34.                 JqqF f = new JqqF();
  35.                
  36.  
  37.         }
  38.          
  39.                 public static JTextField name = new JTextField(20);
  40.                 JLabel nameLab = new JLabel("输入qq号:");
  41.                 public  static JPasswordField nam = new JPasswordField(20);
  42.                 JLabel nameLa = new JLabel("输入qq密码:");
  43.                 String path5 = "pic//x.png";  
  44.             // 背景图片  
  45.             ImageIcon background5 = new ImageIcon(path5);
  46.                 cell but = new cell(background5);
  47.                 Font fnt = new Font("Serief", Font.BOLD, 15);
  48.                 String path4 = "pic//l.png";  
  49.            
  50.             ImageIcon background4 = new ImageIcon(path4);  
  51.                          
  52.                 //cell bt = new cell(background4);     
  53.             cell bt = new cell("注册账号");
  54.                 Font fnt1 = new Font("Serief", Font.BOLD, 11);
  55.                
  56.                 String path3 = "pic//b.png";  
  57.            
  58.             ImageIcon background3 = new ImageIcon(path3);  
  59.                          
  60.         //      cell bt2 = new cell(background3);      
  61.             cell bt2 = new cell("找回密码");       
  62.                 Font fnt2 = new Font("Serief", Font.BOLD, 11); 
  63.                 String path2= "pic//qq3.png";  
  64.            
  65.             ImageIcon background2= new ImageIcon(path2);
  66.             JLabel label2 = new JLabel(background2);
  67.        
  68.        
  69.         public JqqF() {
  70.             super("qq聊天系统");
  71.             this.setSize(500, 334);
  72.                 this.setLocation(300, 200);
  73.                
  74.  
  75.                 this.setVisible(true);
  76.             String path = "pic//qq.png";  
  77.         // 背景图片  
  78.         ImageIcon background = new ImageIcon(path);  
  79.         // 把背景图片显示在一个标签里面  
  80.         JLabel label = new JLabel(background);  
  81.         label.setLayout(null);
  82.         // 把标签的大小位置设置为图片刚好填充整个面板  
  83.         label.setBounds(0, 0, this.getWidth(), this.getHeight());  
  84.         // 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明  
  85.         JPanel imagePanel = (JPanel) this.getContentPane();  
  86.         imagePanel.setOpaque(false);  
  87.         // 把背景图片添加到分层窗格的最底层作为背景  
  88.            
  89.         nameLab.setFont(fnt);
  90.                 nameLab.setForeground(Color.blue);
  91.                 nameLa.setFont(fnt);
  92.                 nameLa.setForeground(Color.blue);
  93.                 bt.setFont(fnt1);
  94.                 bt.setForeground(Color.black);
  95.                 bt2.setFont(fnt2);
  96.                 bt2.setForeground(Color.black);
  97.  
  98.                 nameLab.setBounds(160, 120, 100, 30);
  99.                 bt.setBounds(360, 120, 88, 25);
  100.                 bt.addActionListener(new ActionListener(){
  101.  
  102.                         @Override
  103.                         public void actionPerformed(ActionEvent e) {
  104.                                 register x = new register();
  105.                        
  106.                                
  107.                         }
  108.                        
  109.                 });
  110.                 name.setBounds(250, 120, 108, 25);
  111.                 nameLa.setBounds(160, 160, 100, 30);
  112.                 nam.setBounds(250, 160, 108, 25);
  113.                 bt2.setBounds(360, 160, 88, 25);
  114.                 bt2.addActionListener(new ActionListener(){
  115.  
  116.                         @Override
  117.                         public void actionPerformed(ActionEvent e) {
  118.                                 new findpassword();
  119.                        
  120.                                
  121.                         }
  122.                        
  123.                 });
  124.                 //// nam.setColumns(20) ;
  125.                 label2.setBounds(65, 120, 88, 83);
  126.                 but.setBounds(185, 210, 147, 30);
  127.                 but.addMouseListener(this);
  128.  
  129.                 label.add(nameLab);
  130.                 label.add(bt);
  131.                 label.add(bt2);
  132.                 label.add(nam);
  133.                 label.add(nameLa);
  134.                 label.add(label2);
  135.                 label.add(name);
  136.                 label.add(but);
  137.                 this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));  
  138.                 this.setResizable(false);
  139.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  140.                
  141.                
  142.                 // 让组件可见
  143.         }
  144.  
  145.  
  146.         public void mouseClicked(MouseEvent e) {
  147.                 char[] a = nam.getPassword();
  148.                 String s = new String(a);
  149.                
  150.                 //System.out.print(s);
  151.                 String b = "1";
  152.                 Statement st = null;
  153.                 ResultSet rs = null;
  154.                 boolean t = false;
  155.                 boolean x = false;
  156.                   Connection con =null;
  157.                  
  158.                         String sql = "SELECT name,mibao,password FROM qq";
  159.                   try {
  160.                         con= new JavaMysql().connnecton();
  161.                         st = con.createStatement();
  162.                         rs = st.executeQuery(sql);
  163.                        
  164.                 } catch (ClassNotFoundException e2) {
  165.                         // TODO Auto-generated catch block
  166.                         e2.printStackTrace();
  167.                 } catch (SQLException e2) {
  168.                         // TODO Auto-generated catch block
  169.                         e2.printStackTrace();
  170.                 }
  171.         try {
  172.                 while(rs.next()){
  173.                         String qq = rs.getString("name");
  174.                         String password1 = rs.getString("password");
  175.                         if(qq.equals(name.getText())){
  176.                                 t = true;
  177.                                
  178.                                 if(password1.equals(nam.getText())){
  179.                                         x = true;
  180.                                 }
  181.                         }
  182.                
  183.                        
  184.                 }
  185.                 con.close();
  186.                 st.close();
  187.                 rs.close();
  188.         } catch (SQLException e1) {
  189.                 // TODO Auto-generated catch block
  190.                 e1.printStackTrace();
  191.         }
  192.                 if(t){
  193.                         if (x) {
  194.                                 JqqF2 f1 = new JqqF2();
  195.        
  196.                                 this.setVisible(false);
  197.                                 f1.setVisible(true);
  198.                         } else {
  199.                        new passworderror();
  200.                         }
  201.                 }else{
  202.                         new look();
  203.                 }
  204.         }
  205.  
  206.         @Override
  207.         public void mousePressed(MouseEvent e) {
  208.                 // TODO Auto-generated method stub
  209.  
  210.         }
  211.  
  212.         @Override
  213.         public void mouseReleased(MouseEvent e) {
  214.                 // TODO Auto-generated method stub
  215.  
  216.         }
  217.  
  218.         @Override
  219.         public void mouseEntered(MouseEvent e) {
  220.                 // TODO Auto-generated method stub
  221.  
  222.         }
  223.  
  224.         @Override
  225.         public void mouseExited(MouseEvent e) {
  226.                 // TODO Auto-generated method stub
  227.  
  228.         }
  229.  
  230. };

回复 "QQ聊天系统"

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

captcha