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

📄 testfiledialog.java

📁 有大量的java的实例
💻 JAVA
字号:
import java.io.*;
import java.awt.*;
import java.awt.event.*;

public class TestFileDialog
{
 public static void main(String args[])
 {
   new FileFrame();
 }
}
class FileFrame extends Frame implements ActionListener
{
  TextArea ta;
  Button open,quit;
  FileDialog fd;

  FileFrame()
  {
	super("获取并显示文本文件");
	ta = new TextArea(10,45);
	open = new Button("打开");
	quit = new Button("关闭");
	open.addActionListener(this);
	quit.addActionListener(this);
	setLayout(new FlowLayout());
	add(ta);
	add(open);
	add(quit);
	setSize(350,280);
	show();
  }
  public void actionPerformed(ActionEvent e)
  {
	if(e.getActionCommand()=="打开")
	{
          fd = new FileDialog(this,"",FileDialog.LOAD);
          fd.setDirectory("d:\\temp");//设置文件对话框的基础目录
          fd.show();//弹出并显示文件对话框,程序暂停直至用户选定一文件
	  try{
		File myfile = new File(fd.getDirectory(),fd.getFile());
		RandomAccessFile raf = new RandomAccessFile(myfile,"r");
		while(raf.getFilePointer()<raf.length())
		{
	          ta.append(raf.readLine()+"\n");
		}
	  }
	  catch(IOException ioe)
	  {
		System.err.println(ioe.toString());
	  }
       }
       if(e.getActionCommand()=="关闭")
       {
		dispose();
		System.exit(0);
       }
 }
}

⌨️ 快捷键说明

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