⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsblmainframe.java

📁 JAVA开发的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				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 + -