Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java程序分享区 » 工具  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to topicflat modethreaded modego to previous topicgo to next topicgo to back
话题被移动
该话题已被移动 - tzutolin , 2005-12-13 14:06
如果您尚不清楚该话题被移动的原因,请参考论坛规则以及本版公告或者联系本版版主。
作者 我的第一个java小程序
xd2008





发贴: 18
于 2005-03-13 17:30 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.lang.*;
import java.io.*;

public class qgj implements WindowListener,MouseListener,ActionListener
{
Frame f;
Panel p;
Panel p1;
Panel p2;
Panel p3;
Panel p4;
Button b1;
Button b2;
Button b3;
Label l1;
Label l2;
Label l3;
Label l4;
TextField t1;
TextField t2;
TextField t3;
TextArea ta;
JFileChooser jfc1=new JFileChooser();
JFileChooser jfc2=new JFileChooser();
int oldsize=0;
int newsize=0;
int filenum=0;
byte[] c=new byte[1024];
int i,j,k;

public qgj()
{
f=new Frame("切割机1.0 作者:xd 2005.010.1");
p=new Panel();
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
b1=new Button("浏览");
b2=new Button("浏览");
b3=new Button("切割");
l1=new Label("被切割文件:");
l2=new Label("存储文件夹:");
l3=new Label("新文件大小:");
l4=new Label("KB");
t1=new TextField(25);
t2=new TextField(25);
t3=new TextField(22);
ta=new TextArea(10,50);
p1.add(l1);
p1.add(t1);
p1.add(b1);
p2.add(l2);
p2.add(t2);
p2.add(b2);
p3.add(l3);
p3.add(t3);
p3.add(l4);
p3.add(b3);
p4.add(ta);
p1.setBackground(Color.orange);
p2.setBackground(Color.yellow);
p3.setBackground(Color.green);
p4.setBackground(Color.blue);
b1.setBackground(Color.red);
b2.setBackground(Color.red);
b3.setBackground(Color.red);
p.setLayout(new GridLayout(3,1));
p.add(p1);
p.add(p2);
p.add(p3);
f.add(p,BorderLayout.NORTH);
f.add(p4,BorderLayout.SOUTH);
ta.setText("使用-浏览-输入要被切割的原文件\n");
ta.append("本程序对原文件没有任何的操作,请安心使用.\n");
ta.append("使用-浏览-输入用于存储的文件夹\n");
ta.append("请保证没有与原文件同名的文件.\n");
ta.append("在新文件大小后的文本框中输入新文件的大小\n");
ta.append("默认是切割成3个文件.\n");
ta.append("最后用-切割-开始切割.\n");
ta.append("合并时执行.bat文件即可!!\n\n");
ta.append("谢谢使用.有问题与xd20080@163.com联系!");
t1.addMouseListener(this);
t2.addMouseListener(this);
t3.addMouseListener(this);
b1.addMouseListener(this);
b2.addMouseListener(this);
b3.addMouseListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
f.addWindowListener(this);
f.pack();
f.show();
f.setResizable(false);
t1.setEditable(false);
t2.setEditable(false);
t3.setEditable(false);
b2.setEnabled(false);
b3.setEnabled(false);
ta.setEditable(false);

}
void getf()
{
jfc1.setFileSelectionMode(JFileChooser.FILES_ONLY);
jfc1.setDialogTitle("选择要切割的文件");
jfc1.setMultiSelectionEnabled(false);
int re1=jfc1.showOpenDialog(f);
if (re1!=JFileChooser.APPROVE_OPTION) return;
File sf=jfc1.getSelectedFile();
t1.setText(sf.getAbsolutePath());
String sep=sf.separator;
String temp=jfc1.getCurrentDirectory().getAbsolutePath().concat(sep);
t2.setText(temp);
oldsize=(int)(sf.length());
newsize=oldsize/2048;
filenum=oldsize/newsize+1;
t3.setText(String.valueOf(newsize));
b2.setEnabled(true);
b3.setEnabled(true);
t3.setEditable(true);
ta.setText(t2.getText());
}
void getd()
{
jfc2.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
jfc2.setDialogTitle("选择要用于保存的文件夹");
jfc2.setMultiSelectionEnabled(false);
int re2=jfc2.showSaveDialog(f);
if (re2!=JFileChooser.APPROVE_OPTION) return;
File sf2=jfc2.getSelectedFile();
t2.setText(sf2.getAbsolutePath().concat(sf2.separator));
ta.setText(t2.getText());
}
void start()
{
try{
ta.setText("正在处理中....请等待!");
String oldname=t1.getText();
String newdir=t2.getText();
newsize=Integer.parseInt((t3.getText()));
filenum=oldsize/newsize/1024+1;
if (newsize<1||newsize>oldsize/1024) {ta.setText("文件大小错误!");return;}
String name=jfc1.getSelectedFile().getName().replace('.','_').concat(".");
f.setEnabled(false);
FileInputStream fis=new FileInputStream(oldname);
FileWriter fw=new FileWriter(newdir.concat(name).concat("bat"));
fw.write("copy /b ");
for (i=1;i<=filenum;i++){
String newname=newdir.concat(name).concat(String.valueOf(i));
FileOutputStream fos=new FileOutputStream(newname);
fw.write(name.concat(String.valueOf(i)));
if (i!=filenum)
{
fw.write("+");
for (j=0;j<newsize;j++)
{fis.read(c);
fos.write(c);}
}
else
{
fw.write(" ".concat(jfc1.getSelectedFile().getName()));
while((k=fis.read())!=-1) fos.write(k);
}
fos.close();
}
fw.close();
fis.close();
f.setEnabled(true);
ta.setText("切割完成!");
}
catch(Exception e){ta.setText(e.toString());f.setEnabled(true);}
}
public void actionPerformed(ActionEvent e)
{
Button src=(Button)e.getSource();
if (src==b1) getf();
if (src==b2) getd();
if (src==b3) start();
}
public void windowClosing(WindowEvent e){System.exit(0);}
public void windowActivated(WindowEvent e){f.repaint();}
public void windowDeactivated(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){f.repaint();}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e)
{
if (e.getSource()==b1) getf(); else
if (e.getSource()==b2) getd(); else
if (e.getSource()==b3) start();
}

