?? dsblmainframe.java
字號:
if (index<1){
f=new File(f.getPath()+".txt");
}
int si=JOptionPane.YES_OPTION;
if(f.exists())
si=JOptionPane.showConfirmDialog(father,"文件"+f.getPath()+"已經存在,要覆蓋它嗎?確定覆蓋","文件存在",JOptionPane.YES_NO_OPTION);
if(si==JOptionPane.YES_OPTION) {
try {
OutputStreamWriter w = new OutputStreamWriter(
new FileOutputStream(f));
BufferedWriter ow = new BufferedWriter(w, 1024);
ow.write(father.getJTextPane().getText());
ow.flush();
ow.close();
} catch (Exception e1) {
JOptionPane.showMessageDialog(father, e1.toString(), "錯誤!",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
}
/**
* This method initializes jTabbedPane
*
* @return javax.swing.JTabbedPane
*/
private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
jTabbedPane.setBounds(new java.awt.Rectangle(2, 1, 583, 284));
jTabbedPane.setBackground(java.awt.Color.white);
jTabbedPane.addTab("MD5摘要", null, getJPanel(), null);
jTabbedPane.addTab("生成簽名", null, getJPanel3(), null);
jTabbedPane.addTab("驗證簽名", null, getJPanel2(), "");
}
return jTabbedPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jLabel3 = new JLabel();
jLabel3.setBounds(new java.awt.Rectangle(27, 183, 53, 22));
jLabel3.setText("文件名:");
jLabel2 = new JLabel();
jLabel2.setBounds(new java.awt.Rectangle(28, 162, 81, 18));
jLabel2.setText("文件摘要計算:");
jLabel1 = new JLabel();
jLabel1.setBounds(new java.awt.Rectangle(27, 33, 48, 22));
jLabel1.setText("原消息");
jLabel = new JLabel();
jLabel.setBounds(new java.awt.Rectangle(26, 9, 124, 28));
jLabel.setText("文本消息摘要計算:");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBackground(java.awt.Color.white);
jPanel.add(jLabel, null);
jPanel.add(jLabel1, null);
jPanel.add(getJScrollPane1(), null);
jPanel.add(getJButton(), null);
jPanel.add(jLabel2, null);
jPanel.add(getJTextField(), null);
jPanel.add(jLabel3, null);
jPanel.add(getJButton1(), null);
jPanel.add(getJButton2(), null);
}
return jPanel;
}
/**
* This method initializes jPanel2
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel2() {
if (jPanel2 == null) {
jLabel11 = new JLabel();
jLabel11.setBounds(new java.awt.Rectangle(81,183,59,18));
jLabel11.setText("簽名文件:");
jLabel10 = new JLabel();
jLabel10.setBounds(new java.awt.Rectangle(94,159,47,18));
jLabel10.setText("源文件:");
jLabel9 = new JLabel();
jLabel9.setBounds(new java.awt.Rectangle(16,135,124,18));
jLabel9.setText("當前使用的驗證公鑰:");
jLabel6 = new JLabel();
jLabel6.setBounds(new java.awt.Rectangle(17,15,91,18));
jLabel6.setText("驗證公鑰記錄:");
jPanel2 = new JPanel();
jPanel2.setLayout(null);
jPanel2.setBackground(java.awt.Color.white);
jPanel2.add(jLabel6, null);
jPanel2.add(getJScrollPane3(), null);
jPanel2.add(jLabel9, null);
jPanel2.add(getJTextField2(), null);
jPanel2.add(getJButton3(), null);
jPanel2.add(jLabel10, null);
jPanel2.add(getJTextField5(), null);
jPanel2.add(getJButton7(), null);
jPanel2.add(jLabel11, null);
jPanel2.add(getJTextField6(), null);
jPanel2.add(getJButton8(), null);
jPanel2.add(getJButton9(), null);
}
return jPanel2;
}
/**
* This method initializes jPanel3
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel3() {
if (jPanel3 == null) {
jLabel8 = new JLabel();
jLabel8.setBounds(new java.awt.Rectangle(10,202,86,18));
jLabel8.setText("簽名輸出文件:");
jLabel7 = new JLabel();
jLabel7.setBounds(new java.awt.Rectangle(12,173,89,18));
jLabel7.setText("待簽名文件:");
jLabel5 = new JLabel();
jLabel5.setBounds(new java.awt.Rectangle(9,140,99,18));
jLabel5.setText("當前RSA密鑰:");
jLabel4 = new JLabel();
jLabel4.setBounds(new java.awt.Rectangle(13, 13, 113, 18));
jLabel4.setText("我的RSA密鑰庫:");
jPanel3 = new JPanel();
jPanel3.setLayout(null);
jPanel3.setBackground(java.awt.Color.white);
jPanel3.add(jLabel4, null);
jPanel3.add(getJScrollPane2(), null);
jPanel3.add(jLabel5, null);
jPanel3.add(getJTextField1(), null);
jPanel3.add(jLabel7, null);
jPanel3.add(getJTextField3(), null);
jPanel3.add(getJButton4(), null);
jPanel3.add(getJButton5(), null);
jPanel3.add(getJTextField4(), null);
jPanel3.add(jLabel8, null);
jPanel3.add(getJButton6(), null);
}
return jPanel3;
}
/**
* This method initializes jScrollPane1
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane1() {
if (jScrollPane1 == null) {
jScrollPane1 = new JScrollPane();
jScrollPane1.setBounds(new java.awt.Rectangle(27, 58, 446, 64));
jScrollPane1.setViewportView(getJTextPane1());
}
return jScrollPane1;
}
/**
* This method initializes jTextPane1
*
* @return javax.swing.JTextPane
*/
private JTextPane getJTextPane1() {
if (jTextPane1 == null) {
jTextPane1 = new JTextPane();
}
return jTextPane1;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new java.awt.Rectangle(477, 97, 88, 24));
jButton.setText("計算摘要");
jButton.addActionListener(new ICActionListener(this));
}
return jButton;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new java.awt.Rectangle(87, 181, 280, 25));
}
return jTextField;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new java.awt.Rectangle(377, 180, 92, 25));
jButton1.setText("選擇文件");
jButton1.addActionListener(new FCActionListener(this));
}
return jButton1;
}
private class FCActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
FCActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(father);
if (result == JFileChooser.APPROVE_OPTION) {
father.fc = fileChooser.getSelectedFile();
try {
father.getJTextField().setText(fc.toString());
} catch (Exception e1) {
JOptionPane.showMessageDialog(father, e1.toString(), "錯誤!",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
private class FDCActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
FDCActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
File ftemp = new File(father.getJTextField().getText());
lyMD5 md5 = new lyMD5();
String md5digest = md5.getMD5Digest(ftemp);
// java.sql.Date dtmp=new java.sql.Date(new
// java.util.Date().getTime());
father.getJTextPane().getDocument().insertString(
father.getJTextPane().getDocument().getLength(),
"(" + new java.util.Date() + ":)文件消息摘要=" + md5digest
+ "\n", sas);
} catch (FileNotFoundException e1) {
JOptionPane.showMessageDialog(father, "請輸入正確的文件名,或選擇文件。",
"錯誤!", JOptionPane.ERROR_MESSAGE);
} catch (Exception e2) {
JOptionPane.showMessageDialog(father, e2.toString(), "錯誤!",
JOptionPane.ERROR_MESSAGE);
}
}
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setBounds(new java.awt.Rectangle(476, 180, 89, 25));
jButton2.setText("文件摘要");
jButton2.addActionListener(new FDCActionListener(this));
}
return jButton2;
}
/**
* This method initializes jMenuItem1
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem1() {
if (jMenuItem1 == null) {
jMenuItem1 = new JMenuItem();
jMenuItem1.setText("保存到文件");
jMenuItem1.addActionListener(new MyJMenuItem1ActionListener(this));
}
return jMenuItem1;
}
/**
* This method initializes jScrollPane2
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane2() {
if (jScrollPane2 == null) {
jScrollPane2 = new JScrollPane();
jScrollPane2.setBounds(new java.awt.Rectangle(6,30,561,97));
jScrollPane2.setViewportView(getJTable());
}
return jScrollPane2;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
jTable = this.freshJTable();
}
return jTable;
}
private class Mytj1ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
Mytj1ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
father.jTable = father.freshJTable();
} catch (Exception e1) {
System.out.println(e1);
}
}
}
private class Mytj2ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
Mytj2ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
int si=JOptionPane.showConfirmDialog(father,"確定清空所有密鑰記錄嗎?\n注意 : 此操作無法恢復","請選擇",JOptionPane.YES_NO_OPTION);
if(si==JOptionPane.YES_OPTION) {
con = father.getConnection();
PreparedStatement pst = con
.prepareStatement("delete from MyRSAKeys");
pst.executeQuery();
pst.close();
father.jTable=father.freshJTable();
father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":) 所有記錄已經清空\n", sas);
}
} catch (Exception e1) {
father.jTable=father.freshJTable();
}
}
}
private class Mytj5ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
Mytj5ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
//MDialog dlg = new MDialog(null,this,"Query For Detail",true);
AddRSAKeyDialog dlg=new AddRSAKeyDialog(null,father,"添加RSA密鑰:",true);
dlg.setSize(481, 341);
dlg.setResizable(false);
dlg.setVisible(true);
//if (dlg.flag==1) father.jTable = father.freshJTable();
} catch (Exception e1) {
System.out.println(e1);
}
}
}
public JTable freshJTable() {
String[] c2 = { "編號", "名稱", "描述", "公鑰", "私鑰", "創建日期" };
int i = 0;
ResultSet rs = null;
JTable jtp=null;
try {
con=this.getConnection();
PreparedStatement pst = con
.prepareStatement("select count(*) from MyRSAKeys");
rs = pst.executeQuery();
if (rs.next())
i = rs.getInt(1);
pst = con.prepareStatement("select * from MyRSAKeys");
rs = pst.executeQuery();
int j = 0;
Object[][] c1 = new String[i][6];
while (rs.next()) {
c1[j][0] = Integer.toString(rs.getInt("id"));
c1[j][1] = new String(rs.getString("name").trim());
c1[j][2] = new String(rs.getString("description").trim());
c1[j][3] = new String("長二進制數據");
c1[j][4] = new String("長二進制數據");
c1[j][5] = new String(rs.getString("create_data").trim());
j++;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -