java有没有openfiledialog,savefiledialog等对话框? 在Dialog里可以设置对话框是打开,还是保存,我也是初学者,参数不记得,自己查查 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果你是要图形介面地选择一个文件打开或保存,就用JFileChooser这个类,很好用,以下给出选择一个文件的例子,真接把其存为 filechoolse1.java 文件再编译就可以了!图形介面出来后按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()); } }); } } JFileChooser chooser=new JFileChooser() ;chooser.setCurrentDirectory(new File("C:\\")) ; //設置選擇器的默認目錄為C:int result=chooser.showOpenDialog(null) ;或者用showSaveDialog()方法 ; 输入数据流不完整 用Tree能和数据库连接并在JTable中显示所需的信息吗 java 数据库 有关深度拷贝的小问题! 导包的区别??? Which methods guarantee that a thread will leave the running state 求助 java udp socket的数据包长度问题 怎样划分同时带有图像和文字的jLabel标签…………!! 求救:编程实现dos下dir功能 如何捕捉页面事件用于产生新线程?急!!! 一个关于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()方法 ;