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

📄 frame1.java

📁 一个实用的点对点系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
          pictureInStream.close();


          out.close();
          in.close();
          client.close();
        }
      }
      catch (IOException e) {
        fail(e, "Exception while listening for connections");
      }
    }
// 启动服务器主程序
  }

// End of DownloadFile class

  void jButton1_actionPerformed(ActionEvent e) {
    Server hustjgs = new Server(0);
    hustjgs.start();
    DownloadFile husthxl = new DownloadFile(0);
    husthxl.start();
  }

  void jButton3_actionPerformed(ActionEvent e) {
    JFileChooser filechooser = new JFileChooser();
    filechooser.setCurrentDirectory(new File("."));
    filechooser.setFileSelectionMode(0);
    int pp = filechooser.showOpenDialog(this);

    File file_list;
    long lengthoffile;

    if (pp == 0) {
      // selected the current file or directroy
      file_list = filechooser.getSelectedFile();
      // Find the length of the file
      lengthoffile = file_list.length();

      // Display the  text on to the JTextField..
     // String allfile = jTextArea3.getText();
      //jTextArea3.setText(allfile + file_list.toString()+ "\n" );
      list1.add(file_list.toString()+"  "+lengthoffile+"K");

    }

  }

  void jButton4_actionPerformed(ActionEvent e) {
    JFileChooser filechooser = new JFileChooser();
    filechooser.setCurrentDirectory(new File("."));
    filechooser.setFileSelectionMode(1);
    int pp = filechooser.showOpenDialog(this);

   File file_list;
   long lengthoffile;

   if (pp == 0) {
     // selected the current file or directroy
     file_list = filechooser.getSelectedFile();
     // Find the length of the file
     lengthoffile = file_list.length();

     label1.setText(file_list.toString());
     jTextField1.setText(file_list.toString());

   }
  }

  void jButton6_actionPerformed(ActionEvent e) {
    //list1.delItem(list1.getSelectedIndex());
    int i= list1.getSelectedIndex();
    label1.setText(Integer.toString(i));
    //System.out.println(i);
    list1.delItem(list1.getSelectedIndex());
    list1.repaint();
   //list1.remove(list1.getSelectedIndex());
    //list1.remove(list1.getSelectedItem());
  }

  void jButton5_actionPerformed(ActionEvent e) {
    try {
      String IPAdress = textField1.getText();
      Socket clientSocket = new Socket(IPAdress, 6544);
      String ip_address = null;

      // Store the ip address of local host
        InetAddress localHostAddress = InetAddress.getLocalHost();

                // local ip address converted into string
        String local_address = localHostAddress.toString();

        StringTokenizer st = new StringTokenizer(local_address, "/");

                // While loop run till tokens are present
        while(st.hasMoreTokens())
        {
                        // login computer name stored in this variable
                    String machine_owner_name = st.nextToken();

                        // login computer ip address stored in this variable
                    ip_address = st.nextToken();
                    label1.setText(ip_address);
            }


      DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
      DataInputStream in = new DataInputStream(clientSocket.getInputStream());

      String Message ="";
     for(int i=0;i<list1.getItemCount();i++)
     {
       Message = Message+list1.getItem(i)+"*";
     }
     Message =ip_address +"*"+ Message;
     out.writeUTF(Message);
     in.close();
     out.close();
     clientSocket.close();
    }
    catch (Exception c) {
      //System.out.println("Error");
      c.printStackTrace();
    }

  }

  void jButton2_actionPerformed(ActionEvent e) {
    try {
      String IPAdress = label1.getText();
      Socket clientSocket = new Socket(IPAdress, 6544);
      String ip_address = null;

      // Store the ip address of local host
        InetAddress localHostAddress = InetAddress.getLocalHost();

                // local ip address converted into string
        String local_address = localHostAddress.toString();

        StringTokenizer st = new StringTokenizer(local_address, "/");

                // While loop run till tokens are present
        while(st.hasMoreTokens())
        {
                        // login computer name stored in this variable
                    String machine_owner_name = st.nextToken();

                        // login computer ip address stored in this variable
                    ip_address = st.nextToken();
                    //label1.setText(ip_address);
            }


      DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
      DataInputStream in = new DataInputStream(clientSocket.getInputStream());

      String Message ="";
     for(int i=0;i<list1.getItemCount();i++)
     {
       Message = Message+list1.getItem(i)+"*";
     }
     Message =ip_address +"*"+ Message;
     out.writeUTF(Message);
     in.close();
     out.close();
     clientSocket.close();
    }
    catch (Exception c) {
      //System.out.println("Error");
      c.printStackTrace();
    }

  }

  void jButton7_actionPerformed(ActionEvent e) {
    String DownloadFile = list2.getSelectedItem();
    System.out.print(DownloadFile);
    System.out.print(textField1.getText());
    try {
      Socket clientSocket = new Socket(textField1.getText(),9999);
      DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
      DataInputStream  in  = new DataInputStream(clientSocket.getInputStream());

      String fileName = DownloadFile;
      out.writeUTF(fileName);
      System.out.print("下载文件为:"+fileName+"\n");

      StringTokenizer st = new StringTokenizer(fileName,"  ");
          fileName = st.nextToken();



      File pictureFile = new File(fileName);
      if(pictureFile.exists())
        System.out.println("This file" + fileName + " has existed!");
     int i = 0;
     while(pictureFile.exists()) {
       fileName = fileName.substring(0,fileName.indexOf(".")) + i + fileName.substring(fileName.indexOf("."),fileName.length());
       System.out.println(fileName);
       pictureFile = new File(fileName);
       i++;
     }
     //accept picture file;
     FileOutputStream pictureOutStream = new FileOutputStream(pictureFile);
     byte[] pictureData = new byte[4096];
     int byteNumber;
     while((byteNumber = in.read(pictureData)) != -1)
       pictureOutStream.write(pictureData,0,byteNumber);
       pictureOutStream.close();

      in.close();
      out.close();
      clientSocket.close();
     } catch(Exception d) {
      //System.out.println("Error");
      d.printStackTrace();
    }

  }


}

class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_jButton1_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class Frame1_jButton3_actionAdapter implements java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_jButton3_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton3_actionPerformed(e);
  }
}

class Frame1_jButton4_actionAdapter implements java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_jButton4_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton4_actionPerformed(e);
  }
}

class Frame1_jButton6_actionAdapter implements java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_jButton6_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton6_actionPerformed(e);
  }
}

class Frame1_jButton5_actionAdapter implements java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_jButton5_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton5_actionPerformed(e);
  }
}

class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_jButton2_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class Frame1_jButton7_actionAdapter implements java.awt.event.ActionListener {
  Frame1 adaptee;

  Frame1_jButton7_actionAdapter(Frame1 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton7_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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