• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

我这代码错在哪

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.RandomAccessFile;


import javax.crypto.EncryptedPrivateKeyInfo;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
class Encrypter{
        public Encrypter(int code2, JFileChooser f, boolean selected) {
               
                // TODO Auto-generated constructor stub
        }


        public void encode() {
                // TODO Auto-generated method stub
               
        }
}






public class where extends JFrame {
        JLabel l1,l2;
        JFileChooser f;
        JTextField t;
        JButton b1,b2;
        JCheckBox c;
        JPanel p1,p2;
        int code;
        boolean rewrite;
        File sourceFile;
        FileInputStream fin;
        FileOutputStream fout;
        String sourceFileName;
        String obJFileName;
       
       
        where(){
        l1=new JLabel("选择加密文件");
        l2=new JLabel("选择加密/处理算子");
        t=new JTextField(10);
        b1=new JButton("确定");
        b2=new JButton("取消");
        c=new JCheckBox("覆盖文件");
        f=new JFileChooser();
        p1=new JPanel();
        p2=new JPanel();
        setLayout(new BorderLayout());
        add(p1,BorderLayout.CENTER);
        add(p2,BorderLayout.SOUTH);
       
        f.setControlButtonsAreShown(false);
        p1.setLayout(new FlowLayout(FlowLayout.LEFT));
        p1.add(l1);
        p1.add(f);
        p1.add(l2);
        p1.add(t);
        p1.add(c);
        p2.add(b1);
        p2.add(b2);
       
        this.setSize(700,500);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);//固定窗口
        this.setVisible(true);
        setEvent();
        }
private void setEvent() {
                // TODO Auto-generated method stub
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                b1.addActionListener(new ActionListener() {
                       
                        @Override
                        public void actionPerformed(ActionEvent arg0) {
                                // TODO Auto-generated method stub
                                File f1=f.getSelectedFile();
                                int code=Integer.parseInt(c.getText());
                                new Encrypter(code,f,c.isSelected()).encode();
                                final JDialog jb=new JDialog(where.this,"加密成功!");
                                jb.add(new JLabel("文件加密成功"),BorderLayout.NORTH );
                                JButton jbok;
                                jb.add(jbok=new JButton("确定"),BorderLayout.SOUTH);
                                jbok.addActionListener(new ActionListener() {
                                       
                                        @Override
                                        public void actionPerformed(ActionEvent arg0) {
                                                // TODO Auto-generated method stub
                                                jb.dispose();
                                        }
                                });
                                jb.setLocationRelativeTo(where.this);
                                jb.setSize(300,200);
                                jb.setVisible(true);
                        }
                });
                b2.addActionListener(new ActionListener() {
                       
                        @Override
                        public void actionPerformed(ActionEvent arg0) {
                                // TODO Auto-generated method stub
                                System.exit(0);
                        }
                });
               
        }
public void encode(){
       
        if(rewrite){
                RandomAccessFile fra=null;
                try{
                        fra=new RandomAccessFile(sourceFile, "rw");
                        int temp;
                        while((temp=fra.read())!=-1){
                                fra.seek(fra.getFilePointer()-1);
                                fra.write(temp^code);
                        }
                }catch(Exception e){
                        e.printStackTrace();
                }finally{
                        if(fra!=null)
                                try{
                                fra.close();
                                }catch(Exception e){
                                       
                                }       
                }
        }else{
                FileInputStream fis=null;
                FileOutputStream fos=null;
                try{
                        fis=new FileInputStream(sourceFile);
                        fos=new FileOutputStream(obJFileName);
                        while(fis.available()>0){
                                fos.write(fis.read()^code);
                        }
                        fos.flush();
                }catch(Exception e){
                        e.printStackTrace();
                }finally{
                        if(fis!=null)
                                try{
                                        fis.close();
                                }catch(Exception e){
                                       
                                }
                                if(fos!=null)
                                        try{
                                                fos.close();
                                        }catch(Exception e){
                                               
                                        }
                }
        }
}


public static void main(String[] args) {
        new where();


       
}


}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

把报的错一起贴上来吧,方便查看

使用道具 举报

发新帖

发布任务需求已有1031168位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!