为了账号安全,请及时绑定邮箱和手机立即绑定

我这代码错在哪

我这代码错在哪

慕粉1312236355 2017-04-03 18:45:43
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 回答

?
呦呦米

TA贡献90条经验 获得超59个赞

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

查看完整回答
反对 回复 2017-05-09
  • 1 回答
  • 0 关注
  • 1197 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信