⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplefilechooser.java

📁 本项目是用JAVA3D开发的一款图形界面的3D漫游的类似引擎.至所以这么说.是因为它的部分功能还不完全.说它是引擎是因为它可以完全脱离模型文件.本引擎实现了虚拟漫游,碰撞检测,动态添加模型,以及部分纹
💻 JAVA
字号:
package test;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class SimpleFileChooser extends JFrame {

	File f ;
public SimpleFileChooser() {
 super("File Chooser Test Frame");
 setSize(350, 200);
 setDefaultCloseOperation(EXIT_ON_CLOSE);

 Container c = getContentPane();
 c.setLayout(new FlowLayout());
 JButton openButton = new JButton("Open");
 JButton saveButton = new JButton("Save");
 JButton dirButton = new JButton("Pick Dir");
 final JLabel statusbar = 
              new JLabel("Output of your selection will go here");

 // Create a file chooser that opens up as an Open dialog
 openButton.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent ae) {
     JFileChooser chooser = new JFileChooser();
     chooser.setMultiSelectionEnabled(true);
     int option = chooser.showOpenDialog(SimpleFileChooser.this);
     if (option == JFileChooser.APPROVE_OPTION) {
       File[] sf = chooser.getSelectedFiles();
       String filelist = "nothing";
       if (sf.length > 0) filelist = sf[0].getName();
       for (int i = 1; i < sf.length; i++) {
         filelist += ", " + sf[i].getName();     }
       statusbar.setText("You chose " + filelist);
     }
     else {
       statusbar.setText("You canceled.");
     }
   }
 });

 // Create a file chooser that opens up as a Save dialog
 saveButton.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent ae) {
     JFileChooser chooser = new JFileChooser();
     int option = chooser.showSaveDialog(SimpleFileChooser.this);
     if (option == JFileChooser.APPROVE_OPTION) {
       statusbar.setText("You saved " + ((chooser.getSelectedFile()!=null)?
                         chooser.getSelectedFile().getName():"nothing"));
     }
     else {
       statusbar.setText("You canceled.");
     }
   }
 });

 // Create a file chooser that allows you to pick a directory
 // rather than a file
 dirButton.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent ae) {
     JFileChooser chooser = new JFileChooser();
if(f != null)
chooser.setCurrentDirectory(f);

     chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     int option = chooser.showOpenDialog(SimpleFileChooser.this);
     if (option == JFileChooser.APPROVE_OPTION) {
f = chooser.getSelectedFile();
       statusbar.setText("You opened " + ((chooser.getSelectedFile()!=null)?
                         chooser.getSelectedFile().getName():"nothing"));
     }
     else {
       statusbar.setText("You canceled.");
     }
   }
 });

 c.add(openButton);
 c.add(saveButton);
 c.add(dirButton);
 c.add(statusbar);
}

public static void main(String args[]) {
 SimpleFileChooser sfc = new SimpleFileChooser();
 sfc.setVisible(true);
}
}  
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -