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

📄 dsblmainframe.java

📁 JAVA开发的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			jtp = new MyJTable(c1, c2);
			jtp.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			rs.close();
			pst.close();
			jtp.addMouseListener(jml1);
			getJScrollPane2().addMouseListener(jml1);
			getJScrollPane2().setViewportView(jtp);
			getJScrollPane2().repaint();
			return jtp;
		} catch (Exception e) {
			System.out.println(e);
		}
		return null;
	}

	/**
	 * This method initializes jPopupMenu1
	 * 
	 * @return javax.swing.JPopupMenu
	 */
	private JPopupMenu getJPopupMenu1() {
		if (jPopupMenu1 == null) {
			jPopupMenu1 = new JPopupMenu();
			jPopupMenu1.add(getJMenuItem9());
			jPopupMenu1.addSeparator();
			jPopupMenu1.add(getJMenuItem2());
			jPopupMenu1.add(getJMenuItem8());
			jPopupMenu1.addSeparator();
			jPopupMenu1.add(getJMenuItem5());
			jPopupMenu1.add(getJMenuItem3());
			jPopupMenu1.add(getJMenuItem4());
			jPopupMenu1.addSeparator();
			jPopupMenu1.add(getJMenuItem6());
			jPopupMenu1.add(getJMenuItem7());
		}
		return jPopupMenu1;
	}

	/**
	 * This method initializes jMenuItem2
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItem2() {
		if (jMenuItem2 == null) {
			jMenuItem2 = new JMenuItem();
			jMenuItem2.setText("刷新");
			jMenuItem2.addActionListener(new Mytj1ActionListener(this));
		}
		return jMenuItem2;
	}

	/**
	 * This method initializes jMenuItem3
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItem3() {
		if (jMenuItem3 == null) {
			jMenuItem3 = new JMenuItem();
			jMenuItem3.setText("删除行");
			jMenuItem3.addActionListener(new Mytj3ActionListener(this));
		}
		return jMenuItem3;
	}
	
	private class Mytj3ActionListener implements java.awt.event.ActionListener {
		private DSBLMainFrame father;

		Mytj3ActionListener(DSBLMainFrame f) {
			super();
			father = f;
		}

		public void actionPerformed(java.awt.event.ActionEvent e) {
			try {
				int[] rows=father.getJTable().getSelectedRows();
				int si=JOptionPane.showConfirmDialog(father,"确定删除这"+rows.length+"条记录吗?\n注意 : 此操作无法恢复","请选择",JOptionPane.YES_NO_OPTION);
				if(si==JOptionPane.YES_OPTION) {
				StringBuffer sb=new StringBuffer();
				sb.append("delete from MyRSAKeys where id in (");
				for(int i=0;i<rows.length-1;i++){
					sb.append("?,");
				}
				sb.append("?)");
				String psql=sb.toString();
				con=father.getConnection();
				PreparedStatement pst = con.prepareStatement(psql);
				
				for(int i=0;i<rows.length;i++){
				int id=Integer.parseInt((String)(father.getJTable().getValueAt(rows[i],0)));
				
				pst.setInt(i+1,id);				
				}
				pst.executeUpdate();
				father.jTable=father.freshJTable();
				father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":) 已经删除这"+rows.length+"条记录\n", sas);
				}
			} catch (Exception e1) {
				try{
				father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":)系统异常=" + e1.toString()+ "\n", sas);
				}catch(Exception e2){
					System.out.println(e2);
				}
			}
		}
	}

	/**
	 * This method initializes jMenuItem4
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItem4() {
		if (jMenuItem4 == null) {
			jMenuItem4 = new JMenuItem();
			jMenuItem4.setText("清空全部密钥");
			jMenuItem4.addActionListener(new Mytj2ActionListener(this));
		}
		return jMenuItem4;
	}

	/**
	 * This method initializes jMenuItem5	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem5() {
		if (jMenuItem5 == null) {
			jMenuItem5 = new JMenuItem();
			jMenuItem5.setText("添加新密钥");
			jMenuItem5.addActionListener(new Mytj5ActionListener(this));
		}
		return jMenuItem5;
	}

	/**
	 * This method initializes jMenuItem6	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem6() {
		if (jMenuItem6 == null) {
			jMenuItem6 = new JMenuItem();
			jMenuItem6.setText("输出公钥到文件");
			jMenuItem6.addActionListener(new Mytj6ActionListener(this));
		}
		return jMenuItem6;
	}
	private class Mytj6ActionListener implements java.awt.event.ActionListener {
		private DSBLMainFrame father;

		Mytj6ActionListener(DSBLMainFrame f) {
			super();
			father = f;
		}

		public void actionPerformed(java.awt.event.ActionEvent e) {
			try {
				JFileChooser fileChooser = new JFileChooser();
				fileChooser.setFileFilter(new JAVAFileFilter1("pub"));
				fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
				int result = fileChooser.showSaveDialog(father);
				if (result == JFileChooser.APPROVE_OPTION) {
					File f = fileChooser.getSelectedFile();
					String fileName=f.getName();
					int index=fileName.lastIndexOf('.');
					if (index<1){      
		                  f=new File(f.getPath()+".pub");
		            }
					int si=JOptionPane.YES_OPTION;
					if(f.exists()) 
						 si=JOptionPane.showConfirmDialog(father,"文件"+f.getPath()+"已经存在,要覆盖它吗?确定覆盖","文件存在",JOptionPane.YES_NO_OPTION);
					if(si==JOptionPane.YES_OPTION) {
					try {
						con=father.getConnection();
						int row=father.getJTable().getSelectedRow();
						int id=Integer.parseInt((String)(father.getJTable().getValueAt(row,0)));
						PreparedStatement pst = con
								.prepareStatement("select * from MyRSAKeys where id=?");
						pst.setInt(1,id);
						ResultSet rs = pst.executeQuery();
						RSAPublicKey r=null;
						RSAPrivateKey p=null;	
						if (rs.next()){
								
							r=(RSAPublicKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(4))).readObject());
							//p=(RSAPrivateKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(5))).readObject());
							
						}
						rs.close();
						FileOutputStream w=new FileOutputStream(f);
						ObjectOutputStream ow = new ObjectOutputStream(w);
						ow.writeObject(r);
						ow.flush();
						ow.close();
						pst.close();
						father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":) 已经将公钥id="+id+"保存到文件:"+f.getPath()+"\n", sas);
					} catch (Exception e1) {
						JOptionPane.showMessageDialog(father, e1.toString(), "错误!",
								JOptionPane.ERROR_MESSAGE);
					}
				}
				}
				
			} catch (Exception e1) {
				try{
				father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":)系统异常=" + e1.toString()+ "\n", sas);
				}catch(Exception e2){
					System.out.println(e2);
				}
			}
		}
	}

	/**
	 * This method initializes jMenuItem7	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem7() {
		if (jMenuItem7 == null) {
			jMenuItem7 = new JMenuItem();
			jMenuItem7.setText("输出私钥到文件");
			jMenuItem7.addActionListener(new Mytj7ActionListener(this));
		}
		return jMenuItem7;
	}
	private class Mytj7ActionListener implements java.awt.event.ActionListener {
		private DSBLMainFrame father;

		Mytj7ActionListener(DSBLMainFrame f) {
			super();
			father = f;
		}

		public void actionPerformed(java.awt.event.ActionEvent e) {
			try {
				JFileChooser fileChooser = new JFileChooser();
				fileChooser.setFileFilter(new JAVAFileFilter2("pri"));
				fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
				int result = fileChooser.showSaveDialog(father);
				if (result == JFileChooser.APPROVE_OPTION) {
					File f = fileChooser.getSelectedFile();
					String fileName=f.getName();
					int index=fileName.lastIndexOf('.');
					if (index<1){      
		                  f=new File(f.getPath()+".pub");
		            }
					int si=JOptionPane.YES_OPTION;
					if(f.exists()) 
						 si=JOptionPane.showConfirmDialog(father,"文件"+f.getPath()+"已经存在,要覆盖它吗?确定覆盖","文件存在",JOptionPane.YES_NO_OPTION);
					if(si==JOptionPane.YES_OPTION) {
					try {
						con=father.getConnection();
						int row=father.getJTable().getSelectedRow();
						int id=Integer.parseInt((String)(father.getJTable().getValueAt(row,0)));
						PreparedStatement pst = con
								.prepareStatement("select * from MyRSAKeys where id=?");
						pst.setInt(1,id);
						ResultSet rs = pst.executeQuery();
						RSAPublicKey r=null;
						RSAPrivateKey p=null;	
						if (rs.next()){
								
							//r=(RSAPublicKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(4))).readObject());
							p=(RSAPrivateKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(5))).readObject());
							
						}
						rs.close();
						FileOutputStream w=new FileOutputStream(f);
						ObjectOutputStream ow = new ObjectOutputStream(w);
						ow.writeObject(p);
						ow.flush();
						ow.close();
						pst.close();
						father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":) 已经将私钥id="+id+"保存到文件:"+f.getPath()+"\n", sas);
					} catch (Exception e1) {
						JOptionPane.showMessageDialog(father, e1.toString(), "错误!",
								JOptionPane.ERROR_MESSAGE);
					}
				}
				}
				
			} catch (Exception e1) {
				try{
				father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":)系统异常=" + e1.toString()+ "\n", sas);
				}catch(Exception e2){
					System.out.println(e2);
				}
			}
		}
	}
	/**
	 * This method initializes jMenuItem8	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem8() {
		if (jMenuItem8 == null) {
			jMenuItem8 = new JMenuItem();
			jMenuItem8.setText("显示详细信息");
			jMenuItem8.addActionListener(new Mytj8ActionListener(this));
		}
		return jMenuItem8;
	}
	private class Mytj8ActionListener implements java.awt.event.ActionListener {
		private DSBLMainFrame father;

		Mytj8ActionListener(DSBLMainFrame f) {
			super();
			father = f;
		}

		public void actionPerformed(java.awt.event.ActionEvent e) {
			try {
				con=father.getConnection();
				int row=father.getJTable().getSelectedRow();
				int id=Integer.parseInt((String)(father.getJTable().getValueAt(row,0)));
				PreparedStatement pst = con
						.prepareStatement("select * from MyRSAKeys where id=?");
				pst.setInt(1,id);
				ResultSet rs = pst.executeQuery();
				if (rs.next()){
					RSAPublicKey r=null;
					RSAPrivateKey p=null;
					father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":)RSA密钥详细信息=\n", sas);
					father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),(RSAPublicKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(4))).readObject())+"\n", sas);
					father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),(RSAPrivateKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(5))).readObject())+"\n", sas);
				}
				rs.close();
			} catch (Exception e1) {
				try{
				father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":)系统异常=" + e1.toString()+ "\n", sas);
				}catch(Exception e2){
					System.out.println(e2);
				}
			}
		}
	}

	/**
	 * This method initializes jMenuItem9	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem9() {
		if (jMenuItem9 == null) {
			jMenuItem9 = new JMenuItem();
			jMenuItem9.setText("使用该私钥");
			jMenuItem9.addActionListener(new Mytj9ActionListener(this));
		}
		return jMenuItem9;
	}
	
	private class Mytj9ActionListener implements java.awt.event.ActionListener {
		private DSBLMainFrame father;

		Mytj9ActionListener(DSBLMainFrame f) {
			super();
			father = f;
		}

		public void actionPerformed(java.awt.event.ActionEvent e) {
			try {
				con=father.getConnection();
				int row=father.getJTable().getSelectedRow();
				int id=Integer.parseInt((String)(father.getJTable().getValueAt(row,0)));
				PreparedStatement pst = con
						.prepareStatement("select * from MyRSAKeys where id=?");
				pst.setInt(1,id);
				ResultSet rs = pst.executeQuery();
				if (rs.next()){
					father.recoveryPubKey=(RSAPublicKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(4))).readObject());
					father.priKey=(RSAPrivateKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(5))).readObject());
					father.getJTextField1().setText("我的RSA密钥库中id="+id+"密钥");
				}
				rs.close();
				 
					
				
			} catch (Exception e1) {
				try{
				father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":)系统异常=" + e1.toString()+ "\n", sas);
				}catch(Exception e2){
					System.out.println(e2);
				}
			}
		}
	}

	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setBounds(new java.awt.Rectangle(95,137,306,22));
			jTextField1.setText("无");
			jTextField1.setEditable(false);
		}
		return jTextField1;
	}

	/**
	 * This method initializes jTextField3	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField3() {
		if (jTextField3 == null) {
			jTextField3 = new JTextField();
			jTextField3.setBounds(new java.awt.Rectangle(94,172,305,22));
		}
		return jTextField3;
	}

	/**
	 * This method initializes jButton4	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -