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.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; import com.sf.energy.util.Configuration; /** * ?? * * @author cuizhengyang * @version v1.0 * @since version v1.0 */ public class DataConfiguration extends javax.swing.JFrame { /** * */ public DataConfiguration() { initComponents(); this.setResizable(false); } /** * ? */ @SuppressWarnings("unchecked") private void initComponents() { try { config = Configuration.getConfiguration(); } catch (ConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } config.setAutoSave(true); jPanel1 = new javax.swing.JPanel(); scan = new javax.swing.JButton(); pathSubmit = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); backupDays = new javax.swing.JTextField(); backupSubmit = new javax.swing.JButton(); manualBackup = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); filePath = new javax.swing.JTextField(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setTitle("???"); scan.setText("?"); scan.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { scanActionPerformed(evt); } }); pathSubmit.setText(""); pathSubmit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub pathSubmitActionPerformed(e); } }); jLabel2.setText(""); backupSubmit.setText(""); backupSubmit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub backupSubmitAnctionPerformed(e); } }); manualBackup.setText(""); jLabel3.setText(""); jLabel4.setText(""); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(backupDays, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel4).addGap(120, 120, 120).addComponent(backupSubmit)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(filePath, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(scan))) .addGap(18, 18, 18).addComponent(pathSubmit)) .addComponent(manualBackup).addComponent(jLabel3)).addContainerGap(43, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(22, 22, 22).addComponent(jLabel3) .addGap(8, 8, 8) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(scan).addComponent(pathSubmit).addComponent(filePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(24, 24, 24) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(backupSubmit) .addComponent(backupDays, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4)) .addGap(29, 29, 29).addComponent(manualBackup) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); pack(); } /** * ?? * @param evt ? */ private void scanActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser fc = new JFileChooser(); File directory = new File(dir); // ?? fc.setCurrentDirectory(directory); fc.setDialogTitle(""); // FileNameExtensionFilter filter1 = new FileNameExtensionFilter(".xls", "xls"); fc.addChoosableFileFilter(filter1); FileNameExtensionFilter filter2 = new FileNameExtensionFilter(".dmp", "dmp"); fc.addChoosableFileFilter(filter1); // fc.setFileFilter(fc.getAcceptAllFileFilter()); int intRetVal = fc.showOpenDialog(new JFrame()); // ? if (intRetVal == JFileChooser.APPROVE_OPTION) { // ? dir = fc.getSelectedFile().getPath(); // filePath.setText(dir); } } private void pathSubmitActionPerformed(ActionEvent e) { // TODO Auto-generated method stub String path = filePath.getText(); if (path == null || "".equals(path)) { JOptionPane.showMessageDialog(this, "?"); return; } if (config.getString("dbBackup.backupPath") != null) config.setProperty("dbBackup.backupPath", path); else config.addProperty("dbBackup.backupPath", path); JOptionPane.showMessageDialog(this, "??"); } private void backupSubmitAnctionPerformed(ActionEvent e) { // TODO Auto-generated method stub } private static String dir = "."; // Variables declaration - do not modify//GEN-BEGIN:variables // / private javax.swing.JTextField backupDays; // / private javax.swing.JButton backupSubmit; // / private javax.swing.JTextField filePath; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JPanel jPanel1; // / private javax.swing.JButton manualBackup; // / private javax.swing.JButton pathSubmit; // /? private javax.swing.JButton scan; // /?xml private XMLConfiguration config = null; // End of variables declaration//GEN-END:variables }