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

📄 mainframe.java

📁 有关JAVA的程序,研究P2P的chord协议,相信大家会喜欢的!
💻 JAVA
字号:
package javanet;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Vector;
import java.net.Socket;
import java.net.BindException;
import java.net.*;

public class mainFrame
    extends JFrame {
  Socket socket = null;
  Vector threads = null;
  startTCP tcp = null;
  JPanel contentPane;
  BorderLayout borderLayout1 = new BorderLayout();
  JPanel jPanel1 = new JPanel();
  TitledBorder titledBorder1 = new TitledBorder("操作");
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
  JLabel jButton4 = new JLabel();
  JLabel jLabel1 = new JLabel();
  JOptionPane prompt = new JOptionPane();
  Vector v = new Vector();
  fileTS ts;
  public mainFrame() {
    try {
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      jbInit();
    }
    catch (BindException er) {
      prompt.showMessageDialog(this, "服务已经开启,或端口被占用!", "错误", 0);
      System.exit(0);
      return;
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    contentPane = (JPanel) getContentPane();
    contentPane.setLayout(null);
    setSize(new Dimension(402, 334));
    setTitle("网络快递");
    jPanel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
    jPanel1.setBorder(titledBorder1);
    jPanel1.setBounds(new Rectangle(21, 18, 122, 233));
    jPanel1.setLayout(null);
    titledBorder1.setTitleFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
    jButton1.setBounds(new Rectangle(19, 181, 85, 32));
    jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
    jButton1.setText("扫      描");
    jButton1.addActionListener(new mainFrame_jButton1_actionAdapter(this));
    jButton2.setBounds(new Rectangle(19, 109, 85, 32));
    jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
    jButton2.setText("发送文件");
    jButton2.addActionListener(new mainFrame_jButton2_actionAdapter(this));
    jButton3.setBounds(new Rectangle(19, 35, 85, 32));
    jButton3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
    jButton3.setText("聊      天");
    jButton3.addActionListener(new mainFrame_jButton3_actionAdapter(this));
    jButton4.setBounds(new Rectangle(0, 270, 60, 30));
    jButton4.setFont(new java.awt.Font("Dialog", Font.BOLD, 14));
    jButton4.setForeground(SystemColor.activeCaptionBorder);
    jButton4.setBorder(BorderFactory.createLoweredBevelBorder());
    jButton4.setText("状态:");
    contentPane.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
    jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 13));
    jLabel1.setForeground(SystemColor.inactiveCaption);
    jLabel1.setBorder(BorderFactory.createLoweredBevelBorder());
    jLabel1.setText("");
    jLabel1.setBounds(new Rectangle(60, 270, 340, 30));
    contentPane.add(jPanel1);
    jPanel1.add(jButton1);
    jPanel1.add(jButton2);
    jPanel1.add(jButton3);
    contentPane.add(jButton4);
    contentPane.add(jLabel1);
    jLabel1.setText("   无连接,无任务");
    tcp = new startTCP(this);
    new Thread(tcp).start();
    this.setResizable(false);
  }

  public void jButton2_actionPerformed(ActionEvent e) {
    String ip=prompt.showInputDialog(this, "请填写发送目标:", "选择", 2);
    try
    {
        ip.equals("");
      }catch(Exception er){return;}
    FileDialog file=new FileDialog(this,"请选择文件");
    file.show();
    String fn=file.getFile();
    String fp=file.getDirectory()+file.getFile();
    try {
      fileTS obj = new fileTS(ip, prompt, fn, fp);
      new Thread(obj).start();
    }
    catch (UnknownHostException ex) {
      prompt.showMessageDialog(this,"未能连接到指定主机.","错误",0);
      return;
    }
    catch (IOException ex) {ex.printStackTrace();}
  }

  public void jButton3_actionPerformed(ActionEvent e) {
    Talk talk=new Talk();
    talk.show();
  }

  public void jButton1_actionPerformed(ActionEvent e) {
    Scanhost obj=new Scanhost();
    obj.show();
  }

  class mainFrame_jButton2_actionAdapter
      implements ActionListener {
    private mainFrame adaptee;
    mainFrame_jButton2_actionAdapter(mainFrame adaptee) {
      this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
      adaptee.jButton2_actionPerformed(e);
    }
  }
}

class mainFrame_jButton1_actionAdapter
    implements ActionListener {
  private mainFrame adaptee;
  mainFrame_jButton1_actionAdapter(mainFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class mainFrame_jButton3_actionAdapter
    implements ActionListener {
  private mainFrame adaptee;
  mainFrame_jButton3_actionAdapter(mainFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton3_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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