JLabel label_1 = new JLabel("u590Du5236u5730u5740uFF1A"); label_1.setBounds(10, 40, 70, 15); getContentPane().add(label_1);
textField_1 = new JTextField(); textField_1.setBounds(90, 38, 300, 21); getContentPane().add(textField_1); textField_1.setColumns(10);
JButton button_1 = new JButton("u9009u62E9u5730u5740"); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { do_button_1_actionPerformed(e); } }); button_1.setBounds(400, 39, 93, 23); getContentPane().add(button_1);
JButton button_2 = new JButton("u5F00u59CBu590Du5236"); button_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { do_copyButton_actionPerformed(e); } }); button_2.setBounds(182, 69, 93, 23); getContentPane().add(button_2); } protected void do_button_actionPerformed(ActionEvent e){ JFileChooser chooser=new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); // 显示文件打开对话框 int option = chooser.showOpenDialog(this); // 确定用户按下打开按钮,而非取消按钮 if (option != JFileChooser.APPROVE_OPTION) return; // 获取用户选择的文件对象 file = chooser.getSelectedFile(); // 显示文件信息到文本框 textField.setText(file.toString()); } protected void do_button_1_actionPerformed(ActionEvent e){ JFileChooser chooser=new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int option=chooser.showOpenDialog(this); if(option!=JFileChooser.APPROVE_OPTION) return; file=chooser.getSelectedFile(); textField_1.setText(file.toString()); } //确定复制按钮单击事件 protected void do_copyButton_actionPerformed(ActionEvent arg0) { Thread thread = new Thread(this); thread.start(); } //应用多线程技术实现读取操作 @Override public void run() { ProgressMonitorTest test = new ProgressMonitorTest(); String path = textField.getText(); String save = textField_1.getText(); test.useProgressMonitor(this,path,save+path.substring(path.lastIndexOf("."),path.length()));
} } (编辑:西安站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|