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

📄 pathselect.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
字号:
package net.aetherial.gis.our.allauto.frame;

import javax.swing.JPanel;
import javax.swing.JTextField;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import java.io.File;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import net.aetherial.gis.surface.ItemValue;
import javax.swing.JFileChooser;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class PathSelect
    extends JPanel {
  private String arrayPath = "file\\array\\";
  /**
   * 是否显示选取数组,
   * 默认显示
   */
  private boolean isShowArraySelect = true;
  public PathSelect() {
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public PathSelect(boolean arraySelect) {
    this.isShowArraySelect = arraySelect;
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }

  }

  /**
   * 不显示选取数组
   */
  public void setHideArraySelect() {
    this.isShowArraySelect = false;
  }

  /**
   * 得到输入路径
   */
  public String getInputPath() {
    return setRealDirectory(jinput.getText());
  }

  /**
   * 得到输出路径
   */
  public String getOutputPath() {
    return setRealDirectory(joutput.getText());
  }

  /**
   * 得到数组路径
   */
  public String getArrayPath() {
    return setRealDirectory(jarray.getText());
  }

  public void setInputPath(String inputPath){
    jinput.setText(inputPath);
  }

  public void setOutputPath(String outputPath){
    joutput.setText(outputPath);
  }
 public void reSet(){
   this.jarray.setText("");
   this.jinput.setText("");
   this.joutput.setText("");
 }
  private String setRealDirectory(String path) {
    if (path.endsWith("\\")) {
      return path;
    }
    else if (path.endsWith("/")) {
      return path;
    }
    else {
      return path + "\\";
    }
  }

  private void jbInit() throws Exception {
    jinput.setText("");
    this.setLayout(xYLayout1);
    joutput.setText("");
    arrayPath = new File(arrayPath).getAbsolutePath();
    jarray.setText(arrayPath);
    jLabel1.setText("输入路径:");
    jLabel2.setText("输出路径:");
    jLabel3.setText("数组路径:");
    jButton1.setText("选择路径");
    jButton2.setText("选择路径");
    jButton3.setText("选择路径");
    jButton1.addActionListener(new PathSelect_actionAdapter(this));
    jButton2.addActionListener(new PathSelect_actionAdapter(this));
    jButton3.addActionListener(new PathSelect_actionAdapter(this));
    xYLayout1.setWidth(458);
    xYLayout1.setHeight(300);
    this.add(jLabel1, new XYConstraints(22, 38, -1, -1));
    this.add(jLabel2, new XYConstraints(22, 68, -1, -1));
    this.add(jButton1, new XYConstraints(348, 34, -1, -1));
    this.add(jButton2, new XYConstraints(348, 62, -1, -1));
    this.add(jinput, new XYConstraints(87, 36, 246, -1));
    this.add(joutput, new XYConstraints(87, 64, 246, 22));
    if (this.isShowArraySelect) {
      this.add(jLabel3, new XYConstraints(22, 95, -1, -1));
      this.add(jButton3, new XYConstraints(348, 90, -1, -1));
      this.add(jarray, new XYConstraints(87, 92, 246, 22));
    }

  }

  private JTextField jinput = new JTextField();
  private XYLayout xYLayout1 = new XYLayout();
  private JTextField joutput = new JTextField();
  private JTextField jarray = new JTextField();
  private JLabel jLabel1 = new JLabel();
  private JLabel jLabel2 = new JLabel();
  private JLabel jLabel3 = new JLabel();
  private JButton jButton1 = new JButton();
  private JButton jButton2 = new JButton();
  private JButton jButton3 = new JButton();
  public void jButton_actionPerformed(ActionEvent e) {
    if (e.getSource().equals(this.jButton1)) {
      this.selectPath(jinput);
    }
    else if (e.getSource().equals(this.jButton2)) {
      this.selectPath(joutput);
    }
    else if (e.getSource().equals(this.jButton3)) {
      this.selectPath(jarray);
    }
  }

  private void selectPath(JTextField jText) {
    JFileChooser fileDialog = new JFileChooser();
    fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (! (ItemValue.fileChoosePath.equals(""))) {
      fileDialog.setCurrentDirectory(new File(ItemValue.fileChoosePath));
    }
    int result = fileDialog.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
      File f = fileDialog.getSelectedFile();
      ItemValue.fileChoosePath = f.getAbsolutePath();
      jText.setText(f.getAbsolutePath());
    }
  }

}

class PathSelect_actionAdapter
    implements ActionListener {
  private PathSelect adaptee;
  PathSelect_actionAdapter(PathSelect adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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