📄 opendialog.java~93~
字号:
package myproject;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import javax.swing.border.Border;
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class OpenDialog extends JDialog {
private JPanel panel1 = new JPanel();
private JLabel jLabel1 = new JLabel();
private XYLayout xYLayout1 = new XYLayout();
private JLabel jLabel2 = new JLabel();
private JTextField factoryField = new JTextField();
private JTextField yearField = new JTextField();
private JLabel jLabel3 = new JLabel();
private JCheckBox jCheckBox1 = new JCheckBox();
private ButtonGroup g=new ButtonGroup() ;
private JRadioButton jRadioButton1 = new JRadioButton();
private JRadioButton jRadioButton2 = new JRadioButton();
private JRadioButton jRadioButton3 = new JRadioButton();
private JRadioButton jRadioButton4 = new JRadioButton();
private JLabel jLabel4 = new JLabel();
private JCheckBox jCheckBox2 = new JCheckBox();
private JCheckBox jCheckBox3 = new JCheckBox();
private JCheckBox jCheckBox4 = new JCheckBox();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private Border border1;
private JLabel jLabel5 = new JLabel();
private JTextField manthField = new JTextField();
private JLabel jLabel6 = new JLabel();
private JTextField dayField = new JTextField();
private JLabel jLabel7 = new JLabel();
private String subFileName = "审计意见书.doc";
private String dir = "./works/";
private String fileName1 = null, fileName2 = null,
fileName3 = null, fileName4 = null;
public OpenDialog(Frame frame, String title, boolean modal) {
super(frame, title, true);
try {
jbInit();
pack();
this.setResizable(false);
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public OpenDialog() {
this(null, "打开对话框", false);
}
private void jbInit() throws Exception {
border1 = BorderFactory.createEmptyBorder(0,10,15,10);
panel1.setLayout(xYLayout1);
jLabel1.setText("请 输 入 打 开 文 件 的 工 厂 名:");
jLabel2.setText("请输入要打开文件的建立时间:");
jLabel3.setText("请选择打开文件类型:");
jRadioButton1.setSelected(true);
jRadioButton1.setText("审计意见书");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jRadioButton1_actionPerformed(e);
}
});
jRadioButton2.setText("审计决定书");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jRadioButton2_actionPerformed(e);
}
});
jRadioButton3.setText("审计工作记录");
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jRadioButton3_actionPerformed(e);
}
});
jRadioButton4.setText("审计工作底稿");
jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jRadioButton4_actionPerformed(e);
}
});
jLabel5.setText("年");
jLabel6.setText("月");
jLabel7.setText("日");
jCheckBox1.setEnabled(false);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
g.add(jRadioButton1 );
g.add(jRadioButton2 );
g.add(jRadioButton3 );
g.add(jRadioButton4 );
jLabel4.setText("请选择要打开的相关文件类型:");
jCheckBox1.setText("审计意见书");
jCheckBox2.setText("审计决定书");
jCheckBox3.setText("审计工作记录");
jCheckBox4.setText("审计工作底稿");
jButton1.setText("确定");
jButton2.setText("取消");
panel1.setBorder(border1);
panel1.add(jLabel1, new XYConstraints(18, 17, 174, 30));
panel1.add(jLabel2, new XYConstraints(18, 53, -1, 35));
panel1.add(factoryField, new XYConstraints(196, 20, 172, 25));
panel1.add(yearField, new XYConstraints(196, 58, 40, 27));
panel1.add(jLabel3,new XYConstraints(18, 103, 133, 28));
panel1.add(jRadioButton3, new XYConstraints(276, 103, 106, 26));
panel1.add(jRadioButton1, new XYConstraints(149, 103, 106, -1));
panel1.add(jRadioButton2, new XYConstraints(149, 131, 106, 26));
panel1.add(jRadioButton4, new XYConstraints(276, 128, 106, 26));
panel1.add(jCheckBox3, new XYConstraints(202, 181, -1, 26));
panel1.add(jCheckBox2, new XYConstraints(110, 181, -1, 26));
panel1.add(jCheckBox1, new XYConstraints(17, 181, -1, -1));
panel1.add(jCheckBox4, new XYConstraints(307, 181, -1, 26));
panel1.add(jLabel4, new XYConstraints(18, 150, 178, 29));
panel1.add(jButton1, new XYConstraints(106, 217, 74, -1));
panel1.add(jButton2, new XYConstraints(201, 217, 74, -1));
panel1.add(manthField, new XYConstraints(255, 58, 40, 27));
panel1.add(dayField, new XYConstraints(313, 58, 40, 27));
panel1.add(jLabel5, new XYConstraints(239, 63, 25, -1));
panel1.add(jLabel6, new XYConstraints(297, 62, 25, -1));
panel1.add(jLabel7, new XYConstraints(356, 61, 25, -1));
this.getContentPane().add(panel1, BorderLayout.NORTH);
}
void jRadioButton1_actionPerformed(ActionEvent e) {
subFileName = "审计意见书.doc";
jCheckBox1.setEnabled(false);
jCheckBox1.setSelected(false);
jCheckBox2.setEnabled(true);
jCheckBox3.setEnabled(true);
jCheckBox4.setEnabled(true);
}
void jRadioButton3_actionPerformed(ActionEvent e) {
subFileName = "审计工作记录.doc";
jCheckBox1.setEnabled(true);
jCheckBox2.setEnabled(true);
jCheckBox3.setEnabled(false);
jCheckBox3.setSelected(false);
jCheckBox4.setEnabled(true);
}
void jRadioButton2_actionPerformed(ActionEvent e) {
subFileName = "审计决定书.doc";
jCheckBox1.setEnabled(true);
jCheckBox2.setEnabled(false);
jCheckBox2.setSelected(false);
jCheckBox3.setEnabled(true);
jCheckBox4.setEnabled(true);
}
void jRadioButton4_actionPerformed(ActionEvent e) {
subFileName = "审计工作底稿.doc";
jCheckBox1.setEnabled(true);
jCheckBox2.setEnabled(true);
jCheckBox3.setEnabled(true);
jCheckBox4.setEnabled(false);
jCheckBox4.setSelected(false);
}
void jButton2_actionPerformed(ActionEvent e) {
this.dispose();
}
void jButton1_actionPerformed(ActionEvent e) {
if(factoryField.getText() != null && factoryField.getText().length()> 0&&
yearField.getText().length() >= 0&& manthField.getText().length()>= 0&& dayField.getText().length()>=0){
String fileName = dir;
String profix = fileName+factoryField.getText()+yearField.getText()+manthField.getText()+dayField.getText();
fileName = profix+subFileName;
System.out.println(fileName);
if(jCheckBox1.isSelected()){
fileName1 = profix +"审计意见书.doc";
}
if(jCheckBox2.isSelected()){
fileName2 = profix +"审计决定书.doc";
}
if(jCheckBox3.isSelected()){
fileName3 = profix +"审计工作记录.doc";
}
if(jCheckBox4.isSelected()){
fileName4 = profix +"审计工作底稿.doc";
}
try{
File file = new File(fileName);
if(file.exists()){
Runtime run = Runtime.getRuntime();
if(fileName1 != null){
run.exec("D:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.EXE "+ fileName1);
}
if(fileName2!= null){
run.exec("D:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.EXE "+ fileName2);
}
if(fileName3 != null){
run.exec("D:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.EXE "+ fileName3);
}
if(fileName4!= null){
run.exec("D:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.EXE "+ fileName4);
}
Process p = run.exec("D:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.EXE "+ fileName);
this.setVisible(false);
this.dispose();
}
else{
JOptionPane.showMessageDialog(this, "文件不存在!!!");
}
}
catch(IOException ex){
System.err.println(ex.toString());
}
}
else{
JOptionPane.showMessageDialog(this, "请输入保存文件的文件夹名称!!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -