package com.lx.product.seal.frame; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class PathPanel extends JPanel { public String name="path_panel"; Font ft =new Font("微软雅黑", Font.BOLD, 14); public JTextField product_version_root = new JTextField (); public JTextField install_project_root = new JTextField (); public JTextField product_web_root = new JTextField (); public JTextField product_java_root = new JTextField (); public JTextField product_version = new JTextField (); private JFileChooser path_select = new JFileChooser (); private JButton product_version_button = new JButton (); private JButton install_project_button = new JButton (); private JButton product_web_button = new JButton (); private JButton product_java_button = new JButton (); public PathPanel(MasterPanel f) { product_version_root.setFont(ft); install_project_root.setFont(ft); product_web_root.setFont(ft); product_java_root.setFont(ft); product_version.setFont(ft); path_select.setFont(ft); product_version_button.setFont(ft); install_project_button.setFont(ft); product_web_button.setFont(ft); product_java_button.setFont(ft); product_version_root.setPreferredSize(new Dimension(500, 30)); install_project_root.setPreferredSize(new Dimension(500, 30)); product_web_root.setPreferredSize(new Dimension(500, 30)); product_java_root.setPreferredSize(new Dimension(500, 30)); product_version.setPreferredSize(new Dimension(500, 30)); path_select.setPreferredSize(new Dimension(500, 30)); path_select.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY ); product_version_button.setText("选择目录"); product_version_button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(product_version_root.getText()!="") path_select.setCurrentDirectory(new File(product_version_root.getText())); int result=path_select.showOpenDialog(product_version_button); if (result == JFileChooser.APPROVE_OPTION) { // 如果点击了"保存", 则获取选择的保存路径 File file = path_select.getSelectedFile(); product_version_root.setText( file.getAbsolutePath()); } } }); install_project_button.setText("选择目录"); install_project_button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(install_project_root.getText()!="") path_select.setCurrentDirectory(new File(install_project_root.getText())); int result=path_select.showOpenDialog(install_project_button); if (result == JFileChooser.APPROVE_OPTION) { // 如果点击了"保存", 则获取选择的保存路径 File file = path_select.getSelectedFile(); install_project_root.setText( file.getAbsolutePath()); } } }); product_web_button.setText("选择目录"); product_web_button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(product_web_root.getText()!="") path_select.setCurrentDirectory(new File(product_web_root.getText())); int result=path_select.showOpenDialog(product_web_button); if (result == JFileChooser.APPROVE_OPTION) { // 如果点击了"保存", 则获取选择的保存路径 File file = path_select.getSelectedFile(); product_web_root.setText( file.getAbsolutePath()); } } }); product_java_button.setText("选择目录"); product_java_button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(product_java_root.getText()!="") path_select.setCurrentDirectory(new File(product_java_root.getText())); int result=path_select.showOpenDialog(product_java_button); if (result == JFileChooser.APPROVE_OPTION) { // 如果点击了"保存", 则获取选择的保存路径 File file = path_select.getSelectedFile(); product_java_root.setText( file.getAbsolutePath()); } } }); GridBagLayout bg = new GridBagLayout(); this.setLayout(bg); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; c.insets = new Insets(2, 5, 2, 5); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.gridheight = 1; c.weightx = 0; c.weighty = 0; JLabel sl = new JLabel(); sl.setText("产品版本管理目录:"); sl.setFont(ft); sl.setHorizontalAlignment(JLabel.LEFT); this.add(sl, c); c.gridy = 1; c.gridwidth = 1; product_version_root.setText(f.config.getProduct_version_root()); this.add(product_version_root, c); c.gridx = 1; this.add(product_version_button, c); c.gridx = 0; c.gridwidth = 2; c.gridy = 2; this.add(new JLabel(" "), c); c.gridy = 3; JLabel l3= new JLabel("产品安装工程目录(product-server-install):"); l3.setFont(ft); this.add(l3, c); c.gridwidth = 1; c.gridy = 4; install_project_root.setText(f.config.getInstall_project_root()); this.add(install_project_root, c); c.gridx = 1; this.add(install_project_button, c); c.gridx = 0; c.gridwidth = 2; c.gridy = 5; this.add(new JLabel(" "), c); c.gridy = 6; JLabel l4=new JLabel("前端代码目录(product-web):"); l4.setFont(ft); this.add(l4, c); c.gridwidth = 1; c.gridy = 7; product_web_root.setText(f.config.getProduct_web_root()); this.add(product_web_root, c); c.gridx = 1; this.add(product_web_button, c); c.gridx = 0; c.gridwidth = 2; c.gridy = 8; this.add(new JLabel(" "), c); c.gridy = 9; JLabel pl = new JLabel(); pl.setText("后端代码目录(product-server-web):"); pl.setFont(ft); this.add(pl, c); c.gridwidth = 1; c.gridy = 10; product_java_root.setText(f.config.getProduct_java_root()); this.add(product_java_root, c); c.gridx = 1; this.add(product_java_button, c); c.gridx = 0; c.gridwidth = 2; c.gridy = 11; this.add(new JLabel(" "), c); c.gridy = 12; JLabel vl = new JLabel(); vl.setText("产品版本号,以V开头,如:V1.0.2:"); vl.setFont(ft); this.add(vl, c); c.gridy = 13; product_version.setText(f.config.getProduct_version()); this.add(product_version, c); } }