import java.awt.*;
import javax.swing.text.*;
import java.util.TimerTask;
import java.awt.color.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Timer;
import java.io.*;
import java.io.IOException;
import java.util.StringTokenizer;
import javax.swing.event.*;
import javax.swing.text.rtf.RTFEditorKit;
public class MyJC extends JFrame implements ActionListener,MouseListener//,ItemListener
{
/* 声明类中所需的成员变量*/
private JFrame frame;
private JFrame frame1,frame2;
private JPanel panel3,panel4;
private JButton button1,button2,button3,button4;
private JLabel label1,label2,label3,label4;
private JTextField tf_code1,tf_code2,tf_string1,tf_string2;
private JPanel panel;
private JSplitPane jsp;
private JScrollPane panel1,panel2;
private JTextPane edit_space;
private JTextPane compile_message;
private JPopupMenu popupmenu;
protected StyleContext m_context;
protected DefaultStyledDocument m_doc;
private MutableAttributeSet keyattr,normalattr;
private MutableAttributeSet inputattributes =
new RTFEditorKit().getInputAttributes();
private String keyword[]={"abstract","boolean","break","byte","case","catch","char","class","continue",
"default","do","double","else","extends","false","final","finally","float","for","if","implements","import","instanceof","int","interface","long","native","new","null","package","private","protected",
"public","return","short","static","super","switch","synchronized","this","throw","throws","transient","true","try","void","while"};
//构造方法
public MyJC()
{
frame=new JFrame ("MyJC");
frame.setSize(800,600);
frame.setLocation(100,140);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
Container con=frame.getContentPane();
panel=new JPanel(new GridLayout(1,1));
edit_space=new JTextPane();
compile_message=new JTextPane();
edit_space.setEditable(false);
panel1=new JScrollPane(edit_space);
panel1.setPreferredSize(new Dimension(300,400));
panel2=new JScrollPane(compile_message);
panel.add(panel1);
jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,panel1,panel2);
panel.add(jsp);
//为编辑面板添加响应事件监听器
// edit_space.addKeyListener(this);
edit_space.addMouseListener(this);
compile_message=new JTextPane();
con.add(panel);
m_context = new StyleContext();
m_doc = new DefaultStyledDocument(m_context);
edit_space.setDocument(m_doc);
edit_space.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent ke) {
syntaxparse();
}
});
file://定义关键字显示属性
keyattr = new SimpleAttributeSet();
StyleConstants.setForeground(keyattr, Color.red);
file://定义一般文本显示属性
normalattr = new SimpleAttributeSet();
StyleConstants.setForeground(normalattr, Color.black);
//为框架添加工具栏及菜单
this.addMenu();
frame.setVisible(true);
/************************************
当单击替换字符或字符串按钮弹出框架所需的组件的创建
*************************************/
frame1=new JFrame("Change_Code");
frame2=new JFrame("Change_String");
label1=new JLabel("Input the code ");
frame1.setSize(300,160);
frame2.setSize(300,160);
frame1.setLocation(200,200);
frame2.setLocation(200,200);
frame1.setLayout(new GridLayout(5,1));
frame2.setLayout(new GridLayout(5,1));
panel3=new JPanel();
panel4=new JPanel();
button1=new JButton("确定");
button2=new JButton("取消");
button3=new JButton("确定");
button4=new JButton("取消");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
panel3.add(button1);
panel3.add(button2);
panel4.add(button3);
panel4.add(button4);
label2=new JLabel("Input the string ");
label3=new JLabel("Instead Code:");
label4=new JLabel("Instead String:");
tf_code2=new JTextField(30);
tf_string2=new JTextField(30);
tf_code1=new JTextField(30);
tf_string1=new JTextField(30);
frame1.add(label1);
frame1.add(tf_code1);
frame1.add(label3);
frame1.add(tf_code2);
frame1.add(panel3);
frame2.add(label2);
frame2.add(tf_string1);
frame2.add(label4);
frame2.add(tf_string2);
frame2.add(panel4);
frame1.setVisible(false);
frame2.setVisible(false);
frame1.setDefaultCloseOperation(frame1.HIDE_ON_CLOSE);
frame2.setDefaultCloseOperation(frame2.HIDE_ON_CLOSE);
/*内部类,重写TimerTask的run()方法,实现文件的定时备份*/
class TTask extends TimerTask
{
public void run()
{
File file;
file=new File("E:\\Copy.java");
try
{
FileOutputStream fout=new FileOutputStream("E:\\Copy.java");
byte buff[]=new byte[1000];
String line;
line=edit_space.getText();
buff=line.getBytes();
fout.write(buff);
fout.close();
}
catch(IOException e1)
{
}
}
}
Timer timer=new Timer();
timer.schedule(new TTask(),10,1000);
}
//为创建的框架添加菜单
private void addMenu()
{
JMenuBar menubar=new JMenuBar();
frame.setJMenuBar(menubar);
//添加文件菜单及其的各个菜单项
JMenu menu_file=new JMenu("File");
menubar.add(menu_file);
JMenuItem menuitem_new =new JMenuItem("New");
menu_file.add(menuitem_new);
menu_file.addSeparator();
JMenuItem menuitem_open=new JMenuItem("Open");
menu_file.add(menuitem_open);
menu_file.addSeparator();
JMenuItem menuitem_close=new JMenuItem("Close");
menu_file.add(menuitem_close);
menu_file.addSeparator();
JMenuItem menuitem_save=new JMenuItem("Save");
menu_file.add(menuitem_save);
menu_file.addSeparator();
JMenuItem menuitem_saveas=new JMenuItem("SaveAs");
menu_file.add(menuitem_saveas);
menu_file.addSeparator();
JMenuItem menuitem_exit=new JMenuItem("Exit");
menu_file.add(menuitem_exit);
//各个菜单项添加单击事件监听器
menuitem_new.addActionListener(this);
menuitem_open.addActionListener(this);
menuitem_close.addActionListener(this);
menuitem_save.addActionListener(this);
menuitem_saveas.addActionListener(this);
menuitem_exit.addActionListener(this);
//添加编辑菜单及其菜单项并添加单击事件监听器
JMenu menu_edit=new JMenu("Edit");
menubar.add(menu_edit);
JMenu menu_style=new JMenu("Style");
JCheckBoxMenuItem checkbox_bold=new JCheckBoxMenuItem("Bold");
menu_style.add(checkbox_bold);
menu_style.addSeparator();
JCheckBoxMenuItem checkbox_italic=new JCheckBoxMenuItem("Italic");
menu_style.add(checkbox_italic);
menu_edit.add(menu_style);
menu_edit.addSeparator();
JMenu menu_color=new JMenu("Color");
menu_edit.add(menu_color);
menu_edit.addSeparator();
ButtonGroup buttongroup=new ButtonGroup();
JRadioButtonMenuItem rb_red=new JRadioButtonMenuItem("Red",true);
buttongroup.add(rb_red);
menu_color.add(rb_red);
JRadioButtonMenuItem rb_green=new JRadioButtonMenuItem("Green",true);
buttongroup.add(rb_green);
menu_color.add(rb_green);
JRadioButtonMenuItem rb_yellow=new JRadioButtonMenuItem("Yellow",true);
buttongroup.add(rb_yellow);
menu_color.add(rb_yellow);
JMenuItem item_selectall=new JMenuItem("SelectAll");
menu_edit.add(item_selectall);
item_selectall.addActionListener(this);
JMenuItem item_copy2=new JMenuItem("E:\\Copy");
menu_edit.addSeparator();
JMenuItem item_cut1=new JMenuItem("CUT");
JMenuItem item_copy1=new JMenuItem("COPY");
JMenuItem item_paste1=new JMenuItem("PASTE"
简单的java源程序编辑器 java课程设计
4星 · 超过85%的资源 需积分: 9 14 浏览量
2008-12-04
17:06:28
上传
评论
收藏 5KB RAR 举报
zhfengyu
- 粉丝: 5
- 资源: 1
最新资源
- 前端开发-什么是前端开发-关于前端开发的一些相关介绍
- Sora AI-关于文生视频的使用场景说明
- suno AI文生视频的相关教程和介绍使用
- 什么是后端开发-关于后端开发的一些小介绍分享
- Jurassic Pack Vol. II Dinosaurs 侏罗纪包卷恐龙二号Unity游戏模型资源unitypackage
- Jurassic Pack Vol. III Dinosaurs 侏罗纪包卷恐龙三号Unity游戏模型资源unitypackag
- Ultimate Seating Controller 终极座椅控制器Unity游戏开发插件资源unitypackage
- 什么是人工智能-关于人工智能的相关介绍说明
- Figma Converter for Unity适用Unity的Figma转换器Unity游戏开发插件unitypackage
- Creepy Animatronic Anims 令人毛骨悚然的电子动画Unity游戏动画插件资源unitypackage
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