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

📄 hhl.java

📁 一个很好玩的小游戏
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
  ImageIcon icon3=new ImageIcon("image/3.gif");
  ImageIcon icon4=new ImageIcon("image/4.gif");
  JPanel jp=new JPanel();
  JSplitPane jsp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,jsc,jp);
  String mypassname;
  String who;

  Frame1(String passtowho,String whopass,String pass)
   {
   	
 //界面部分
 //****************************************
    jf = (JPanel) this.getContentPane();
    namearea.setFont(new java.awt.Font("Dialog", 0, 13));
    namearea.setBorder(BorderFactory.createEtchedBorder());
    namearea.setHorizontalAlignment(SwingConstants.LEFT);
    namearea.setText(" "+passtowho);
    mypassname = pass;
    who = whopass;
    namearea.setBounds(new Rectangle(51, 6, 140, 33));
    jf.setLayout(null);
    this.setSize(new Dimension(500, 382));
    this.setTitle("发送到"+passtowho);
    this.setLocation(350,300);
    name.setFont(new java.awt.Font("Dialog", 0, 13));
    name.setBorder(BorderFactory.createEtchedBorder());
    name.setDebugGraphicsOptions(0);
    name.setDoubleBuffered(false);
    name.setMinimumSize(new Dimension(43, 23));
    name.setOpaque(false);
    name.setRequestFocusEnabled(true);
    name.setToolTipText("");
    name.setHorizontalAlignment(SwingConstants.RIGHT);
    name.setHorizontalTextPosition(SwingConstants.CENTER);
    name.setIconTextGap(4);
    name.setText("呢称:");
    name.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
    name.setBounds(new Rectangle(9, 6, 45, 33));
    e_mailarea.setBounds(new Rectangle(53, 41, 270, 31));
    e_mailarea.setText("该用户没有填写邮箱");
    e_mailarea.setBorder(BorderFactory.createEtchedBorder());
    e_mailarea.setHorizontalAlignment(SwingConstants.LEFT);
    e_mailarea.setFont(new java.awt.Font("Dialog", 0, 13));
    e_mail.setBounds(new Rectangle(8, 41, 46, 31));
    e_mail.setText("邮箱:");
    e_mail.setBorder(BorderFactory.createEtchedBorder());
    e_mail.setToolTipText("");
    e_mail.setHorizontalAlignment(SwingConstants.RIGHT);
    e_mail.setFont(new java.awt.Font("Dialog", 0, 13));
    icon.setEnabled(true);
    icon.setBorder(BorderFactory.createEtchedBorder());
    icon.setHorizontalAlignment(SwingConstants.CENTER);
    icon.setIcon(icon3);
    icon.setIconTextGap(4);
    icon.setText("头像");
    icon.setBounds(new Rectangle(388, 4, 95, 110));
    icon.addMouseListener(new MouseAdapter(){
            public void mouseClicked(MouseEvent e)
            {
                    JOptionPane.showMessageDialog(null,"该用户没有填写个人资料");

            }
            });
    ip.setFont(new java.awt.Font("Dialog", 0, 14));
    ip.setHorizontalAlignment(SwingConstants.CENTER);
    ip.setText("对方的ip为:");
    ip.setBounds(new Rectangle(8, 79, 366, 33));
    simple.setFont(new java.awt.Font("Dialog", 0, 13));
    simple.setToolTipText("");
    simple.setHorizontalAlignment(SwingConstants.CENTER);
    simple.setText("按ctrl+enter发送");
    simple.setBounds(new Rectangle(192, 6, 181, 33));
    jsp2.setBounds(new Rectangle(5, 119, 485, 233));
    jsp2.setDividerLocation(488);
    jsp2.setBorder(BorderFactory.createEtchedBorder());
    jsp2.setOpaque(false);
    jsp2.setPreferredSize(new Dimension(476, 218));
    jsp2.setBottomComponent(jp);
    jsp2.setContinuousLayout(true);
    jsp2.setDividerSize(15);
    jsp2.setLastDividerLocation(400);
    jsp2.setLeftComponent(jsc);
    jsp2.setOneTouchExpandable(true);
    jsp2.setEnabled(false);
    jt.addKeyListener(new KeyAdapter(){
                  public void keyPressed(KeyEvent e)
                  {
                       int keyCode = e.getKeyCode();
                    int modifiers = e.getModifiers();
                     if (modifiers==2 & keyCode==10)
                     {
                             if (jt.getText().compareTo("")==0)
                                {
                                        JOptionPane.showMessageDialog(null,"空消息不发送");
                                }
                                else
                                {
                                	clientservice.usrName=who;
									clientservice.msg=jt.getText();
									clientservice.flag=namearea.getText();
									ts=new thSend();
									ts.start();
                                    dispose();
                                }
                    }
                  }
                  });
    jsc.setBounds(new Rectangle(5, 124, 488, 233));
    jt.setText("");
    jb1.setBounds(0,0,70,25);
    jb1.addActionListener(new ActionListener()
    {
            public void actionPerformed(ActionEvent e)
            {
                    dispose();
                    new cschat(mypassname);


            }
    });
    jb2.setBounds(0,25,70,25);
    jb2.addActionListener(new ActionListener()
    {
            public void actionPerformed(ActionEvent e)
            {
                    new getfile();
             }

    });
    jp.setLayout(null);
    jp.setBorder(BorderFactory.createEtchedBorder());
    jp.setDoubleBuffered(true);
    jp.add(jb1,null);
    jp.add(jb2,null);
    jf.add(e_mail, null);
    jf.add(icon, null);
    jf.add(e_mailarea, null);
    jf.add(namearea, null);
    jf.add(name, null);
    jf.add(simple, null);
    jf.add(jsp2, null);
    jf.add(ip, null);
    this.setResizable(false);
    jsc.getViewport().add(jt, null);
  }
  
}

