📄 addorsadialog.java
字号:
package ly.util;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.interfaces.RSAPublicKey;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.JButton;
public class AddORSADialog extends JDialog {
private RSAPublicKey inspectPubKey=null;
private JPanel jContentPane = null;
private DSBLMainFrame father;
private JPanel jPanel = null;
private JLabel jLabel = null;
private JTextField jTextField = null;
private JLabel jLabel1 = null;
private JTextField jTextField1 = null;
private JLabel jLabel2 = null;
private JScrollPane jScrollPane = null;
private JTextPane jTextPane = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
public AddORSADialog(Frame owner,DSBLMainFrame ft, String title, boolean modal) {
super(owner, title, modal);
father=ft;
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(446, 313);
this.setContentPane(getJContentPane());
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(), java.awt.BorderLayout.CENTER);
}
return jContentPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jLabel2 = new JLabel();
jLabel2.setBounds(new java.awt.Rectangle(37,96,38,18));
jLabel2.setText("描述:");
jLabel1 = new JLabel();
jLabel1.setBounds(new java.awt.Rectangle(37,66,37,18));
jLabel1.setText("名称:");
jLabel = new JLabel();
jLabel.setBounds(new java.awt.Rectangle(38,32,36,18));
jLabel.setText("公钥:");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.add(jLabel, null);
jPanel.add(getJTextField(), null);
jPanel.add(jLabel1, null);
jPanel.add(getJTextField1(), null);
jPanel.add(jLabel2, null);
jPanel.add(getJScrollPane(), null);
jPanel.add(getJButton(), null);
jPanel.add(getJButton1(), null);
jPanel.add(getJButton2(), null);
}
return jPanel;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new java.awt.Rectangle(76,30,206,22));
jTextField.setEditable(false);
}
return jTextField;
}
/**
* This method initializes jTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setBounds(new java.awt.Rectangle(76,65,208,22));
}
return jTextField1;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new java.awt.Rectangle(38,114,363,99));
jScrollPane.setViewportView(getJTextPane());
}
return jScrollPane;
}
/**
* This method initializes jTextPane
*
* @return javax.swing.JTextPane
*/
private JTextPane getJTextPane() {
if (jTextPane == null) {
jTextPane = new JTextPane();
}
return jTextPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new java.awt.Rectangle(292,29,113,23));
jButton.setText("从文件导入");
jButton.addActionListener(new jbActionListener(this));
}
return jButton;
}
private class jbActionListener implements java.awt.event.ActionListener {
private AddORSADialog father;
jbActionListener(AddORSADialog f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new JAVAFileFilter1("pub"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(father);
if (result == JFileChooser.APPROVE_OPTION) {
File f = fileChooser.getSelectedFile();
try {
FileInputStream sin=new FileInputStream(f);
ObjectInputStream oin=new ObjectInputStream(sin);
RSAPublicKey ptemp=(RSAPublicKey)oin.readObject();
if(ptemp instanceof RSAPublicKey) {
father.inspectPubKey=ptemp;
father.getJTextField().setText("来自文件"+f.getPath());
}else throw new Exception("文件类型不对");
} catch (Exception e1) {
JOptionPane.showMessageDialog(father, "文件找不到或者文件类型不对,非合适类型!", "错误!",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new java.awt.Rectangle(221,235,93,24));
jButton1.setText("确定添加");
jButton1.addActionListener(new MyB1ActionListener(this));
}
return jButton1;
}
private class MyB1ActionListener implements java.awt.event.ActionListener {
private AddORSADialog father;
public MyB1ActionListener(AddORSADialog ft) {
super();
father = ft;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
if (father.inspectPubKey!= null) {
try {
ByteArrayOutputStream bout1 = new ByteArrayOutputStream();
ObjectOutputStream oout1 = new ObjectOutputStream(
bout1);
oout1.writeObject(inspectPubKey);
oout1.flush();
oout1.close();
ByteArrayInputStream pubin = new ByteArrayInputStream(
bout1.toByteArray());
Connection con = father.father.getConnection();
PreparedStatement pst = con
.prepareStatement("insert into ORSA(name,description,RSApublicKey,create_data) values (?,?,?,?)");
pst.setString(1, father.getJTextField1().getText());
pst.setString(2, father.getJTextPane().getText());
pst
.setBinaryStream(3, pubin, pubin
.available());
pst.setString(4, new java.sql.Date(
new java.util.Date().getTime())
.toString());
pst.executeUpdate();
father.father.getJTextPane().getDocument().insertString(father.father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":) 以添加记录,名称为"+father.getJTextField1().getText()+"\n", father.father.sas);
father.father.jTable1=father.father.refreshJTable1();
father.dispose();
} catch (Exception e1) {
JOptionPane.showMessageDialog(father, e
.toString(), "错误:",
JOptionPane.ERROR_MESSAGE);
}
} else
JOptionPane.showMessageDialog(father, "密钥不正确,请生成密钥!", "错误:",
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(324,235,84,24));
jButton2.setText("取消");
jButton2.addActionListener(new MyB3ActionListener(this));
}
return jButton2;
}
private class MyB3ActionListener implements java.awt.event.ActionListener {
private AddORSADialog father;
public MyB3ActionListener(AddORSADialog ft) {
super();
father = ft;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
father.dispose();
}
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -