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

📄 configframe.java

📁 飞鸽传书的源代码 快速的局域网传输软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing (java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowClosing
    {//GEN-HEADEREND:event_formWindowClosing
        // TODO 将在此处添加您的处理代码:
        dispose();
    }//GEN-LAST:event_formWindowClosing

    private void saveButtonActionPerformed (java.awt.event.ActionEvent evt)//GEN-FIRST:event_saveButtonActionPerformed
    {//GEN-HEADEREND:event_saveButtonActionPerformed
        // TODO 将在此处添加您的处理代码:
            JFileChooser fc = new JFileChooser(); 
            fc.setFileSelectionMode ( JFileChooser.FILES_ONLY);
            if ( fc.showSaveDialog ( this ) == JFileChooser.CANCEL_OPTION ) return;
            File target = fc.getSelectedFile ();
            copy("config.ini",target.getPath () + target.getName ());
    }//GEN-LAST:event_saveButtonActionPerformed

    private void fileInButtonActionPerformed (java.awt.event.ActionEvent evt)//GEN-FIRST:event_fileInButtonActionPerformed
    {//GEN-HEADEREND:event_fileInButtonActionPerformed
        // TODO 将在此处添加您的处理代码:
            JFileChooser fc = new JFileChooser(); 
            fc.setFileSelectionMode ( JFileChooser.FILES_ONLY);
            if ( fc.showOpenDialog ( this ) == JFileChooser.CANCEL_OPTION ) return;
            File file = fc.getSelectedFile ();
            RandomAccessFile rf;
        try
        {
            rf = new RandomAccessFile (file, "rw");
            rf.seek (0);
            String strIP = "";
             while( (strIP = rf.readLine().trim () ) != null )
             {  
                  if ( MainFrame.getIPType (strIP) == 0 ) 
                  {
                      JOptionPane.showMessageDialog(null,"文件格式不合法,请重新选择!","错误", JOptionPane.DEFAULT_OPTION);
                      return;
                  }
                  for (int i = 0 ; i < model.size () ; i ++)
                      if (strIP.equals (( String ) model.get ( i ))) continue;
                  model.addElement (strIP);
             }
            rf.close();  
        } 
        catch ( Exception ex )
        {
            ex.printStackTrace();
        }    
    }//GEN-LAST:event_fileInButtonActionPerformed

    private void jButton4ActionPerformed (java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton4ActionPerformed
    {//GEN-HEADEREND:event_jButton4ActionPerformed
        // TODO 将在此处添加您的处理代码:
       model.clear ();
        String local;
        try
        {
            local = MainFrame.getBNet(InetAddress.getLocalHost().getHostAddress());
            model.addElement (local);
        } catch (UnknownHostException ex)
        {
            ex.printStackTrace();
        }
       
    }//GEN-LAST:event_jButton4ActionPerformed

    private void delButtonActionPerformed (java.awt.event.ActionEvent evt)//GEN-FIRST:event_delButtonActionPerformed
    {//GEN-HEADEREND:event_delButtonActionPerformed
        // TODO 将在此处添加您的处理代码:
        int index = IPList.getSelectedIndex ();
        if ( index != -1)
            model.remove ( index );
    }//GEN-LAST:event_delButtonActionPerformed

    private void applyButtonActionPerformed (java.awt.event.ActionEvent evt)//GEN-FIRST:event_applyButtonActionPerformed
    {//GEN-HEADEREND:event_applyButtonActionPerformed
        // TODO 将在此处添加您的处理代码:
        apply();
    }//GEN-LAST:event_applyButtonActionPerformed

    private void OKButtonActionPerformed (java.awt.event.ActionEvent evt)//GEN-FIRST:event_OKButtonActionPerformed
    {//GEN-HEADEREND:event_OKButtonActionPerformed
        // TODO 将在此处添加您的处理代码:
        apply();
        dispose();
    }//GEN-LAST:event_OKButtonActionPerformed

    private void addButtonActionPerformed (java.awt.event.ActionEvent evt)//GEN-FIRST:event_addButtonActionPerformed
    {//GEN-HEADEREND:event_addButtonActionPerformed
        // TODO 将在此处添加您的处理代码:
        String strIP = this.IPTextField.getText ();
        if ( MainFrame.getIPType ( strIP ) == 0)
        {
            JOptionPane.showMessageDialog(null,"IP地址不合法,请重新输入","错误", JOptionPane.DEFAULT_OPTION);
            return;
        }
        else model.addElement (strIP);
        
    }//GEN-LAST:event_addButtonActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main (String args[])
    {
        java.awt.EventQueue.invokeLater (new Runnable ()
        {
            public void run ()
            {
                new ConfigFrame ().setVisible (true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JList IPList;
    private javax.swing.JTextField IPTextField;
    private javax.swing.JButton OKButton;
    private javax.swing.JButton addButton;
    private javax.swing.JButton applyButton;
    private javax.swing.JButton delButton;
    private javax.swing.JButton fileInButton;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton saveButton;
    // 变量声明结束//GEN-END:variables
    
    void init()
    {
        File file = new File("config.ini");
        RandomAccessFile fout;
        boolean isExist = file.exists ();
        try
        {
         if ( !isExist ) file.createNewFile ();
         fout = new RandomAccessFile (file, "rw");   
         if( !isExist ){
                String local = MainFrame.getBNet(InetAddress.getLocalHost ().getHostAddress ());
                fout.writeChars (local +"\r\n");
         } 
         String strIP;
         fout.seek (0);
         while( (strIP = fout.readLine() ) != null )
         {  
              model.addElement (strIP);
         }
          fout.close(); 
        } 
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
        
        void apply()
        {
            try{
                File file = new File( "config.ini" );
	    	if( file.exists() )
	    		file.delete ();
                file.createNewFile ();
                RandomAccessFile rf = new RandomAccessFile(file,"rw");    	
                for (int i = 0 ; i < model.getSize () ;i ++)
                {
                    String strIP = (String) model.get (i);
                    rf.writeBytes ( strIP + "\r\n");
                }
                  rf.close();  
                
            }
            catch (Exception e){
            System.out.println (e.toString ());
            }
        }
        void copy (String src,String tar)
        {   
                
                try{
                File file1 = new File( src );
                File file2 = new File( tar ); 
	    	if( !file1.exists() )
                { 
                    JOptionPane.showMessageDialog(null,"文件不存在","错误", JOptionPane.DEFAULT_OPTION);
                    return;
                }
                if ( file2.exists () )
                {
                    if ( JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(null, 
"文件已存在,是否覆盖!", "提示", JOptionPane.YES_NO_OPTION)) return;
                    else file2.delete ();
                }
                file2.createNewFile ();
                RandomAccessFile rf1 = new RandomAccessFile(file1,"rw");    	
                RandomAccessFile rf2 = new RandomAccessFile(file2,"rw"); 
                String strIP = "";
                while ( true )
                {
                    strIP = rf1.readLine ();
                    if ( strIP == null )break;
                    strIP = strIP.trim ();
                    if (strIP == "")break;
                    rf2.writeBytes (strIP + "\r\n");
                }
                rf1.close();
                rf2.close();
                
            }
            catch (Exception e){
            System.out.println (e.toString ());
            }
        }
}

⌨️ 快捷键说明

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