(高分求解)AWT中FileDialog表示位置的问题
FileDialog表示的时候直接表示在左上边了,如何定位FileDialog的初始表示位置。最好能够有个例子。
楼主看看我的试试: 一个文件分割程序 点 打开 可以有 FileDialog
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Fen{
String fileName;
int size;
public Fen(String fileName,String size){
this.fileName = fileName;
this.size = Integer.parseInt(size)*1024;
}
public void cut()throws Exception{
int maxx = 0;
File inFile = new File(fileName);
int fileLength = (int)inFile.length(); //取得文件的大小
int value; //取得要分割的个数
RandomAccessFile inn = new RandomAccessFile(inFile,"r");//打开要分割的文件
value = fileLength/size;
int i=0;
int j=0;
//根据要分割的数目输出文件
for (;j<value;j++){
File outFile = new File(inFile.getName()+j+"zzii");
RandomAccessFile outt= new RandomAccessFile(outFile,"rw");
maxx+=size;
for (;i<maxx;i++){
outt.write(inn.read());
}
outt.close();
}
File outFile = new File(inFile.getName()+j+"zzii");
RandomAccessFile outt= new RandomAccessFile(outFile,"rw");
for(;i<fileLength;i++){
outt.write(inn.read());
}
outt.close();
inn.close();
}
}
class He{
String fileName;
String filterName;
He(String fileName,String filterName){
this.fileName = fileName;
this.filterName = filterName;
}
public void unite()throws Exception{
String [] tt;
File inFile = new File("."); //在当前目录下的文件
File outFile = new File(fileName); //取得输出名
RandomAccessFile outt= new RandomAccessFile(outFile,"rw");
//取得符合条件的文件名
tt = inFile.list(new FilenameFilter(){
public boolean accept(File dir,String name){
String rr = new File(name).toString();
return rr.endsWith(filterName);
}
});
//打印出取得的文件名
for (int i = 0;i<tt.length;i++){
System.out.println(tt[i]);
}
//打开所有的文件再写入到一个文件里
for(int i=0;i<tt.length;i++){
inFile = new File(tt[i]);
RandomAccessFile inn= new RandomAccessFile(inFile,"r");
int c;
while((c=inn.read())!=-1)
outt.write(c);
}
outt.close();
}
}
public class fenge extends JFrame implements ActionListener
{
Fen cutt;
He hee;
int size;
String finalfilename;
String sameend;
File myfile;
JPanel jp1;
JPanel jp2;
JLabel jl1;
JTextField jt;
JButton btn_1 ;
JLabel jl2;
JTextField jt1;
JButton btn_2;
JLabel jl3;
JTextField jt2;
JLabel jl4;
JTextField jt3;
JButton btn_3;
fenge()
{
super("文件分割器");
setLayout(new GridLayout(2,1));
jp1=new JPanel(new FlowLayout());
jp2=new JPanel(new FlowLayout());
jl1=new JLabel("请选择要分割的文件");
jt=new JTextField(10);
btn_1=new JButton("打开");
jl2=new JLabel("请输入分割后每个文件大小(k)");
jt1=new JTextField(4);
btn_2=new JButton("开始分割");
jl3=new JLabel("请输入合并后的文件名:");
jt2=new JTextField(10);
jl4=new JLabel("请输入要合并文件的同样后缀名");
jt3=new JTextField(10);
btn_3=new JButton("开始合并");
jp1.add(jl1);
jp1.add(jt);
jp1.add(btn_1);
jp1.add(jl2);
jp1.add(jt1);
jp1.add(btn_2);
jp2.add(jl3);
jp2.add(jt2);
jp2.add(jl4);
jp2.add(jt3);
jp2.add(btn_3);
getContentPane().add(jp1);
getContentPane().add(jp2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,400);
setLocation(100,100);
btn_1.addActionListener(this);
btn_2.addActionListener(this);
btn_3.addActionListener(this);
show();
}
public static void main(final String [] args){
fenge fg=new fenge();
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="打开")
{
FileDialog fd=new FileDialog(this,"打开文件",FileDialog.LOAD);
fd.show();
jt.setText(fd.getFile());
myfile=new File(fd.getDirectory()+fd.getFile());
}
else if(e.getActionCommand()=="开始分割")
{
size=Integer.parseInt(jt1.getText());
cutt=new Fen(myfile.toString(),""+size);
try{
cutt.cut();
}catch(Exception ie){System.out.println(ie);}
}
else if(e.getActionCommand()=="开始合并")
{
finalfilename=jt2.getText();
sameend=jt3.getText();
try{
He hee = new He(finalfilename,sameend);
hee.unite();
}catch(Exception ie){System.out.println(ie);}
}
}
}