/*

//传送文件部分
//*********************************************
class sendfile extends JFrame
{
	JPanel filecontent;
	JFileChooser file = new JFileChooser();
	OutputStream outfie;
	FileInputStream in;
	private Socket sock=null;
	byte[] buf=new byte[1024];
	int num;
	
sendfile()
{
	filecontent = (JPanel)this.getContentPane();
	filecontent.setLayout(null);
	this.setTitle("选择你要传送的文件");
	this.setSize(410,320);
	this.setLocation(300,300);
	file.setBounds(0,0,400,300);
	file.addActionListener(new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			File f1 = file.getSelectedFile();
			System.out.println(f1.getName());
			dispose();
			try
			{
				sock = new Socket("127.0.0.1",4388);
				in = new FileInputStream(f1.getName());
				BufferedInputStream bis=new BufferedInputStream(in,1024);
				while((num=bis.read(buf))!=-1)
				{					
					if(num<1024)
					{
						byte[] wbuf = new byte[num];
						for (int i = 0; i < num; i++) 
						{
							wbuf[i] = buf[i];
						}
					}
					outfie.write(buf);
				}
				outfie.close();
				bis.close();
			}
			catch(Exception fe){dispose();}
		}
	});
	filecontent.add(file,null);
	this.setVisible(true);
}
protected void processWindowEvent(WindowEvent e)
   {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING)
    {
    	dispose();
    }
   }

}
*/


//接收文件部分
//*********************************************
class getfile extends JFrame {
  JPanel contentPane;
  JLabel message = new JLabel();
  JButton ok = new JButton();
  JButton cance = new JButton();
  final static private int BUFFER=1024;  
  Socket sock;
  InputStream in;
  FileOutputStream fos;


