?? configframe.java
字號:
);
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 + -