BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #13944同步于 2010/4/11
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

程序出错了,但不知道是怎么回事,求助!!!

whychina
2010/4/11镜像同步9 回复
程序出错了,但不知道是怎么回事!!! 我的程序有问题,但就是不知道哪儿出错了,还有后面的不会弄了,有没有人帮我搞搞!! 源程序: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication5; /** * * @author 王 */ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; import java.io.*; /** * * @author 静 */ public class Qiegeqi{ void Qiegeqi(){ frame fr=new frame(); fr.fram(); } /** * @param args the command line arguments */ public static void main(String[] args) { Qiegeqi Q=new Qiegeqi(); Q.Qiegeqi(); // TODO code application logic here } } class filedialog{ private JFileChooser open,close; public String filePath,fname,fp; void open(){ javax.swing.filechooser.FileNameExtensionFilter filter = new javax.swing.filechooser.FileNameExtensionFilter("Txt file", "txt", "TXT"); open=new JFileChooser(); open.setFileFilter(filter); int result=open.showOpenDialog(null); if(result==JFileChooser.APPROVE_OPTION){ filePath=open.getSelectedFile().getPath(); fname=open.getSelectedFile().getName(); } } void close(){ close=new JFileChooser(); close.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result=close.showOpenDialog(null); if(result==JFileChooser.APPROVE_OPTION){ fp=close.getSelectedFile().getPath(); } } } class frame{ private JFrame frame; private JMenuBar menubar; private JMenu wenjian,bianji,help; private JMenuItem dakai,baocun,exit,chexiao,copy,cut,paste,about,shuoming; void fram(){ frame=new JFrame("TXT切割器"); menubar=new JMenuBar(); wenjian=new JMenu("文件"); dakai=new JMenuItem("打开"); baocun=new JMenuItem("输出"); exit=new JMenuItem("退出"); exit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.exit(0); } }); wenjian.add(dakai); wenjian.add(baocun); wenjian.add(exit); bianji=new JMenu("编辑"); chexiao=new JMenuItem("撤销"); copy=new JMenuItem("复制"); cut=new JMenuItem("剪切"); paste=new JMenuItem("粘贴"); bianji.add(chexiao); bianji.add(copy); bianji.add(cut); bianji.add(paste); help=new JMenu("帮助"); about=new JMenuItem("关于"); shuoming=new JMenuItem("说明"); help.add(about); help.add(shuoming); menubar.add(wenjian); menubar.add(bianji); menubar.add(help); frame.setJMenuBar(menubar); frame.setContentPane(new panel().pane()); frame.addWindowListener(new WindowAdapter(){ @Override public void windowClosing(WindowEvent e) {System.exit(0); } }) ; frame.setSize(300,300); frame.setVisible(true); } } class panel implements ActionListener{ private JPanel panel,p1,p2,p3,p4,p5; public JTextField yuanwenjian,shuchuwenjian,daxiao,shuchuwenjianm; private JButton liulan,xuanze,qiege,quxiao,tuichu; public String ypath,fn,cpath; JPanel pane(){ panel=new JPanel(); panel.setLayout(new GridLayout(5,1)); p1=new JPanel(); p2=new JPanel(); p3=new JPanel(); p4=new JPanel(); p5=new JPanel(); p1.setLayout(new FlowLayout()); p1.add(new JLabel("源文件:")); yuanwenjian=new JTextField("请输入源文件的路径或点击浏览"); p1.add("North",yuanwenjian); liulan=new JButton("浏览"); liulan.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ filedialog op=new filedialog(); op.open(); ypath=op.filePath; yuanwenjian.setText(ypath); fn=op.fname; shuchuwenjianm.setText(fn); } }); p1.add("North",liulan); p2.setLayout(new FlowLayout()); p2.add(new JLabel("输出:")); shuchuwenjian=new JTextField("请输入输出路径或点击选择 "); p2.add(shuchuwenjian); xuanze=new JButton("选择"); xuanze.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ filedialog cl=new filedialog(); cl.close(); cpath=cl.fp; shuchuwenjian.setText(cpath); } }); p2.add(xuanze); p3.setLayout(new FlowLayout()); p3.add(new JLabel("切割设置:")); daxiao=new JTextField("10",10); p3.add(daxiao); p3.add(new JLabel("KB")); p4.setLayout(new FlowLayout()); p4.add(new JLabel("输出文件名:")); shuchuwenjianm=new JTextField(10); p4.add(shuchuwenjianm); p4.add(new JLabel("+序数")); p5.setLayout(new FlowLayout()); qiege=new JButton("切割"); qiege.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ try { file fil = new file(); fil.file(); } catch (IOException ex) { Logger.getLogger(panel.class.getName()).log(Level.SEVERE, null, ex); } } }); p5.add(qiege); quxiao=new JButton("取消"); quxiao.addActionListener(this); p5.add(quxiao); tuichu=new JButton("退出"); tuichu.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ System.exit(0); } }) ; p5.add(tuichu); panel.add(p1); panel.add(p2); panel.add(p3); panel.add(p4); panel.add(p5); return panel; } public void actionPerformed(ActionEvent e){ } } class file{ void file() throws IOException{ int i=Integer.parseInt(new panel().daxiao.getText()); File f=new File(new panel().yuanwenjian.getText()); File f2=new File(new panel().shuchuwenjian.getText()+new panel().shuchuwenjianm.getText()+i); try{ if(!f.exists()) { JOptionPane.showInputDialog(new String("请输入或选择正确的文件!")); }else{ try{ FileInputStream fi=new FileInputStream(f); int len=i*1024; byte[] b=new byte[len]; if(2*len>f.length()){ while(i!=-1){ byte[] b1=new byte[1]; fi.read(b1); fi.close(); File f3=new File(new panel().shuchuwenjian.getText()+new panel().shuchuwenjianm.getText()); OutputStream fos=new FileOutputStream(f3); fos.write(b1); fos.close(); } }else{ } }catch(IOException e){ JOptionPane.showInputDialog(e); } } }catch(Exception e){ } } }
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
ericyosho机器人#1 · 2010/4/11
我非常不了解,为什么构造函数,都要写成void呢?@@ void Qiegeqi() void file()
caomeiliang机器人#2 · 2010/4/12
回:1楼 构造函数你想返回啥呢? ps:程序太长,实在不想看。。。。 把错误代码贴出来吧
ericyosho机器人#3 · 2010/4/12
回二楼。 再敢说构造函数需要返回类型,就拖出去,弹xx弹到死…… 【 在 caomeiliang 的大作中提到: 】 : 回:1楼 : 构造函数你想返回啥呢? : ps:程序太长,实在不想看。。。。 : ...................
Adun机器人#4 · 2010/4/12
lz敢说说有啥错么...这么长的代码...
fly84021210机器人#5 · 2010/4/12
【 在 caomeiliang 的大作中提到: 】 : 回:1楼 : 构造函数你想返回啥呢? : ps:程序太长,实在不想看。。。。 : ................... 构造函数 不是不准有任何返回类型么 连void都不准 否则就变成普通函数了 没记错的话
mx201245机器人#6 · 2010/4/12
感觉就是从网上复制过来的源代码。。。
Adun机器人#7 · 2010/4/12
【 在 mx201245 的大作中提到: 】 : 感觉就是从网上复制过来的源代码。。。 re
wks机器人#8 · 2010/4/12
1. 构造函数不该有返回值 2. 命名方式很威武 3. 好象也没有问题。毕竟没有需求嘛。
Akesumu机器人#9 · 2010/4/21
谈经济谈党史 【 在 ericyosho 的大作中提到: 】 : 回二楼。 : 再敢说构造函数需要返回类型,就拖出去,弹xx弹到死…… : 【 在 caomeiliang 的大作中提到: 】 : ...................