  public getfile() {
  	try
  	{
  		sock = new Socket("127.0.0.1", 4388);
  		in = sock.getInputStream();
  		fos=new FileOutputStream("image/getfile/get.gif");
  	}
  	catch(Exception e){}
    contentPane = (JPanel) this.getContentPane();
    this.setLocation(200,200);
    message.setFont(new java.awt.Font("Dialog", 0, 14));
    message.setBorder(BorderFactory.createEtchedBorder());
    message.setHorizontalAlignment(SwingConstants.CENTER);
    message.setText("有文件到");
    message.setBounds(new Rectangle(9, 10, 168, 34));
    contentPane.setLayout(null);
    this.setTitle("有文件到");
    this.setSize(new Dimension(200, 114));
    ok.setBounds(new Rectangle(9, 55, 74, 28));
    ok.setFont(new java.awt.Font("Dialog", 0, 13));
    ok.setText("接受");    
    ok.addActionListener(new ActionListener()
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		if(in != null)
    		{    		
			try{
    							dispose();
								int num=0;
								byte[] buf=new byte[BUFFER];
								while((num=in.read(buf))!=-1)
								{
								if(num<BUFFER)
								{
									byte[] wbuf = new byte[num];
									for (int i = 0; i < num; i++) 
									{
										wbuf[i] = buf[i];
									}
								}
								fos.write(buf);
								}
								fos.flush();
								fos.close();
								in.close();			
								}
								catch(Exception ioe){ioe.printStackTrace();}
								
								succ suc = new succ();
								suc.show(true);	
    							in = null;
    			}
    		
    			
    	}
    });
    cance.setBounds(new Rectangle(97, 55, 78, 28));
    cance.setFont(new java.awt.Font("Dialog", 0, 13));
    cance.setText("拒绝");
    cance.addActionListener(new ActionListener()
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		System.out.println("b t y");
    		dispose();
    	}
    });
    contentPane.add(message, null);
    contentPane.add(ok, null);
    contentPane.add(cance, null);
    this.setVisible(true);
  }

  protected void processWindowEvent(WindowEvent e)
   {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING)
    {
    	dispose();
    }
   }
   


class succ extends JFrame
   {
   	
   	JPanel contentPane1;
   	JLabel jl;
   	JButton jb;
   	
   	succ()
   	{
   		contentPane1 = (JPanel) this.getContentPane();
   		this.setSize(100,90);
   		this.setLocation(300,200);
   		contentPane1.setLayout(null);
   		jl = new JLabel();
   		jl.setBounds(0,0,100,30);
   		jl.setFont(new java.awt.Font("Dialog", 0, 13));
   		jl.setHorizontalAlignment(SwingConstants.CENTER);
   		jl.setText("文件传送完毕!");
   		jb = new JButton("确定");
   		jb.setFont(new java.awt.Font("Dialog", 0, 13));
   		jb.setBounds(20,35,60,25);
   		jb.addActionListener(new ActionListener()
   		{
   			public void actionPerformed(ActionEvent e)
   			{
   				dispose();
   			}
   		});
   		contentPane1.add(jl,null);
   		contentPane1.add(jb,null);
   		this.setVisible(true);
   		
   	}
   }
  }




//消息接收框
//*****************************************************************************

 class receiveFrame extends JFrame {

 //界面部分
  JPanel jf;
  JLabel namearea = new JLabel();
  JLabel name = new JLabel();
  JLabel e_mailarea = new JLabel();
  JLabel e_mail = new JLabel();
  JLabel icon = new JLabel();
  JTextArea jt=new JTextArea();
  JScrollPane jsc = new JScrollPane();
  JLabel ip = new JLabel();
  JLabel simple = new JLabel();
  ImageIcon icon1=new ImageIcon("image/1.gif");
  ImageIcon icon2=new ImageIcon("image/2.gif");
  ImageIcon icon3=new ImageIcon("image/3.gif");
  ImageIcon icon4=new ImageIcon("image/4.gif");
  String passmessage1;
  String sname1;
  String who;

  receiveFrame(String passname,String whopass,String passmessage)
   {
 //界面部分实例化
    jf = (JPanel) this.getContentPane();
    namearea.setFont(new java.awt.Font("Dialog", 0, 13));
    namearea.setBorder(BorderFactory.createEtchedBorder());
    namearea.setHorizontalAlignment(SwingConstants.LEFT);
    //namearea.setText(" "+passname);
    namearea.setText(" "+whopass);
    sname1 = passname;
    who = whopass;

⌨️ 快捷键说明

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