展开全部
package com.java.MyNotepad;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.java.find.FindString;
public class MyNotepad {
private JFrame f;
public static JTextArea ta;
private JMenuBar mb;
private JMenu fileMenu, edit, FColor, help;
private JMenuItem mOpenFile, mSave, mExit, mFind, fRed, fGreen, fBlack,
fGray, fBlue, mAbout;
private String[] fontTypeStr = { "宋体", "华文行楷", "隶书e69da5e6ba9062616964757a686964616f31333332613637", "华文彩云", "华文新魏",
"华文琥珀", "幼圆", "楷书" };
private String fontStyleStr[] = { "常规", "倾斜", "粗体", "倾斜+粗体" };
private String fontSizeStr[] = { "13", "15", "20", "30", "40", "50", "60",
"70", "80", "100", "120", "150", "200", "300", "400", "500", "700",
"1000", "1500", "2000", "4000" };
private JComboBox fontt = new JComboBox(fontTypeStr);
private JComboBox fontStyle = new JComboBox(fontStyleStr);
private JComboBox fontSize = new JComboBox(fontSizeStr);
// 文件对话框
private JFileChooser Chooser;
private File file;
private int flag;
private BufferedReader br;
private BufferedWriter bw;
private FileNameExtensionFilter filter;
private int fileNum = 1;
private FindString fs;
public void initialized() {
f = new JFrame("MyNotepad");
// 多行文本框
ta = new JTextArea();
ta.addKeyListener(new Process());
// 滚动条
JScrollPane jsp = new JScrollPane(ta);
// 元素
fontt.addItemListener(new Process());
fontStyle.addItemListener(new Process());
fontSize.addItemListener(new Process());
mOpenFile = new JMenuItem("Open");
mOpenFile.addActionListener(new Process());
mSave = new JMenuItem("Save to...");
mSave.addActionListener(new Process());
mExit = new JMenuItem("Exit");
mExit.addActionListener(new Process());
mFind = new JMenuItem("Find");
mFind.addActionListener(new Process());
fRed = new JMenuItem("Red");
fRed.addActionListener(new Process());
fGreen = new JMenuItem("Green");
fGreen.addActionListener(new Process());
fBlack = new JMenuItem("Black");
fBlack.addActionListener(new Process());
fGray = new JMenuItem("Gray");
fGray.addActionListener(new Process());
fBlue = new JMenuItem("Blue");
fBlue.addActionListener(new Process());
mAbout = new JMenuItem("About");
mAbout.addActionListener(new Process());
// 菜单列表元素
fileMenu = new JMenu("File");
edit = new JMenu("Edit");
FColor = new JMenu("Font Color");
help = new JMenu("Help");
// 菜单
mb = new JMenuBar();
// 添加组件
fileMenu.add(mOpenFile);
fileMenu.add(mSave);
fileMenu.add(mExit);
fileMenu.setForeground(Color.WHITE);
edit.add(mFind);
edit.setForeground(Color.WHITE);
help.add(mAbout);
help.setForeground(Color.WHITE);
FColor.add(fRed);
FColor.add(fGreen);
FColor.add(fBlack);
FColor.add(fGray);
FColor.add(fBlue);
FColor.setForeground(Color.WHITE);
mb.add(fileMenu);
mb.add(edit);
mb.add(FColor);
mb.add(help);
mb.add(fontt);
mb.add(fontStyle);
mb.add(fontSize);
mb.setBackground(Color.gray);
ta.setBackground(Color.LIGHT_GRAY);
ta.setForeground(Color.black);
f.add(mb, BorderLayout.NORTH);
f.add(jsp, BorderLayout.CENTER);
f.setLocation(400, 200);
f.setSize(800, 450);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
这是写记事本中的界面代码,功能代码没有贴上来,要不你看着感觉复杂了。。。如果要源码可以留邮箱,运行这段代码直接写个main函数实例化一个该类对象,调用initialized方法