小型的课程设计

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

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

相关代码

				/*				 * 文件解密.java				 *				 * Created on 2008年12月5日, 下午6:16				 */								/**				 *				 * @author  Administrator				 */				import javax.swing.*;				import java.io.*;								public class 文件解密 extends javax.swing.JFrame {								    String wzlj;				    File file;								    /** 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();				        lujing = new javax.swing.JLabel();				        xuanze = new javax.swing.JButton();				        jLabel2 = new javax.swing.JLabel();				        mima = new javax.swing.JTextField();				        jiemi = new javax.swing.JButton();				        fanhui = new javax.swing.JButton();				        quxiao = new javax.swing.JButton();				        mimawen = new javax.swing.JLabel();				        tishi = new javax.swing.JLabel();				        jLabel4 = new javax.swing.JLabel();								        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);				        setTitle("\u6587\u4ef6\u89e3\u5bc6");				        addKeyListener(new java.awt.event.KeyAdapter() {				            public void keyPressed(java.awt.event.KeyEvent evt) {				                formKeyPressed(evt);				            }				        });								        jLabel1.setFont(new java.awt.Font("宋体", 1, 36));				        jLabel1.setText("\u6587\u4ef6\u89e3\u5bc6");								        lujing.setText("请选择路径!");								        xuanze.setFont(new java.awt.Font("宋体", 1, 12));				        xuanze.setText("\u9009 \u62e9");				        xuanze.addActionListener(new java.awt.event.ActionListener() {				            public void actionPerformed(java.awt.event.ActionEvent evt) {				                xuanzeActionPerformed(evt);				            }				        });								        jLabel2.setFont(new java.awt.Font("宋体", 1, 14));				        jLabel2.setText("\u8bf7\u8f93\u5165\u5bc6\u7801\uff1a");								        mima.addKeyListener(new java.awt.event.KeyAdapter() {				            public void keyPressed(java.awt.event.KeyEvent evt) {				                mimaKeyPressed(evt);				            }				        });								        jiemi.setFont(new java.awt.Font("宋体", 1, 14));				        jiemi.setText("\u6587\u4ef6\u89e3\u5bc6");				        jiemi.setActionCommand("\u786e\u5b9a\u89e3\u5bc6");				        jiemi.addActionListener(new java.awt.event.ActionListener() {				            public void actionPerformed(java.awt.event.ActionEvent evt) {				                jiemiActionPerformed(evt);				            }				        });								        fanhui.setFont(new java.awt.Font("宋体", 1, 14));				        fanhui.setText("\u8fd4  \u56de");				        fanhui.addActionListener(new java.awt.event.ActionListener() {				            public void actionPerformed(java.awt.event.ActionEvent evt) {				                fanhuiActionPerformed(evt);				            }				        });								        quxiao.setFont(new java.awt.Font("宋体", 1, 14));				        quxiao.setText("\u53d6  \u6d88");				        quxiao.addActionListener(new java.awt.event.ActionListener() {				            public void actionPerformed(java.awt.event.ActionEvent evt) {				                quxiaoActionPerformed(evt);				            }				        });								        mimawen.setForeground(new java.awt.Color(255, 51, 51));								        tishi.setText("\u8bf7\u8f93\u5165\u4efb\u610f\u957f\u5ea6\u7684\u5927\u5c0f\u5199\u5b57\u6bcd\u7ec4\u5408\uff01\uff01\uff01");								        jLabel4.setText("\u5173\u4e8e");				        jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {				            public void mouseClicked(java.awt.event.MouseEvent evt) {				                jLabel4MouseClicked(evt);				            }				        });								        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());				        getContentPane().setLayout(layout);				        layout.setHorizontalGroup(				            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)				            .addGroup(layout.createSequentialGroup()				                .addGap(29, 29, 29)				                .addComponent(lujing, javax.swing.GroupLayout.PREFERRED_SIZE, 394, javax.swing.GroupLayout.PREFERRED_SIZE)				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)				                .addComponent(xuanze)				                .addContainerGap(102, Short.MAX_VALUE))				            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()				                .addContainerGap(89, Short.MAX_VALUE)				                .addComponent(jLabel2)				                .addGap(26, 26, 26)				                .addComponent(mima, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)				                .addComponent(mimawen, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)				                .addGap(23, 23, 23))				            .addGroup(layout.createSequentialGroup()				                .addGap(44, 44, 44)				                .addComponent(jiemi)				                .addGap(81, 81, 81)				                .addComponent(fanhui)				                .addGap(92, 92, 92)				                .addComponent(quxiao)				                .addContainerGap(126, Short.MAX_VALUE))				            .addGroup(layout.createSequentialGroup()				                .addGap(190, 190, 190)				                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)				                .addContainerGap(221, Short.MAX_VALUE))				            .addGroup(layout.createSequentialGroup()				                .addGap(140, 140, 140)				                .addComponent(tishi)				                .addContainerGap(238, Short.MAX_VALUE))				            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()				                .addContainerGap(511, Short.MAX_VALUE)				                .addComponent(jLabel4)				                .addGap(59, 59, 59))				        );				        layout.setVerticalGroup(				            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)				            .addGroup(layout.createSequentialGroup()				                .addGap(23, 23, 23)				                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)				                .addGap(18, 18, 18)				                .addComponent(tishi)				                .addGap(36, 36, 36)				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)				                    .addComponent(jLabel2)				                    .addComponent(mima, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)				                    .addComponent(mimawen))				                .addGap(35, 35, 35)				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)				                    .addComponent(lujing, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)				                    .addComponent(xuanze))				                .addGap(27, 27, 27)				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)				                    .addComponent(jiemi)				                    .addComponent(quxiao)				                    .addComponent(fanhui))				                .addGap(26, 26, 26)				                .addComponent(jLabel4)				                .addGap(19, 19, 19))				        );								        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {mima, mimawen});								        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();				        setBounds((screenSize.width-602)/2, (screenSize.height-359)/2, 602, 359);				    }// //GEN-END:initComponents								private void xuanzeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_xuanzeActionPerformed				// TODO add your handling code here:				    JFileChooser chooser = new JFileChooser();//创建JFileChooser对象								    int state = chooser.showOpenDialog(null);//新建并打开选择文件对话框								    file = chooser.getSelectedFile();//获取被选的文件								    File lujings = chooser.getCurrentDirectory();//反回当前目录								    String filename = chooser.getName(file);//获取被选的文件								    wzlj = lujings + "\\" + filename;//完整的路径名(当前路径+"\"+文件名), "\\"为转义的"\"								    this.lujing.setText(wzlj);				}//GEN-LAST:event_xuanzeActionPerformed								private void fanhuiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fanhuiActionPerformed				// TODO add your handling code here:				    主界面 ac = new 主界面();//创建主页面对象								    ac.setVisible(true);//显示主页面								    this.setVisible(false);//隐藏本页面				}//GEN-LAST:event_fanhuiActionPerformed								private void quxiaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quxiaoActionPerformed				// TODO add your handling code here:				    System.exit(this.HIDE_ON_CLOSE);//关闭软件				}//GEN-LAST:event_quxiaoActionPerformed								private void jiemiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jiemiActionPerformed				// TODO add your handling code here:				    String mm = mima.getText();////mima是输入密码的文本框  获取输入密码的文本框的字符串								    int shuruchangdu = mm.length();//输入的密码长度								    if (shuruchangdu == 0) {//输入密码的文本框为空时								        JOptionPane.showMessageDialog(rootPane, "密码不能为空!", "输入错误!", this.HIDE_ON_CLOSE);				        mimawen.setText("不能为空!");				        tishi.setText("解密失败,再来一次!");				    } else {//输入密码的文本框不为空								        if (file == null) {//没选择文件								            JOptionPane.showMessageDialog(rootPane, "请选择路径!", "错误!", this.HIDE_ON_CLOSE);				        } else {//选择了文件								            lujingchuli lj = new lujingchuli();//创建路径处理的对象								            filein fi = new filein();//创建文件读取的对象								            String mubiaolujing = lj.jiemilujingchuli(wzlj);//处理路径得到密码文件的路径								            boolean fh = fi.cunchu(wzlj, mm, mubiaolujing); //进行判断密码是否正确,正确进行解密        								            if (fh == false) {//密码输入错误								                JOptionPane.showMessageDialog(rootPane, "输入密码错误!", "错误!", this.HIDE_ON_CLOSE);				                mima.setText("");				                mimawen.setText("密码错误!");				                tishi.setText("密码错误,再来一次!");				            } else {//密码输入正确								                mima.setText("");				                tishi.setText("解密成功,欢迎使用!");				                mimawen.setText("");				            }				        }				    }				}//GEN-LAST:event_jiemiActionPerformed								private void mimaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_mimaKeyPressed				// TODO add your handling code here:				    主界面 jb = new 主界面();//创建主页面对象								    int keycodemm = evt.getKeyCode();//获取当前按下键的键值				    //   System.out.println(keycodemima);								    if (keycodemm == 32 || (keycodemm > 40 && keycodemm < 64) || (keycodemm > 90 && keycodemm < 97) || keycodemm == 192) {  //限定只有字幕能键入								        JOptionPane.showMessageDialog(rootPane, "密码请输入大小写组合!", "输入错误!", this.HIDE_ON_CLOSE);				        mima.setText("");				        mimawen.setText("密码重新输入!");				    }				    if (keycodemm == 27) { //键值27为Esc健 点击退出上层菜单								        jb.setVisible(true);//显示主界面								        this.setVisible(false);//隐藏当前界面								    }				    if (keycodemm == 112) {//键值为112为F1时,打开关于界面								        关于 gg = new 关于();				        gg.setVisible(true);				    }				}//GEN-LAST:event_mimaKeyPressed								private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseClicked				// TODO add your handling code here:				    关于 gy = new 关于();				    gy.setVisible(true);				}//GEN-LAST:event_jLabel4MouseClicked								private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed				// TODO add your handling code here:				    //键值为112为F1时,打开关于界面				    主界面 za = new 主界面(); //键值27为Esc健 点击退出上层菜单								    int keycodemimaf = evt.getKeyCode();//获取当前按下键的键值								    if (keycodemimaf == 27) {  //键值27为Esc健 点击退出上层菜单								        za.setVisible(true);//显示主界面								        this.setVisible(false);//隐藏当前界面								    }				    if (keycodemimaf == 112) {//按F1打开关于								        关于 gg = new 关于();				        gg.setVisible(true);				    }								}//GEN-LAST:event_formKeyPressed								    /**				     * @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.JButton fanhui;				    private javax.swing.JLabel jLabel1;				    private javax.swing.JLabel jLabel2;				    private javax.swing.JLabel jLabel4;				    private javax.swing.JButton jiemi;				    private javax.swing.JLabel lujing;				    private javax.swing.JTextField mima;				    private javax.swing.JLabel mimawen;				    private javax.swing.JButton quxiao;				    private javax.swing.JLabel tishi;				    private javax.swing.JButton xuanze;				    // End of variables declaration//GEN-END:variables				}							

相关资源