Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.sf.energy.transfer.form; import java.io.File; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.WindowConstants; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; import com.sf.energy.transfer.tftcp.TranClientHandler; import com.sf.energy.util.Configuration; /** * * <????> * @author lujinquan * @version v1.0 * @since version v1.0 */ public class ServerConfiguration extends javax.swing.JFrame { /** * Creates new form ServerConfiguration */ public ServerConfiguration() { initComponents(); this.setResizable(false); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" // desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); reset = new javax.swing.JButton(); submit = new javax.swing.JButton(); try { config = Configuration.getConfiguration(); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } config.setAutoSave(true); ipAddress = new javax.swing.JTextField(); ipPort = new javax.swing.JTextField(); transferName = new javax.swing.JTextField(); String ip = config.getString("server.serverIP"); String port = config.getString("server.serverPort"); String name = config.getString("server.transferName"); if (ip != null && !"".equals(ip) && port != null && !"".equals(port) && port != null && !"".equals(port)) { ipAddress.setText(ip); ipPort.setText(port); transferName.setText(name); } setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setTitle("??"); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText(" ? IP "); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setText(" ? ?"); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel3.setText("???"); reset.setText("?"); reset.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { resetActionPerformed(evt); } }); submit.setText(""); submit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { submitActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(reset) .addGap(40, 40, 40).addComponent(submit).addGap(104, 104, 104)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(63, 63, 63) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel2)) .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(ipPort, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(ipAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(transferName, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(73, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(23, 23, 23) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(ipAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(23, 23, 23) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(ipPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(31, 31, 31) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3).addComponent(transferName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(33, 33, 33) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(reset).addComponent(submit)) .addContainerGap(27, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents //? private void resetActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_resetActionPerformed // TODO add your handling code here: String ip = config.getString("server.serverIP"); ipAddress.setText(ip); String port = config.getString("server.serverPort"); ipPort.setText(port); String name = config.getString("server.transferName"); transferName.setText(name); }// GEN-LAST:event_resetActionPerformed // private void submitActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_submitActionPerformed //System.out.println("macarthur"); String ip = ipAddress.getText(); String port = ipPort.getText(); String name = transferName.getText(); if (ip == null || "".equals(ip) || port == null || "".equals(port) || port == null || "".equals(port)) { JOptionPane.showMessageDialog(this, "?"); return; } String regex = "(((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))"; if (!ip.matches(regex)) { JOptionPane.showMessageDialog(this, "ip??"); return; } String xmlip = config.getString("server.serverIP"); String xmlport = config.getString("server.serverPort"); String xmlname = config.getString("server.transferName"); if (xmlip != null && !"".equals(xmlip)) { config.setProperty("server.serverIP", ip); } else { config.addProperty("server.serverIP", ip); } if (xmlport != null && !"".equals(xmlport)) { config.setProperty("server.serverPort", port); } else { config.addProperty("server.serverPort", port); } if (port != null && !"".equals(xmlport)) { config.setProperty("server.transferName", name); } else { config.addProperty("server.transferName", name); } // TranClientHandler.tranCientIoSession.close(); this.dispose(); }// GEN-LAST:event_submitActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables // / ?IP private javax.swing.JTextField ipAddress; // / ??? private javax.swing.JTextField transferName; // / ??? private javax.swing.JTextField ipPort; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPanel jPanel1; // / ? private javax.swing.JButton reset; // / private javax.swing.JButton submit; // /?xml private XMLConfiguration config = null; // End of variables declaration//GEN-END:variables }