public static void main(String args[])
{qgj q=new qgj();}
}

qgj.jar (4.27k)


xd2008 edited on 2005-03-17 15:30

作者 Re:我的第一个java小程序 [Re:xd2008]
xd2008





发贴: 18
于 2005-03-13 17:34 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
重发的代码 !

qgj.java (5.22k)



作者 Re:我的第一个java小程序 [Re:xd2008]
雪中行





发贴: 23
于 2005-03-15 10:40 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
编译通不过呀
160多行有三个错误 , 都是not a statement
fis.read;
^
fos.write;
^
while((k=fis.read())!=-1)fos.write;
^
请问楼主为什么?



作者 Re:我的第一个java小程序 [Re:雪中行]
tzutolin



版主


发贴: 581
于 2005-03-15 11:39 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
雪中行 wrote:
编译通不过呀
160多行有三个错误 , 都是not a statement
fis.read;
^
fos.write;
^
while((k=fis.read())!=-1)fos.write;
^
请问楼主为什么?

read, write 後面要加括弧.



作者 Re:我的第一个java小程序 [Re:tzutolin]
xd2008





发贴: 18
于 2005-03-17 15:22 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
编译后的CLASS

qgj.class (7.22k)



作者 Re:我的第一个java小程序 [Re:tzutolin]
xd2008





发贴: 18
于 2005-03-17 15:27 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我用的是J2SDK1.4.2
我的编译结果是正确的



作者 Re:我的第一个java小程序 [Re:xd2008]
xd2008





发贴: 18
于 2005-03-17 15:34 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可能是你复制的代码出错拉

read write后原来有括号的



作者 Re:我的第一个java小程序 [Re:xd2008]
achosun





发贴: 3
于 2005-04-01 13:10 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不错,在我netbeans3.6里没问题


作者 Re:我的第一个java小程序 [Re:xd2008]
Waynewen





发贴: 7
于 2005-04-22 13:33 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不错,鼓励鼓励!
不过我的经验觉得,最好将ActionListener都分开,那么你就不用使用IF—STATEMENT了,而且如果BUTTON或者其他加EVENT的COMPONENTS多了就很容易出错了。
e.g.
b1.addActionListener(new b1_actionListener())
...
...
class b1_actionListener() implements ActionListener{
public void actionPerformed(ActionEvent event))
{
.........
}}



作者 Re:我的第一个java小程序 [Re:Waynewen]
xd2008





发贴: 18
于 2005-05-07 13:58 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
十分感谢各位兄弟的帮助,小弟感激不尽!
小弟正在改进,
有个小问题请教:
用到File.createNewFile()时出现IOException
不知道是哪里出错了
新建的文件确实不存在,
且用这个方法新建一个文件夹的时候出来的是一个无扩展名的文件
请各位兄弟帮帮小弟!



作者 Re:我的第一个java小程序 [Re:xd2008]
mesocool





发贴: 53
于 2005-05-10 11:05 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
xd2008 wrote:
十分感谢各位兄弟的帮助,小弟感激不尽!
小弟正在改进,
有个小问题请教:
用到File.createNewFile()时出现IOException
不知道是哪里出错了
新建的文件确实不存在,
且用这个方法新建一个文件夹的时候出来的是一个无扩展名的文件
请各位兄弟帮帮小弟!


把它放到try catch里



新Java群:6526029
作者 我的JAVA切割机2.0 [Re:xd2008]
xd2008





发贴: 18
于 2005-05-10 20:19 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的程序之改进版

JavaApplication2.jar (31.32k)



作者 改进的代码 [Re:xd2008]
xd2008





发贴: 18
于 2005-05-10 20:23 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list


cut.java (26.19k)




reply to topicflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923