import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.GraphicsEnvironment;
import javax.swing.*;
import java.util.*;
import java.awt.Graphics;
class MyTextPad extends Frame implements ActionListener
{
JTextArea text;
JScrollPane jsp;
PopupMenu popm;
Date date=new Date();
String str="";
Dialog d,About;
Choice c1,c2,c3;
Button btn1,btn2;
String Str1="宋体",Str2="普通",Str3="15";
int temp=0;
int Red=0,Green=0,Blue=0;
Label lFind = new Label("查找字符串:");
Label lReplace = new Label("替换字符串:");
TextField tFind = new TextField(10);
TextField tReplace = new TextField(10);
Button bFind = new Button("查找");
Button bReplace = new Button("替换");
Button bReplaceAll=new Button("替换所有");
Dialog dialog;
Dialog findD;
public MyTextPad(String str)
{
super(str);
text=new JTextArea();
text.setFont(new Font("宋体",0,15));
jsp=new JScrollPane(text);
add("Center",jsp);
findD=new Dialog(this);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
}
}
);
d=new Dialog(this,"字体选择");
d.setBounds(150,150,320,200);
findD.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
findD.setVisible(false);
}
}
);
d.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
d.setVisible(false);
}
}
);
c1=new Choice();c2=new Choice();c3=new Choice();
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
String fontName[]=ge.getAvailableFontFamilyNames();
for(int i=0;i<fontName.length;i++)
{
c1.add(fontName[i]);
}
c2.add("粗体");
c2.add("斜体");
c2.add("粗体与斜体");
c2.add("普通");
for(int i=8;i<100;i++)
{
c3.add(""+i);
}
Panel p1=new Panel();
Panel p2=new Panel();
p1.add(c1);
p1.add(c2);
p1.add(c3);
btn1=new Button("确定");
btn2=new Button("取消");
d.setLayout(new GridLayout(5,3));
d.add(p1);
p2.add(btn1);
btn1.addActionListener(this);
btn2.addActionListener(this);
p2.add(btn2);
d.add(p2);
About=new Dialog(this,"关于");
About.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
About.setVisible(false);
}
}
);
About.setBounds(300,300,150,150);
About.add(new Label("蒋俊涛的计事体1.0版本"));
Menu mn=new Menu("文件");
MenuItem miNewFile=new MenuItem("新建",new MenuShortcut(KeyEvent.VK_N));
MenuItem miOpenFile=new MenuItem("打开",new MenuShortcut(KeyEvent.VK_O));
MenuItem miSaveFile=new MenuItem("保存",new MenuShortcut(KeyEvent.VK_S));
MenuItem miExit=new MenuItem("退出",new MenuShortcut(KeyEvent.VK_E));
mn.add(miNewFile);
mn.add(miOpenFile);
mn.add(miSaveFile);
mn.addSeparator();
mn.add(miExit);
miNewFile.addActionListener(this);
miOpenFile.addActionListener(this);
miSaveFile.addActionListener(this);
miExit.addActionListener(this);
Menu mn1=new Menu("编辑");
MenuItem miSelectAll=new MenuItem("全选",new MenuShortcut(KeyEvent.VK_P));
MenuItem miClear=new MenuItem("清空",new MenuShortcut(KeyEvent.VK_S));
MenuItem miCopy=new MenuItem("复制",new MenuShortcut(KeyEvent.VK_C));
MenuItem miPaste=new MenuItem("粘贴",new MenuShortcut(KeyEvent.VK_V));
MenuItem miCut=new MenuItem("剪切",new MenuShortcut(KeyEvent.VK_T));
MenuItem miFind=new MenuItem("查找",new MenuShortcut(KeyEvent.VK_D));
MenuItem miReplace=new MenuItem("替换",new MenuShortcut(KeyEvent.VK_R));
MenuItem miAuto=new MenuItem("自动换行");
miAuto.addActionListener(this);
mn1.add(miSelectAll);
mn1.add(miClear);
mn1.add(miCopy);
mn1.add(miPaste);
mn1.add(miCut);
mn1.addSeparator();
mn1.add(miFind);
mn1.add(miReplace);
mn1.add(miAuto);
miSelectAll.addActionListener(this);
miClear.addActionListener(this);
miCopy.addActionListener(this);
miPaste.addActionListener(this);
miCut.addActionListener(this);
miFind.addActionListener(this);
miReplace.addActionListener(this);
Menu mn2=new Menu("格式");
MenuItem miFont=new MenuItem("字体",new MenuShortcut(KeyEvent.VK_F));
MenuItem miColor=new MenuItem("颜色选择",new MenuShortcut(KeyEvent.VK_K));
MenuItem miTime=new MenuItem("插入时间",new MenuShortcut(KeyEvent.VK_T));
miFont.addActionListener(this);
miColor.addActionListener(this);
miTime.addActionListener(this);
mn2.add(miFont);
mn2.add(miColor);
mn2.add(miTime);
Menu mn3=new Menu("帮助");
MenuItem miAbout=new MenuItem("关于",new MenuShortcut(KeyEvent.VK_A));
miAbout.addActionListener(this);
mn3.add(miAbout);
FileDialog findDlg = new FileDialog(this);
Panel p5=new Panel();
Panel p6=new Panel();
Panel p7=new Panel(); p7.setLayout(new GridLayout(1,2,30,30));
p5.add(lFind); p5.add(tFind); p5.add(bFind); tFind.addActionListener(this); bFind.addActionListener(this);
p6.add(lReplace); p6.add(tReplace); p7.add(bReplace); p7.add(bReplaceAll); p6.add(p7);
tReplace.addActionListener(this); bReplace.addActionListener(this);bReplaceAll.addActionListener(this);
findD.setLayout(new GridLayout(2,1,10,10));
findD.setResizable(false);
findD.add(p5);
findD.add(p6);
findD.setBounds(100,100,260,190);
//弹出PopupMenu
popm=new PopupMenu();
MenuItem OpenFile=new MenuItem("打开");
MenuItem SaveFile=new MenuItem("保存");
MenuItem SelectAll=new MenuItem("全选");
MenuItem Copy=new MenuItem("复制");
MenuItem Paste=new MenuItem("粘贴");
MenuItem Cut=new MenuItem("剪切");
OpenFile.addActionListener(this);
SaveFile.addActionListener(this);
SelectAll.addActionListener(this);
Copy.addActionListener(this);
Paste.addActionListener(this);
Cut.addActionListener(this);
popm.add(OpenFile);
popm.add(SaveFile);
popm.add(SelectAll);
popm.add(Copy);
popm.add(Paste);
popm.add(Cut);
text.add(popm);
text.addMouseListener(new MyMouseEvent(this));
MenuBar Bar=new MenuBar();
Bar.add(mn);
Bar.add(mn1);
Bar.add(mn2);
Bar.add(mn3);
setMenuBar(Bar);
setSize(800,600);
setVisible(true);
}
class MyMouseEvent extends MouseAdapter
{
MyTextPad myParentFrame;
MyMouseEvent(MyTextPad myf)
{
myParentFrame=myf;
}
public void mouseReleased(MouseEvent e)
{
if(e.isPopupTrigger())
myParentFrame.popm.show((Component)e.getSource(),e.getX(),e.getY());
}
}
public void actionPerformed(ActionEvent e)
{
String strCmd=e.getActionCommand()
java做的简单记事本
4星 · 超过85%的资源 需积分: 9 158 浏览量
2008-09-04
23:18:07
上传
评论 1
收藏 53KB RAR 举报
search001
- 粉丝: 8
- 资源: 12
最新资源
- Windows 常见运行运行库32+64
- 基于3KW光伏并网单相逆变器设计(TMS320F28035控制板+显示板+STM32F103功率板)硬件(原理图+PCB)工程
- 正点原子HAL库 STM32F4 外部中断(学习自用附源码)
- delphi rzcombobox DropDownList 灰色背景改为白色
- sap sd.docsap sd.doc
- torch-1.10.2-cp38-cp38-win-amd64.whl
- 菜单栏实现增加数据,修改数据,查询数据,删除数据
- 全国省市区三级联动json文件,带code
- C8_全局&局部&static.zip
- Unity和安卓交互插件Unity调Android Native Goodies PRO
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