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

📄 filldialogtest.java

📁 这是java的源代码,感觉上是挺不错的哦,要下载赶快来哦,有附加数据库的哦
💻 JAVA
字号:
package ptu;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class FillDialogTest extends Frame {

	FileDialog fileDialog1;

	Button saveButton, openButton;

	String path,readString,readByLine;

	public FillDialogTest() {
		this.setTitle("文件对话框测试");
		this.setSize(100, 100);
		this.setLayout(new FlowLayout());
		saveButton = new Button("保存");
		openButton = new Button("打开");
		fileDialog1 = new FileDialog(this);
		fileDialog1.setModal(true);
		this.add(saveButton);
		this.add(openButton);
		saveButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// TODO 自动生成方法存根
				fileDialog1.setMode(FileDialog.SAVE);
				fileDialog1.setDirectory("d:\\java");
				
				fileDialog1.show();
				
				if (fileDialog1.getDirectory() == null
						|| fileDialog1.getFile() == null) {

				} else {
					path=fileDialog1.getDirectory()+fileDialog1.getFile();
					try {
						FileOutputStream outPut=new FileOutputStream(path);
						OutputStreamWriter outWrite=new OutputStreamWriter(outPut);
						outWrite.write("ptminshan");
						outWrite.close();
						outPut.close();
					} catch (FileNotFoundException e) {
						// TODO 自动生成 catch 块
						e.printStackTrace();
					} catch (IOException e) {
						// TODO 自动生成 catch 块
						e.printStackTrace();
					}
					
				}
			}

		});

		openButton.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent arg0) {
				// TODO 自动生成方法存根
				fileDialog1.setMode(FileDialog.LOAD);
				fileDialog1.show();
				if(fileDialog1.getDirectory()==null || fileDialog1.getFile()==null)
				{
					
				}else{
					path=fileDialog1.getDirectory()+fileDialog1.getFile();
					try {
						readString="";
						FileReader fileReader=new FileReader(path);
						BufferedReader bufReader=new BufferedReader(fileReader);
						readByLine=bufReader.readLine();
						while(readByLine!=null)
						{
							readString=readString+readByLine;
							readByLine=bufReader.readLine();
						}
						System.out.println(readString);
					} catch (FileNotFoundException e) {
						// TODO 自动生成 catch 块
						e.printStackTrace();
					} catch (IOException e) {
						// TODO 自动生成 catch 块
						e.printStackTrace();
					}
				}
			}
			
		});
	}
	public static void main(String[] args)
	{
		FillDialogTest fillTest1=new FillDialogTest();
		fillTest1.addWindowListener(new WindowAdapter(){

			public void windowClosing(WindowEvent arg0) {
				// TODO 自动生成方法存根
				System.exit(0);
			}

		});
		fillTest1.show();
	}
}

⌨️ 快捷键说明

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