【java swing 编程】文件替换小秘书(四)
来源:互联网 发布:wifi有信号没网络 编辑:程序博客网 时间:2024/06/10 09:24
文件路径界面实现代码如下:
package panel;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.List;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import util.CommonUtil;import util.PathBean;public class FilePathPanel extends JPanel {private static final long serialVersionUID = 1L;private int gridRows = 10;private JPanel contentPanel = null;private List<PathPanel> pathList = new ArrayList<PathPanel>();public FilePathPanel() {super();setLayout(new BorderLayout());//添加放置按钮的面板JPanel operPanel = new JPanel();operPanel.setLayout(new FlowLayout(FlowLayout.LEFT));JButton addBtn = new JButton("添加", CommonUtil.getImg("image/add.png")); addBtn.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String inputValue = JOptionPane.showInputDialog("请输入映射分类,比如:海南测试环境。");PathPanel pathPanel = new PathPanel((inputValue != null && !"".equals(inputValue.trim())) ? inputValue : "未知分类");pathList.add(pathPanel);if(pathList.size() > gridRows) {contentPanel.setLayout(new GridLayout(pathList.size(), 1));}contentPanel.add(pathPanel);contentPanel.validate();contentPanel.repaint();}});operPanel.add(addBtn);JButton delBtn = new JButton("删除", CommonUtil.getImg("image/del.png"));delBtn.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {if(pathList.size() > 0) {List<PathPanel> checkedList = new ArrayList<PathPanel>();//遍历存在的分类for(PathPanel pathObj : pathList) {if(pathObj.getPathBox().isSelected()) {checkedList.add(pathObj);}}//若勾选了,则删除分类if(checkedList.size() > 0) {for(PathPanel checkedObj : checkedList) {pathList.remove(checkedObj);}contentPanel.removeAll();if(pathList.size() > gridRows) {contentPanel.setLayout(new GridLayout(pathList.size(), 1));} else {contentPanel.setLayout(new GridLayout(gridRows, 1));}for(PathPanel noCheckObj : pathList) {contentPanel.add(noCheckObj);}contentPanel.validate();contentPanel.repaint();} else {CommonUtil.showMsgWin("请选择需要删除的映射分类!", JOptionPane.WARNING_MESSAGE);}} else {CommonUtil.showMsgWin("暂无可选择映射分类!", JOptionPane.INFORMATION_MESSAGE);}}});operPanel.add(delBtn);add(operPanel, BorderLayout.NORTH);//路径配置JPanel pathInfoPanel = new JPanel();pathInfoPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "路径映射"));pathInfoPanel.setLayout(new GridLayout(1, 1));contentPanel = new JPanel();contentPanel.setLayout(new GridLayout(gridRows, 1));pathInfoPanel.add(contentPanel);add(new JScrollPane(pathInfoPanel), BorderLayout.CENTER);}public void addCom(List<PathBean> pathBeanList) {if(pathBeanList.size() > gridRows) {contentPanel.setLayout(new GridLayout(pathBeanList.size(), 1));}PathPanel pathPanel = null;for(PathBean pathBean : pathBeanList) {pathPanel = new PathPanel((pathBean.getType() != null && !"".equals(pathBean.getType().trim())) ? pathBean.getType() : "未知分类");pathPanel.setIndex(pathBean.getIndex());pathPanel.getHostPath().setText(pathBean.getHostPath());pathPanel.getLocalPath().setText(pathBean.getLocalPath());pathList.add(pathPanel);contentPanel.add(pathPanel);}contentPanel.validate();contentPanel.repaint();}public List<PathPanel> getPathList() {return pathList;}public void setPathList(List<PathPanel> pathList) {this.pathList = pathList;}public JPanel getContentPanel() {return contentPanel;}public void setContentPanel(JPanel contentPanel) {this.contentPanel = contentPanel;}}
package panel;import java.awt.FlowLayout;import javax.swing.JCheckBox;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import util.DBSequence;public class PathPanel extends JPanel {private static final long serialVersionUID = 1L;private String index = null;private JCheckBox pathBox = null;private JTextField hostPath = null;private JTextField localPath = null;public PathPanel(String desc) {super();setLayout(new FlowLayout(FlowLayout.LEFT));index = DBSequence.getInstance().getSequence();add(new JLabel("服务器路径:"));hostPath = new JTextField(25);add(hostPath);add(new JLabel("本地路径:"));localPath = new JTextField(25);add(localPath);pathBox = new JCheckBox(desc);add(pathBox);}public JCheckBox getPathBox() {return pathBox;}public void setPathBox(JCheckBox pathBox) {this.pathBox = pathBox;}public JTextField getHostPath() {return hostPath;}public void setHostPath(JTextField hostPath) {this.hostPath = hostPath;}public JTextField getLocalPath() {return localPath;}public void setLocalPath(JTextField localPath) {this.localPath = localPath;}public String getIndex() {return index;}public void setIndex(String index) {this.index = index;}}
0 0
- 【java swing 编程】文件替换小秘书(四)
- 【java swing 编程】文件替换小秘书(一)
- 【java swing 编程】文件替换小秘书(二)
- 【java swing 编程】文件替换小秘书(三)
- 【java swing 编程】文件替换小秘书(五)
- 【java swing 编程】文件替换小秘书(六)
- Swing编程方面步骤之四java绘图技术画小乌龟
- swing入门教程(四) 附加的swing小部件(下)
- swing入门教程(四) 附加的swing小部件(下)
- JAVA Swing图形化编程(一)文件选择器JFileChooser
- 疯狂JAVA讲义---第十二章:Swing编程(四)Applet和JApplet
- 家庭理财小秘书 官方
- 小秘书(mytip) 是什么
- 小秘书 绿色
- 小demo, java swing窗口编程(JDK 1.6)
- 小demo, java swing窗口编程(JDK 1.6) (二)
- JAVA SWING 系统托盘(右下角小图标)
- Java-Swing 小例子
- 关键路径
- UVA - 12001 UVa Panel Discussion
- 推挽输出与开漏输出的区别
- 深入理解计算机系统之链接
- Core Foundation(C对象)与 Foundation(OC对象)之间的转换 理解
- 【java swing 编程】文件替换小秘书(四)
- C语言字节对齐概述
- horspool算法
- Erlang学习笔记
- ACM 87. [NOIP2000] 乘积最大(水dp)
- POJ 2513 Colored Sticks
- html中使用map标签,coords值怎么精确定位gif上的链接
- poj 2008
- ACM 124. [NOI1996]添加号(高精度+dp)