在Dialog里可以设置对话框是打开,还是保存,我也是初学者,参数不记得,自己查查
解决方案 »
- 求救!!!!编译的出来框架不对?怎么改?好像展开空白地方也不对,怎么办?
- 请教大侠:用JBuilder 2005 生成javadoc 时,提示请增加内存,如何增加JBuilder中JVM的内存?如何在控制台生成javadoc?
- 有没有面试题(算法题(java或.net))
- 该方法为什么打不开windows的应用程序?(outlook程序)
- 想从java基础开始学的来看看
- 请问怎么有没有可能把java程序编译成本地机器代码?
- java的平台无关性是什么意思?
- 线程方面的小问题
- 我的jb怎么不能编译程序
- 关于线程的
- 一个关于3DES密钥的问题
- 关于jar打包的问题(把文件夹里的所有文件和一个.class文件打成一个jar包)?
图形介面出来后按select 铵钮就会弹出对话框
import javax.swing.*;
import java.io.File;
import javax.swing.plaf.metal.MetalLookAndFeel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.lang.String;public class filechoolse1{
public filechoolse1(){
}
public static void main(String[] args){
JFrame frame=new JFrame("main");
try{
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
SwingUtilities.updateComponentTreeUI(frame);
}
catch (Exception e){
System.out.print("error");
}
frame.setSize(300,200);
frame.setLocation(100,100); String[] aa={"chris","amy","f_fire","sarha"};
JComboBox bb=new JComboBox(aa);
JButton b=new JButton("select");
JButton sb=new JButton("combobox ");
frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,2,2));
frame.getContentPane().add(b);
frame.getContentPane().add(sb);
frame.getContentPane().add(bb);
frame.setVisible(true);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame f=new JFrame("choose file");
JFileChooser c=new JFileChooser();
c.setDialogTitle("choose file");
int a=c.showOpenDialog(f);
File file=c.getSelectedFile();
String sfilename=file.getName();
System.out.print(file.getPath());
} });
}
}
chooser.setCurrentDirectory(new File("C:\\")) ; //設置選擇器的默認目錄為C:int result=chooser.showOpenDialog(null) ;
或者用showSaveDialog()方法 ;