⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryinf.java

📁 与大家分享
💻 JAVA
字号:
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;

public class QueryInf extends JFrame implements ActionListener{

	private static final long serialVersionUID = 1L;
	
	JPanel  pnlQueryInf;
	JLabel  lblUserName,lblGender,lblAge,lblPassword,lblEmail,logoPosition;
	JLabel  userName, gender, age, password, email;
	JButton btnReturn;
	String  strServerIp="localhost";
	JLabel  Ilabel;
	String name;
	
	final JLabel headLabel = new JLabel();
    //用于将窗口用于定位
	Dimension scrnsize;
    Toolkit toolkit=Toolkit.getDefaultToolkit();
    //构造方法
    public QueryInf(String name){
    	super("查询用户基本信息");
    	pnlQueryInf = new JPanel();
    	this.name = name;
    	this.getContentPane().add(pnlQueryInf);

    	lblUserName = new JLabel("用户名");
    	userName = new JLabel(name);
    	lblGender = new JLabel("性别");
    	lblPassword = new JLabel("密码");
    	lblAge = new JLabel("年龄");
    	lblEmail = new JLabel("邮箱");
    	gender = new JLabel();
    	age = new JLabel();
    	password = new JLabel();
    	email = new JLabel();
    	
    	btnReturn = new JButton("返回");
    	
    	
    	Information data = new Information();
		data.setUserName(name);
		
		 //String status=null;
    	try
		{
		    //连接到服务器
		    Socket toServer = new Socket(strServerIp,30002); //生成Socket函数对象 
		    ObjectOutputStream streamToServer=new ObjectOutputStream (toServer.getOutputStream());  
		    //获得输出流	
		    //把客户详细资料写到服务器socket
		    streamToServer.writeObject((Information)data);
            //读来自服务器socket的状态
            BufferedReader fromServer=new BufferedReader(new InputStreamReader(toServer.getInputStream()));
            String status=fromServer.readLine();
            //告知用户成功消息
            JOptionPane.showMessageDialog(null,status);
		
            if (status.equals("查询成功")){
            	Information inf = new Information();
            	userName.setText(name);
            	
            	gender.setText(inf.getUserGender());
            	age.setText(inf.getUserAge());
            	password.setText(inf.getUserPwd());
            	email.setText(inf.getUserEmail());
            	
            	/*  该布局采用手动布局           *
        		 * setBounds设置组件位置        *
        		 *  setFont设置字体、字型、字号  *
        		 * setForeground设置文字的颜色  *
        		 *  setBackground设置背景色      *
        		 *  setOpaque将背景设置为透明    */
        		
        		pnlQueryInf.setLayout(null);   
        		pnlQueryInf.setBackground(new Color(125,100,175));
        		
        		lblUserName.setBounds(30,80,100,30);
        		userName.setBounds(110,85,120,20);
        		lblPassword.setBounds(30,141,100,30);
        		password.setBounds(110,146,120,20);
        		lblGender.setBounds(30,191,100,30);
        		lblAge.setBounds(30,216,100,30);
        		age.setBounds(110,221,120,20);
        		lblEmail.setBounds(30,241,80,30);
        		email.setBounds(110,246,120,20);
        		
        		btnReturn.setBounds(246,300,80,25);
        		
        		Font fontstr=new Font("宋体",Font.PLAIN,12);	
        		lblUserName.setFont(fontstr);
        	    lblGender.setFont(fontstr);
        		lblPassword.setFont(fontstr);
        		lblAge.setFont(fontstr);
        		lblEmail.setFont(fontstr);
        		userName.setFont(fontstr);
        	    gender.setFont(fontstr);
        		password.setFont(fontstr);
        		age.setFont(fontstr);
        		email.setFont(fontstr);
        		btnReturn.setFont(fontstr);
        		
        		
        		lblUserName.setForeground(Color.BLACK);
        		lblGender.setForeground(Color.BLACK);
        		lblPassword.setForeground(Color.BLACK);
        		lblAge.setForeground(Color.BLACK);
        		lblEmail.setForeground(Color.BLACK);
        		userName.setForeground(Color.BLACK);
        		gender.setForeground(Color.BLACK);
        		password.setForeground(Color.BLACK);
        		btnReturn.setBackground(Color.ORANGE);
        		
        		pnlQueryInf.add(lblUserName);
        		pnlQueryInf.add(lblGender);
        		pnlQueryInf.add(lblPassword);
        		pnlQueryInf.add(lblAge);
        		pnlQueryInf.add(lblEmail);
        		pnlQueryInf.add(userName);
        		pnlQueryInf.add(gender);
        		pnlQueryInf.add(password);
        		pnlQueryInf.add(age);
        		pnlQueryInf.add(email);
        		
        		//设置背景图片
        	    Icon logo = new ImageIcon("image\\i.jpg");
        	 	logoPosition = new JLabel(logo);
        		logoPosition.setBounds(0, 0, 360,78);
        		pnlQueryInf.add(logoPosition);
        	    
        	    this.setSize(370,380);
        		this.setVisible(true);
        		this.setResizable(false);
        		//将窗口定位在屏幕中央
            	scrnsize=toolkit.getScreenSize();
            	this.setLocation(scrnsize.width/2-this.getWidth()/2,
            	                 scrnsize.height/2-this.getHeight()/2);
        		Image img=toolkit.getImage("images\\10.jpg");
                this.setIconImage(img);
        		//按钮注册监听
                btnReturn.addActionListener(this);
            }}catch (ConnectException e1) {
    			JOptionPane.showMessageDialog(null, "未能建立到指定服务器的连接!");
    		} catch (InvalidClassException e2) {
    			JOptionPane.showMessageDialog(null, "类错误!");
    		} catch (NotSerializableException e3) {
    			JOptionPane.showMessageDialog(null, "对象未序列化!");
    		} catch (IOException e4) {
    			JOptionPane.showMessageDialog(null, "不能写入到指定服务器!");
    		}
	
    }

	public void actionPerformed(ActionEvent ae) {
		// TODO Auto-generated method stub
		Object source = ae.getSource();
		if (source.equals(btnReturn)){
			this.dispose();
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -