记事本Java源程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
return chooser.getSelectedFile();
}
return null;
}
});
jmiNew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JColorChooser;
return f.isDirectory()
|| filename.endsWith(".txt")
|| filename.endsWith(".cpp")
|| filename.endsWith(".c")
|| filename.endsWith(".java");
return "文本文件";
}
@Override
public boolean accept(File f) { // 判断文件是否被选择在chooser.showOpenDialog()里
String filename = f.getName().toLowerCase();
}
Байду номын сангаас });
int chooserVar = chooser.showOpenDialog(new JFrame());
if (chooserVar == JFileChooser.APPROVE_OPTION) {
System.out.println("You can choose this file");
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
}
br.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
public class Notepad extends JFrame {
/**
*
*/
}
private void openChooseFile() {
File file = chooseFile();
if (file == null)
;
else {
FileReader fr;
try {
fr = new FileReader(file);
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
// 要显示在chooser.showOpenDialog()里的文件
@Override
public String getDescription() { // 获取描述
// TODO Auto-generated method stub
// 要显示在chooser.showOpenDialog()里的文件
@Override
public String getDescription() { // 获取描述
// TODO Auto-generated method stub
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
if(TextArea1.getText().length()==0){
new Notepad();
}
}
});
jmisave.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
import java.awt.FlowLayout;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
/*
* 主菜单初始化
*/
jmb = new JMenuBar();
fileMenu = new JMenu("文件");
editMenu = new JMenu("编辑");
helpMenu = new JMenu("帮助");
fileMenu.setMnemonic('f'); // 设置热键
/*
* 下拉式菜单初始化
*/
jmiNew = new JMenuItem("新建");
jmiOpen = new JMenuItem("打开");
jmiAbout = new JMenuItem("关于");
jmiexit = new JMenuItem("退出");
}
});
int chooserVar = chooser.showSaveDialog(new JFrame());
private static final long serialVersionUID = 1L;
JMenuBar jmb;
JMenu fileMenu, editMenu, helpMenu; // 主菜单
JMenuItem jmiNew, jmiOpen, jmiexit, jmisave; // fileMenu 下拉式菜单
jmisave = new JMenuItem("保存");
copy = new JMenuItem("复制");
selectAll = new JMenuItem("全选");
paste = new JMenuItem("粘贴");
cut = new JMenuItem("剪切");
JMenuItem jmiAbout; // helpMenu 下拉式菜单
JMenuItem selectAll, copy, paste, cut, cancel; // editMenu 下拉式菜单
JTextArea TextArea1;
public Notepad() {
super("记事本");
//记事本程序Java实现
/*******************************************************/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FileDialog;
BufferedReader br = new BufferedReader(fr);
String string = null;
while ((string = br.readLine()) != null) {
TextArea1.append(string + "\n");
helpMenu.setMnemonic('h');
/*
* 主菜单绑定到JFrame
*/
jmb.add(fileMenu);
jmb.add(editMenu);
jmb.add(helpMenu);
this.setJMenuBar(jmb); // 将菜单栏添加到窗口上
System.out.println("You press it");
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new FileFilter() { // 通过FileFilter选择
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
}
}
}
private File chooseFile() {
System.out.println("You press it");
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new FileFilter() { // 通过FileFilter选择
return "文本文件";
}
@Override
public boolean accept(File f) { // 判断文件是否被选择在chooser.showOpenDialog()里
String filename = f.getName().toLowerCase();
return f.isDirectory()
|| filename.endsWith(".txt")
|| filename.endsWith(".cpp")
|| filename.endsWith(".c")
|| filename.endsWith(".java");
/*
*
* 动作监听器的实现
*/
jmiOpen.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openChooseFile();
}
return null;
}
});
jmiNew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JColorChooser;
return f.isDirectory()
|| filename.endsWith(".txt")
|| filename.endsWith(".cpp")
|| filename.endsWith(".c")
|| filename.endsWith(".java");
return "文本文件";
}
@Override
public boolean accept(File f) { // 判断文件是否被选择在chooser.showOpenDialog()里
String filename = f.getName().toLowerCase();
}
Байду номын сангаас });
int chooserVar = chooser.showOpenDialog(new JFrame());
if (chooserVar == JFileChooser.APPROVE_OPTION) {
System.out.println("You can choose this file");
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
}
br.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
public class Notepad extends JFrame {
/**
*
*/
}
private void openChooseFile() {
File file = chooseFile();
if (file == null)
;
else {
FileReader fr;
try {
fr = new FileReader(file);
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
// 要显示在chooser.showOpenDialog()里的文件
@Override
public String getDescription() { // 获取描述
// TODO Auto-generated method stub
// 要显示在chooser.showOpenDialog()里的文件
@Override
public String getDescription() { // 获取描述
// TODO Auto-generated method stub
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
if(TextArea1.getText().length()==0){
new Notepad();
}
}
});
jmisave.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
import java.awt.FlowLayout;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
/*
* 主菜单初始化
*/
jmb = new JMenuBar();
fileMenu = new JMenu("文件");
editMenu = new JMenu("编辑");
helpMenu = new JMenu("帮助");
fileMenu.setMnemonic('f'); // 设置热键
/*
* 下拉式菜单初始化
*/
jmiNew = new JMenuItem("新建");
jmiOpen = new JMenuItem("打开");
jmiAbout = new JMenuItem("关于");
jmiexit = new JMenuItem("退出");
}
});
int chooserVar = chooser.showSaveDialog(new JFrame());
private static final long serialVersionUID = 1L;
JMenuBar jmb;
JMenu fileMenu, editMenu, helpMenu; // 主菜单
JMenuItem jmiNew, jmiOpen, jmiexit, jmisave; // fileMenu 下拉式菜单
jmisave = new JMenuItem("保存");
copy = new JMenuItem("复制");
selectAll = new JMenuItem("全选");
paste = new JMenuItem("粘贴");
cut = new JMenuItem("剪切");
JMenuItem jmiAbout; // helpMenu 下拉式菜单
JMenuItem selectAll, copy, paste, cut, cancel; // editMenu 下拉式菜单
JTextArea TextArea1;
public Notepad() {
super("记事本");
//记事本程序Java实现
/*******************************************************/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FileDialog;
BufferedReader br = new BufferedReader(fr);
String string = null;
while ((string = br.readLine()) != null) {
TextArea1.append(string + "\n");
helpMenu.setMnemonic('h');
/*
* 主菜单绑定到JFrame
*/
jmb.add(fileMenu);
jmb.add(editMenu);
jmb.add(helpMenu);
this.setJMenuBar(jmb); // 将菜单栏添加到窗口上
System.out.println("You press it");
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new FileFilter() { // 通过FileFilter选择
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
}
}
}
private File chooseFile() {
System.out.println("You press it");
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new FileFilter() { // 通过FileFilter选择
return "文本文件";
}
@Override
public boolean accept(File f) { // 判断文件是否被选择在chooser.showOpenDialog()里
String filename = f.getName().toLowerCase();
return f.isDirectory()
|| filename.endsWith(".txt")
|| filename.endsWith(".cpp")
|| filename.endsWith(".c")
|| filename.endsWith(".java");
/*
*
* 动作监听器的实现
*/
jmiOpen.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openChooseFile();