小型的课程设计

源代码在线查看: 文件加密.java

软件大小: 125 K
上传用户: magicchange
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*				 * 文件加密.java				 *				 * Created on 2008年12月5日, 下午6:16				 */								/**				 *				 * @author  Administrator				 */				import javax.swing.*;				import java.io.*;				import java.awt.*;								public class 文件加密 extends javax.swing.JFrame {								    /** Creates new form 文件加密 */				    public 文件加密() {				        initComponents();				    }								    /** This method is called from within the constructor to				     * initialize the form.				     * WARNING: Do NOT modify this code. The content of this method is				     * always regenerated by the Form Editor.				     */				    @SuppressWarnings("unchecked")				    // //GEN-BEGIN:initComponents				    private void initComponents() {								        jLabel1 = new javax.swing.JLabel();				        jLabel2 = new javax.swing.JLabel();				        jLabel3 = new javax.swing.JLabel();				        mima = new javax.swing.JTextField();				        chongshumima = new javax.swing.JTextField();				        jLabel4 = new javax.swing.JLabel();				        lujing = new javax.swing.JLabel();				        jButton1 = new javax.swing.JButton();				        jButton2 = new javax.swing.JButton();				        jButton3 = new javax.swing.JButton();				        jButton4 = new javax.swing.JButton();				        mimats = new javax.swing.JLabel();				        mimacsti = new javax.swing.JLabel();								        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);				        setTitle("文件加密");				        addWindowListener(new java.awt.event.WindowAdapter() {				            public void windowClosed(java.awt.event.WindowEvent evt) {				                formWindowClosed(evt);				            }				        });								        jLabel1.setFont(new java.awt.Font("宋体", 1, 36));				        jLabel1.setText("文件加密");								        jLabel2.setFont(new java.awt.Font("宋体", 1, 14));				        jLabel2.setText("请输入密码:");								        jLabel3.setFont(new java.awt.Font("宋体", 1, 14));				        jLabel3.setText("请重新输入密码:");								        mima.addActionListener(new java.awt.event.ActionListener() {				            public void actionPerformed(java.awt.event.ActionEvent evt) {				                mimaActionPerformed(evt);				            }				        });								        jLabel4.setText("请输入任意长度的大小写字母组合!!!");								        lujing.setText("请选择路径!");								        jButton1.setFont(new java.awt.Font("宋体", 1, 12));				        jButton1.setText("选 择");				        jButton1.addActionListener(new java.awt.event.ActionListener() {				            public void actionPerformed(java.awt.event.ActionEvent evt) {				                jButton1ActionPerformed(evt);				            }				        });								        jButton2.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N				        jButton2.setText("确定加密");				        jButton2.addActionListener(new java.awt.event.ActionListener() {				            public void actionPerformed(java.awt.event.ActionEvent evt) {				                jButton2ActionPerformed(evt);				            }				        });								        jButton3.setFont(new java.awt.Font("宋体", 1, 14));				        jButton3.setText("返  回");				        jButton3.addActionListener(new java.awt.event.ActionListener() {				            public void actionPerformed(java.awt.event.ActionEvent evt) {				                jButton3ActionPerformed(evt);				            }				        });								        jButton4.setFont(new java.awt.Font("宋体", 1, 14));				        jButton4.setText("取  消");				        jButton4.addActionListener(new java.awt.event.ActionListener() {				            public void actionPerformed(java.awt.event.ActionEvent evt) {				                jButton4ActionPerformed(evt);				            }				        });								        mimats.setForeground(new java.awt.Color(255, 51, 51));								        mimacsti.setForeground(new java.awt.Color(255, 51, 51));								        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());				        getContentPane().setLayout(layout);				        layout.setHorizontalGroup(				            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)				            .addGroup(layout.createSequentialGroup()				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)				                    .addGroup(layout.createSequentialGroup()				                        .addGap(46, 46, 46)				                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)				                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()				                                .addComponent(lujing, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)				                                .addGap(18, 18, 18)				                                .addComponent(jButton1))				                            .addGroup(layout.createSequentialGroup()				                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)				                                    .addComponent(jLabel3)				                                    .addComponent(jLabel2))				                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)				                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)				                                    .addComponent(mima, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)				                                    .addComponent(chongshumima, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE))))				                        .addGap(6, 6, 6))				                    .addGroup(layout.createSequentialGroup()				                        .addGap(103, 103, 103)				                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)				                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)				                    .addComponent(mimacsti, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)				                    .addComponent(mimats, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))				                .addContainerGap())				            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)				                    .addGroup(layout.createSequentialGroup()				                        .addContainerGap()				                        .addComponent(jButton2)				                        .addGap(18, 18, 18)				                        .addComponent(jButton3)				                        .addGap(21, 21, 21)				                        .addComponent(jButton4))				                    .addGroup(layout.createSequentialGroup()				                        .addGap(90, 90, 90)				                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)))				                .addGap(23, 23, 23))				        );								        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton2, jButton3, jButton4});								        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {mimacsti, mimats});								        layout.setVerticalGroup(				            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)				            .addGroup(layout.createSequentialGroup()				                .addGap(27, 27, 27)				                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)				                .addComponent(jLabel4)				                .addGap(17, 17, 17)				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)				                    .addComponent(jLabel2)				                    .addComponent(mima, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)				                    .addComponent(mimats, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))				                .addGap(27, 27, 27)				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)				                    .addComponent(jLabel3)				                    .addComponent(chongshumima, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)				                    .addComponent(mimacsti, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))				                .addGap(27, 27, 27)				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)				                    .addComponent(lujing, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)				                    .addComponent(jButton1))				                .addGap(18, 18, 18)				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)				                    .addComponent(jButton2)				                    .addComponent(jButton4)				                    .addComponent(jButton3))				                .addContainerGap(27, Short.MAX_VALUE))				        );								        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton2, jButton3, jButton4});								        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {mimacsti, mimats});								        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();				        setBounds((screenSize.width-408)/2, (screenSize.height-334)/2, 408, 334);				    }// //GEN-END:initComponents								private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed				// TODO add your handling code here:				    主界面 ab = new 主界面();				    ab.setVisible(true);				}//GEN-LAST:event_formWindowClosed								private void mimaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mimaActionPerformed				// TODO add your handling code here:				}//GEN-LAST:event_mimaActionPerformed								private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed				// TODO add your handling code here:				    主界面 ac = new 主界面();				    ac.setVisible(true);				    this.setVisible(false);				}//GEN-LAST:event_jButton3ActionPerformed								private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed				// TODO add your handling code here:				    JFileChooser chooser = new JFileChooser();				    int state = chooser.showOpenDialog(null);				    File file = chooser.getSelectedFile();								}//GEN-LAST:event_jButton1ActionPerformed								private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed				// TODO add your handling code here:				    System.exit(this.HIDE_ON_CLOSE);				}//GEN-LAST:event_jButton4ActionPerformed								private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed				// TODO add your handling code here:				    String sm = mima.getText();				    String smcs = chongshumima.getText();				    int jim = sm.compareTo(smcs);				    int jim1 = sm.length();				    if (jim1 == 0) {				        JOptionPane.showMessageDialog(rootPane, "不能为空!", "输入错误!", this.HIDE_ON_CLOSE);				        mimats.setText("不能为空!");				        mimacsti.setText("不能为空!");				    } else {												        if (jim != 0) {				            final JFrame k = new JFrame("输入错误!");				            JOptionPane.showMessageDialog(rootPane, "两次密码不一样请重新输入!", "输入错误!", this.HIDE_ON_CLOSE);				            mima.setText("");				            chongshumima.setText("");				            mimats.setText("请重新输入!");				            mimacsti.setText("请重再次新输入!");				        } else {				            JOptionPane.showMessageDialog(rootPane, "密码符合要求", "输入正确!", this.HIDE_ON_CLOSE);				        }				}//GEN-LAST:event_jButton2ActionPerformed				    }								    /**				     * @param args the command line arguments				     */				    public static void main(String args[]) {				        java.awt.EventQueue.invokeLater(new Runnable() {								            public void run() {				                new 文件加密().setVisible(true);				            }				        });				    }								    // Variables declaration - do not modify//GEN-BEGIN:variables				    private javax.swing.JTextField chongshumima;				    private javax.swing.JButton jButton1;				    private javax.swing.JButton jButton2;				    private javax.swing.JButton jButton3;				    private javax.swing.JButton jButton4;				    private javax.swing.JLabel jLabel1;				    private javax.swing.JLabel jLabel2;				    private javax.swing.JLabel jLabel3;				    private javax.swing.JLabel jLabel4;				    private javax.swing.JLabel lujing;				    private javax.swing.JTextField mima;				    private javax.swing.JLabel mimacsti;				    private javax.swing.JLabel mimats;				    // End of variables declaration//GEN-END:variables				}							

相关资源