大家来解释一下

Albertzmh 2010-10-31 08:40:26
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.text.BoxView;
public class CopyFileDemo extends JFrame{

JFileChooser fileChooser;
JTextField txtSource;
JTextField textDest;
JButton btnSelectA;
JButton btnSelectB;
JButton btncopy;
public CopyFileDemo(){
super("Java cpyfile");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fileChooser=new JFileChooser();
txtSource=new JTextField(16);
textDest=new JTextField(16);
btnSelectA=new JButton("选择");
btnSelectB=new JButton("选择");
btncopy=new JButton("复制");
Box box=Box.createVerticalBox();
JPanel panel=new JPanel();
panel.add(new JLabel("源文件"));
panel.add(txtSource);panel.add(btnSelectA);
box.add(panel);
panel=new JPanel();
panel.add(new JLabel("目标文件"));
panel.add(textDest);panel.add(btnSelectB);
box.add(panel);
box.add(btncopy);
getContentPane().add("Center",box);



}//
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==btncopy)
{
String sourceFile=txtSource.getText();
String targetFile=textDest.getText();
if(copyFile(sourceFile, targetFile))
{
JOptionPane.showMessageDialog(CopyFileDemo.this, "Succeed!");

}
else {
JOptionPane.showMessageDialog(CopyFileDemo.this, "Failure!");
}
}
else {
if(fileChooser.showOpenDialog(CopyFileDemo.this)==JFileChooser.APPROVE_OPTION)
{
String fileName=fileChooser.getSelectedFile().getAbsolutePath();
if(event.getSource().equals(btnSelectA))
txtSource.setText(fileName);
else
textDest.setText(fileName);
}
}
}
}////
public boolean copyFile(String file1,String file2)
{
try {
File fileIn=new File(file1);
File fileOut=new File(file2);
FileInputStream fInputStream=new FileInputStream(fileIn);
FileOutputStream fOutputStream=new FileOutputStream(fileOut);
byte[] bytes=new byte[1024];
int c;
while ((c=fInputStream.read(bytes))!=-1) {
fOutputStream.write(bytes,0,c);

}
fInputStream.close();
fOutputStream.close();
return true;
} catch (Exception e) {
// TODO: handle exception
return false;
}
}
public static void main(String args[])
{
CopyFileDemo obj=new CopyFileDemo();
}


}
这个java 为什么 会出现
...全文
71 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Albertzmh 2010-11-05
  • 打赏
  • 举报
回复
setvisible()后确实可见,也确实没效果
Albertzmh 2010-11-05
  • 打赏
  • 举报
回复
我把运行界面图片传到相册去了,大家看看
dr_lou 2010-11-01
  • 打赏
  • 举报
回复
obj.setVisible(true);

加了这句,看到了界面,但是选择按钮没效果。
dr_lou 2010-11-01
  • 打赏
  • 举报
回复
运行了一下,什么也没出现。界面也没
dr_lou 2010-11-01
  • 打赏
  • 举报
回复
请把图片贴到相册了
llbupt 2010-11-01
  • 打赏
  • 举报
回复
图片出错了
yxn1216 2010-11-01
  • 打赏
  • 举报
回复
无图无真相!
gularess 2010-10-31
  • 打赏
  • 举报
回复
出现什么?

50,545

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