zoukankan      html  css  js  c++  java
  • 期末设计(第十四周)

    1、登录界面与好友列表框的连接
    代码:
    public LoginFrame() {

    	frm = new JFrame();
    	frm.setLayout(null);
    
    	//账号
    	yonghuming = new JLabel("账号");
    	yonghuming.setBounds(150, 125, 100, 40);
    	frm.add(yonghuming);
    	
    	//密码
    	mima = new JLabel("密码");
    	mima.setBounds(150, 150, 100, 40);
    	frm.add(mima);
    
    	//用户名
    	username = new JTextField(10);
    	username.setBounds(190, 135, 100, 20);
    	frm.add(username);
    	
        //密码框
    	password = new JPasswordField(10);
    	password.setBounds(190, 160, 100, 20);
    	frm.add(password);
    	
        //注册账号
    	register = new JLabel("注册账号");
    	register.setBounds(300, 123, 100, 40);
    	frm.add(register);
    	//为注册账号添加链接
    	register.addMouseListener(new MouseListener() {
    		
    		public void mouseReleased(MouseEvent e) {
    			
    			Desktop desk=Desktop.getDesktop();
    			URI path = null;
    			try {
    				path = new URI("http://zc.qq.com/chs/index.html?from=client&pt_clientver=5479&pt_src=1&ptlang=2052&regkey=C74DB39C0C04892165D4EC8934CC3AF7D4F82CB5CE3E6927F712367058A23491&ADUIN=0&ADSESSION=0&ADTAG=CLIENT.QQ.5479_NewAccount_Btn.0&ADPUBNO=26582");
    				desk.browse(path);
    			} catch (URISyntaxException e1) {
    				// TODO Auto-generated catch block
    				e1.printStackTrace();
    			} catch (IOException e1) {
    				// TODO Auto-generated catch block
    				e1.printStackTrace();
    			}
    							
    		}
    
    		public void mouseExited(MouseEvent e) {
    			// TODO Auto-generated method stub
    			register.setForeground(Color.black);
    		}
    
    		public void mousePressed(MouseEvent e) {
    			// TODO Auto-generated method stub
    			
    
    	
    		}
    
    		public void mouseEntered(MouseEvent e) {
    			// TODO Auto-generated method stub
    			register.setForeground(Color.blue);				
    		}
    
    		@Override
    		public void mouseClicked(MouseEvent e) {
    			// TODO Auto-generated method stub
    			
    		}
    		
    					
    	});
    	
        /回密码
    	lookpsw = new JLabel("找回密码");
    	lookpsw.setBounds(300, 150, 100, 40);
    	frm.add(lookpsw);
    	lookpsw.addMouseListener(new MouseListener() {
    		
    		public void mouseReleased(MouseEvent e) {
    			
    			Desktop desk=Desktop.getDesktop();
    			URI path = null;
    			try {
    				path = new URI("https://aq.qq.com/cn2/findpsw/pc/pc_find_pwd_input_account?source_id=1003&pt_clientver=5467&pt_src=1&ptlang=2052&aquin=534038459 
    

    ");
    desk.browse(path);
    } catch (URISyntaxException e1) {

    				e1.printStackTrace();
    			} catch (IOException e1) {
    				
    				e1.printStackTrace();
    			}								
    		}
    
    		public void mouseExited(MouseEvent e) {
    			
    			lookpsw.setForeground(Color.black);
    		}
    
    		public void mousePressed(MouseEvent e) {
    			
    			
    		}
    
    		public void mouseEntered(MouseEvent e) {
    			
    			lookpsw.setForeground(Color.blue);
    		}
    
    		
    		public void mouseClicked(MouseEvent e) {
    			
    			
    		}
    					
    	});
    
    	//上部背景
    	image1 = new ImageIcon("icon\北部背景01.png");
    	image1.setImage(image1.getImage().getScaledInstance(520, 138, Image.SCALE_DEFAULT));
    	label1 = new JLabel(image1);
    	label1.setBounds(-40, -75, 500, 250);
    	
    	//头像
        image = new ImageIcon("icon\头像01.png");
    	image.setImage(image.getImage().getScaledInstance(80, 80, Image.SCALE_DEFAULT));
    	label = new JLabel(image);
    	label.setBounds(-20, 75, 200, 200);
    	
    	// 下部背景
    	image2 = new ImageIcon("icon\下.png");
    	image2.setImage(image2.getImage().getScaledInstance(470, 250, Image.SCALE_DEFAULT));
    	label2 = new JLabel(image2);
    	label2.setBounds(0, 70, 470, 250);
    	
    	//二维码
    	
    	image3 = new ImageIcon("icon\二维码.png");
    	image3.setImage(image3.getImage().getScaledInstance(30, 30, Image.SCALE_DEFAULT));
    	label3 = new JLabel(image3);
    	label3.setBounds(410, 180, 50, 50);
    	label3.addMouseListener(new MouseListener() {
    		
    		
    		public void mouseReleased(MouseEvent e) {
    			
    			
    		}
    		
    		
    		public void mousePressed(MouseEvent e) {
    			frm.dispose();
    			new ERweima();
    			
    			
    		}
    		
    		
    		public void mouseExited(MouseEvent e) {
    			
    			
    		}
    		
    		
    		public void mouseEntered(MouseEvent e) {
    			
    			
    		}
    		
    		
    		public void mouseClicked(MouseEvent e) {
    			
    			
    		}
    	});
    	
    	//多账号
    	image4 = new ImageIcon("icon\人.png");
    	image4.setImage(image4.getImage().getScaledInstance(35, 35, Image.SCALE_DEFAULT));
    	label4 = new JLabel(image4);
    	label4.setBounds(0, 180, 50, 50);
    	label4.addMouseListener(new MouseListener() {
    		
    	
    		public void mouseReleased(MouseEvent arg0) {
    			
    			
    		}
    		
    		
    		public void mousePressed(MouseEvent arg0) {
    			
    			frm.dispose();
    			new DZHLogin();
    		}
    		
    		
    		public void mouseExited(MouseEvent arg0) {
    			
    			
    		}
    		
    		
    		public void mouseEntered(MouseEvent arg0) {
    			
    			
    		}
    		
    		
    		public void mouseClicked(MouseEvent arg0) {
    			
    			
    		}
    	});
    	
    	
    	label2.add(label3);
    	label2.add(label4);
    	
    	frm.add(label);
    	frm.add(label1);
    	frm.add(label2);
    	
    	
    	frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	frm.setResizable(false);
    	frm.setBounds(700, 200, 460, 330);
    	frm.setVisible(true);
    }
    
    public static void main(String[] args) {
    	new LoginFrame();
    }
    

    程序运行图:

    2、界面:QQ聊天框
    设计人:米健霞
    代码:
    import java.net.;
    import java.awt.
    ;

    import javax.swing.*;

    import java.awt.event.;
    import java.util.
    ;
    import javax.swing.JDialog;

    @SuppressWarnings("serial")
    public class AboutQQ
    extends JFrame
    implements ActionListener,Runnable{ //定义qq界面所需的组件
    static JPanel p1 = new JPanel(), p2 = new JPanel();
    /用来设置滚动条模式, 有四种选择:
    ScrollBars.None (无滚动条),
    ScrollBars.Horizontal(水平滚动条),
    ScrollBars.Vertical(垂直滚动条),
    ScrollBars.Both(水平和垂直滚动条)。
    /
    TextArea output = new TextArea("", 20, 18, TextArea.SCROLLBARS_BOTH),
    input = new TextArea("", 20, 18, TextArea.SCROLLBARS_VERTICAL_ONLY);

    String nicheng1 = "MI"; //定义默认昵称
    String nicheng2 = "对方";

    JButton b_biaoqing = new JButton("表情");
    JButton b_ziti = new JButton("字体");
    JButton b_zitiys = new JButton("字体颜色");
    JButton b_guanbi = new JButton("关闭(Alt+C)");
    JButton b_fasong = new JButton("发送(Alt+S)");

    //线程
    Thread thread1=new Thread(this);

    Color ys = new Color(220, 220, 220);

    public AboutQQ() { //布局qq界面
    super("与XX聊天中");
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    b_fasong.setMnemonic(KeyEvent.VK_S);//发送的快捷键
    b_fasong.addActionListener(this);
    b_guanbi.setMnemonic(KeyEvent.VK_C);//关闭的快捷键
    b_guanbi.addActionListener(this);
    b_biaoqing.addActionListener(this);
    b_ziti.addActionListener(this);
    b_zitiys.addActionListener(this);

    Container cc = getContentPane();
    setBounds(150, 150, 600, 510);
    cc.setLayout(new BorderLayout());
    output.setBackground(Color.white);
    output.setForeground(Color.blue);
    output.setBounds(4, 50, 420, 250);
    output.setFont(new Font("楷体", Font.PLAIN, 14));
    output.setEditable(false);

    ImageIcon image2 = new ImageIcon("imgh.png");
    JLabel label2 = new JLabel(image2);
    label2.setBounds(5,2,45,45);
    p1.add(label2);

    ImageIcon image1 = new ImageIcon("imgqq.png");
    JLabel label1 = new JLabel(image1);
    label1.setBounds(440,30,140,400);
    p1.add(label1);

    ImageIcon image3 = new ImageIcon("imgah.png");
    JLabel label3 = new JLabel(image3);
    label3.setBounds(50,1,340,50);
    p1.add(label3);

    p1.setLayout(null);
    p1.setBackground(new Color(220, 220, 220));
    p1.add(output);
    b_biaoqing.setBounds(4, 303, 60, 25);
    p1.add(b_biaoqing);
    b_ziti.setBounds(65, 303, 60, 25);
    p1.add(b_ziti);
    b_zitiys.setBounds(126, 303, 90, 25);
    p1.add(b_zitiys);
    input.setFont(new Font("楷体", Font.PLAIN, 14));
    input.setBackground(Color.white);
    input.setForeground(Color.blue);
    input.setBounds(4, 330, 420, 125);
    p1.add(input);
    b_guanbi.setBounds(250, 456, 98, 25);
    p1.add(b_guanbi);
    b_fasong.setBounds(350, 456, 98, 25);
    p1.add(b_fasong);
    p1.setBackground(ys);
    cc.add(p1, "Center");

    p2.setBackground(ys);
    p2.setLayout(new GridLayout(10, 1, 1, 10));
    cc.add(p2, "East");
    setVisible(true);
    }

    public void AboutQQ1() {
    }

    public AboutQQ(AboutQQ aboutQQ) {
    // TODO Auto-generated constructor stub
    }

    //执行按钮动作的方法
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == b_fasong) {
    sendData1();
    }

    else if(e.getSource() == b_guanbi){
    System.exit(0);
    }
    }

    //发送及接受数据的方法
    void sendData1(){
    try {
    Calendar rightNow = Calendar.getInstance(); //获取当前系统日期和时间
    int hour = rightNow.get(Calendar.HOUR_OF_DAY); //获取当前时间的整点数
    int year = rightNow.get(Calendar.YEAR);
    int month = rightNow.get(Calendar.MONTH) + 1;
    int day = rightNow.get(Calendar.DATE);
    int minute = rightNow.get(Calendar.MINUTE);
    int second = rightNow.get(Calendar.SECOND);

    String msg = input.getText();
    //if (msg.equals("")) {
    //return;
    //}
    input.setText("");
    //InetAddress tea = InetAddress.getLocalHost();
    //String asd = tea.getHostAddress(); //发送方的IP地址
    output.append(nicheng1 + " " + year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + " " + " " + msg + " ");
    msg = nicheng2 + " " + year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + " " + " " + msg + " ";
    byte[] message = msg.getBytes();
    DatagramPacket packet = new DatagramPacket(message, message.length,9999);
    DatagramSocket socket = new DatagramSocket();
    socket.send(packet);
    }
    catch (Exception e) {
    }
    }

    //等待接受数据的方法
    public void run() {
    if(Thread.currentThread()==thread1){//线程
    try {
    byte[] buffer = new byte[1024];
    DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
    DatagramSocket socket = new DatagramSocket(9999);
    while (true) {
    socket.receive(packet);
    String s = new String(packet.getData(), 0, packet.getLength());
    output.append(s + " ");
    packet = new DatagramPacket(buffer, buffer.length);
    }
    }
    catch (Exception e) {
    }
    }
    }

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    new AboutQQ();
    }

    }

    程序运行图:

  • 相关阅读:
    Oracle数据库死锁和MySQL死锁构造和比较
    shell单引号中输出参数值
    视频流媒体服务器
    使用syncthing进行双机文件同步
    状态(State)模式--设计模式
    中介者(调停者)模式--设计模式
    链表的中间节点
    删除链表中的倒数第N个节点
    Logos讲解--逆向开发
    MonkeyDev安装--逆向开发
  • 原文地址:https://www.cnblogs.com/mijx/p/5560875.html
Copyright © 2011-2022 走看看