导航:首页 > 源码编译 > 用java写一个简易文本编译器

用java写一个简易文本编译器

发布时间:2022-03-05 15:17:41

‘壹’ 用java编写一个图形应用程序,可以是一个简单的文本编辑器、计算器等等。 求完整代码

//网络文库找的,可费了我的财富值了,你可要把分给我呀。
package lee;
/*文件名:Calculator.java

*说明:简易科学计算器
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Calculator extends Frame implements ActionListener, WindowListener
{
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JTextField displayField; //计算结果显示区
private String lastCommand; //保存+,-,*,/,=命令0
private double result; //保存计算结果
private boolean start; //判断是否为数字的开始
private JMenuBar menubar;
private JMenuItem m_exit,m2_ejz,m2_bjz;
private Dialog dialog;
private Label label_dialog;
private JButton button_sqrt,button_plusminus,button_CE,button_cancel,button_1,button_2,
button_3,button_4,button_5,button_6,button_7,button_8,button_9,button_0,
button_plus,button_minus,button_multiply,button_divide,button_point,
button_equal,button_log,button_tan,button_cos,button_sin,button_exp;

public Calculator() //构造方法设置布局、为按钮注册事件监听器
{
super("Calculator");
this.setLocation(240,200);
this.setSize(350,300);
this.setResizable(true);
this.setLayout(new GridLayout(7,1));
this.addmyMenu(); //调用成员方法添加菜单
displayField=new JTextField(30);
this.add(displayField);
displayField.setEditable(true);

start=true;
result=0;
lastCommand = "=";

JPanel panel0=new JPanel();
panel0.setLayout(new GridLayout(1,4,4,4));

JPanel panel1=new JPanel();
panel1.setLayout(new GridLayout(1,5,4,4));
this.add(panel1);
button_sqrt=new JButton("sqrt");
button_plusminus=new JButton("+/-");
button_exp=new JButton("exp");
button_CE=new JButton("退格");
button_cancel=new JButton("C");

JPanel panel2=new JPanel();
panel2.setLayout(new GridLayout(1,5,4,4));
this.add(panel2);
button_7=new JButton("7");
button_8=new JButton("8");
button_9=new JButton("9");
button_log=new JButton("log");
button_divide=new JButton("/");

JPanel panel3=new JPanel();
panel3.setLayout(new GridLayout(1,5,4,4));
this.add(panel3);
button_4=new JButton("4");
button_5=new JButton("5");
button_6=new JButton("6");
button_tan=new JButton("tan");
button_multiply=new JButton("*");

JPanel panel4=new JPanel();
panel4.setLayout(new GridLayout(1,5,4,4));
this.add(panel4);
button_1=new JButton("1");
button_2=new JButton("2");
button_3=new JButton("3");
button_cos=new JButton("cos");
button_minus=new JButton("-");

JPanel panel5=new JPanel();
panel5.setLayout(new GridLayout(1,5,4,4));
this.add(panel5);
button_0=new JButton("0");
button_point=new JButton(".");
button_equal=new JButton("=");
button_sin=new JButton("sin");
button_plus=new JButton("+");

panel1.add(button_sqrt);
panel1.add(button_plusminus);
panel1.add(button_exp);
panel1.add(button_CE);
panel1.add(button_cancel);
panel2.add(button_7);
panel2.add(button_8);
panel2.add(button_9);
panel2.add(button_log);
panel2.add(button_divide);
panel3.add(button_4);
panel3.add(button_5);
panel3.add(button_6);
panel3.add(button_tan);
panel3.add(button_multiply);
panel4.add(button_1);
panel4.add(button_2);
panel4.add(button_3);
panel4.add(button_cos);
panel4.add(button_minus);
panel5.add(button_0);
panel5.add(button_point);
panel5.add(button_equal);
panel5.add(button_sin);
panel5.add(button_plus);

button_sqrt.addActionListener(this);
button_plusminus.addActionListener(this);
button_exp.addActionListener(this);
button_CE.addActionListener(this);
button_cancel.addActionListener(this);
button_7.addActionListener(this);
button_8.addActionListener(this);
button_9.addActionListener(this);
button_log.addActionListener(this);
button_divide.addActionListener(this);
button_4.addActionListener(this);
button_5.addActionListener(this);
button_6.addActionListener(this);
button_tan.addActionListener(this);
button_multiply.addActionListener(this);
button_1.addActionListener(this);
button_2.addActionListener(this);
button_3.addActionListener(this);
button_cos.addActionListener(this);
button_minus.addActionListener(this);
button_0.addActionListener(this);
button_point.addActionListener(this);
button_equal.addActionListener(this);
button_sin.addActionListener(this);
button_plus.addActionListener(this);

this.addWindowListener(new WinClose()); //注册窗口监听器
this.setVisible(true);
}

private void addmyMenu() //菜单的添加
{
JMenuBar menubar=new JMenuBar();
this.add(menubar);
JMenu m1=new JMenu("选项");
JMenu m2=new JMenu("进制转换");
JMenuItem m1_exit=new JMenuItem("退出");
m1_exit.addActionListener(this);
JMenuItem m2_ejz=new JMenuItem("二进制");
m2_ejz.addActionListener(this);
JMenuItem m2_bjz=new JMenuItem("八进制");
m2_bjz.addActionListener(this);
JMenu m3 = new JMenu(" 帮助");
JMenuItem m3_Help = new JMenuItem("用法");
m3_Help.addActionListener(this);

dialog = new Dialog(this,"提示",true); //模式窗口
dialog.setSize(240,80);
label_dialog = new Label("",Label.CENTER); //标签的字符串为空,居中对齐
dialog.add(label_dialog);
dialog.addWindowListener(this); //为对话框注册窗口事件监听器

m1.add(m1_exit);
menubar.add(m1);
m2.add(m2_ejz);
m2.add(m2_bjz);
menubar.add(m2);
m3.add(m3_Help);
menubar.add(m3); }

public void actionPerformed(ActionEvent e) //按钮的单击事件处理方法
{
if(e.getSource().equals(button_1)||e.getSource().equals(button_2)||
e.getSource().equals(button_3)||e.getSource().equals(button_4)||
e.getSource().equals(button_5)|| e.getSource().equals(button_6)||
e.getSource().equals(button_7)|| e.getSource().equals(button_8)||
e.getSource().equals(button_9) ||e.getSource().equals(button_0)||
e.getSource().equals(button_point)||e.getSource().equals(button_plusminus)||
e.getSource().equals(button_cancel)||e.getSource().equals(button_CE))
{ //非运算符的处理方法
String input=e.getActionCommand();

if (start)
{
displayField.setText("");
start=false;
if(input.equals("+/-"))
displayField.setText(displayField.getText()+"-");
}
if(!input.equals("+/-"))
{
String str=displayField.getText();
if(input.equals("退格")) //退格键的实现方法
{
if(str.length()>0)
displayField.setText(str.substring(0,str.length()-1));
}
else if(input.equals("C")) //清零键的实现方法
{
displayField.setText("0");
start=true;
}
else
displayField.setText(displayField.getText()+input);
}
}
else if (e.getActionCommand()=="二进制") //二进制的转换
{
int n=Integer.parseInt(displayField.getText());
displayField.setText(Integer.toBinaryString(n));
}
else if (e.getActionCommand()=="八进制") //八进制的转换
{
int n=Integer.parseInt(displayField.getText());
displayField.setText(Integer.toOctalString(n));
}
else if (e.getActionCommand()=="退出") //选项中退出的处理方法
{
System.exit(0);
}
else if (e.getActionCommand()=="用法") //按下'帮助'菜单栏中用法的处理方法
{
label_dialog.setText("sqrt,exp等键是先输运算符再输数字\n");
dialog.setLocation(400,250);
dialog.setVisible(true);
}
else //各运算符的识别
{
String command=e.getActionCommand();
if(start)
{
lastCommand=command;
}
else
{
calculate(Double.parseDouble(displayField.getText()));
lastCommand=command;
start=true;
}
}
}

public void calculate(double x) //各运算符的具体运算方法
{
double d=0;
if (lastCommand.equals("+"))
result+= x;
else if (lastCommand.equals("-"))
result-=x;
else if (lastCommand.equals("*"))
result*=x;
else if (lastCommand.equals("/"))
result/=x;
else if (lastCommand.equals("="))
result=x;
else if (lastCommand.equals("sqrt"))
{
d=Math.sqrt(x);
result=d;
}
else if (lastCommand.equals("exp"))
{
d=Math.exp(x);
result=d;
}
else if (lastCommand.equals("log"))
{
d=Math.log(x);
result=d;
}
else if (lastCommand.equals("tan"))
{
d=Math.tan(x);
result=d;
}
else if (lastCommand.equals("cos"))
{
d=Math.cos(x);
result=d;
}
else if (lastCommand.equals("sin"))
{
d=Math.sin(x);
result=d;
}
displayField.setText(""+ result);
}

public void windowClosing(WindowEvent e)
{
if(e.getSource()==dialog)
dialog.setVisible(false); //隐藏对话框
else
System.exit(0);
}

public void windowOpened(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }

public static void main(String args[])
{
Calculator calculator=new Calculator();
}
}

class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e) //单击窗口关闭按钮时触发并执行实现窗口监听器接口中的方法
{
System.exit(0); //结束程序运行
}
public void windowOpened(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
}

‘贰’ 能编译运行java的简单文本编辑器 求代码

package Notepad;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
@SuppressWarnings("serial")
public class Notepad extends JFrame
{
private JTextArea editor;
private Container c;
private Font f=new Font("sanserif",Font.PLAIN,12);
//菜单栏成员属性声明
private JMenuBar mb; //菜单棒
private JMenu Menu; //文件菜单
private JMenuItem New,Open,Save,Close; //文件菜单的菜单项
//工具栏成员属性声明
private JToolBar toolBar; //工具棒
private JButton New1,Open1,Save1,About; //声明4个按钮,分别为:“新建”、“打开”、“保存”、“关于”

//弹出式菜单属性声明
private JPopupMenu pm;
private JMenuItem item1,item2,item3,item4;

public Notepad()
{
super("文本编辑器");
setSize(800,600);
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e){ System.err.println("不能被设置外观的原因:"+e);}

c=getContentPane(); //创建一个内容面板
editor = new JTextArea(); //创建一个文本区
c.add(new JScrollPane(editor)); //设置滚动条,并添加到内容面板
//菜单栏的实现
//文件菜单的实现
mb = new JMenuBar(); //创建菜单棒
Menu = new JMenu("菜单(M)");//创建菜单
New = new JMenuItem("新建(N)...Ctrl+N");
Open = new JMenuItem("打开(O)...Ctrl+O");
Save = new JMenuItem("保存(S)...Ctrl+S");
Close = new JMenuItem("退出");
JMHandler JM=new JMHandler(); //创建监听器
New.addActionListener(JM);//注册监听器
Open.addActionListener(JM);
Save.addActionListener(JM);
Close.addActionListener(JM);
Menu.add(New);
Menu.add(Open);
Menu.add(Save);
Menu.addSeparator(); //添加分隔线
Menu.add(Close);
Menu.setFont(f); //设置菜单中文体的字体

//将菜单全部添加菜单棒里
mb.add(Menu);

//工具栏的实现
//按钮分别为:“新建”、“打开”、“保存”、“关于”
toolBar =new JToolBar(); //创建工具棒
New1= new JButton(new ImageIcon("img/New.png"));
Open1= new JButton(new ImageIcon("img/Open.png"));
Save1= new JButton(new ImageIcon("img/Save.png"));
About= new JButton(new ImageIcon("img/About.png"));
TBHandler TB=new TBHandler(); //创建按钮监听器
New1.addActionListener(TB); Open1.addActionListener(TB);
Save1.addActionListener(TB); About.addActionListener(TB);
//把按钮全部添加到工具棒中
toolBar.add(New1); toolBar.add(Open1);
toolBar.add(Save1); toolBar.add(About);

//弹出菜单的实现
pm =new JPopupMenu(); //创建弹出菜单
item1 = new JMenuItem("新建");
item2 = new JMenuItem("打开");
item3 = new JMenuItem("保存");
item4 = new JMenuItem("关于");
JPHandler JP=new JPHandler();
item1.addActionListener(JP); //注册菜单项的鼠标事件监听器
item2.addActionListener(JP);
item3.addActionListener(JP);
item4.addActionListener(JP);
editor.addMouseListener(JP); //注册文本区的鼠标事件监听器
pm.add(item1); pm.add(item2);
pm.add(item3); pm.add(item4);

//把菜单栏、工具栏、弹出菜单添加到内容面板
setJMenuBar(mb); //显示菜单栏
c.add(toolBar,BorderLayout.NORTH);

setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//自定义类实现文件菜单项的事件处理
private class JMHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==New){ creatFile(); }
else if(e.getSource()==Open){ loadFile(); }
else if(e.getSource()==Save){ saveFile(); }
else{System.exit(0);}
}
}
private void creatFile() {//新建文件方法
editor.setText(null);
}
public void loadFile() //打开文件方法
{
JFileChooser fc=new JFileChooser();
int r=fc.showOpenDialog(this);
if(r==JFileChooser.APPROVE_OPTION)
{
File file=fc.getSelectedFile();
try{ editor.read(new FileReader(file),null);}
catch(IOException e){}
}
}

public void saveFile() //保存文件的方法
{
JFileChooser fc=new JFileChooser();
int r=fc.showSaveDialog(this);
if(r==JFileChooser.APPROVE_OPTION)
{
File file=fc.getSelectedFile();
try{ editor.write(new FileWriter(file));}
catch(IOException e){}
}
}

//自定义实现查找事件处理
//自定义类实现工具栏的按钮事件处理
private class TBHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==New1){ creatFile(); } //实现打开文件功能
else if(e.getSource()==Open1) {loadFile();}
else if(e.getSource()==Save1) {saveFile();} //实现保存文件功能
else {
editor.();
editor.requestFocus();
}
}
}

//自定义类实现弹出式菜单的事件处理
private class JPHandler implements ActionListener,MouseListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==item1){ creatFile(); } //实现创建文件功能
else if(e.getSource()==item2){ loadFile(); } //实现打开文件功能
else if(e.getSource()==item3) {saveFile();} //实现保存文件功能
else if(e.getSource()==item4) //关于文件
{
}
}
public void mouseReleased(MouseEvent e)
{
if(e.isPopupTrigger()) //判断是否按下鼠标右键
pm.show(editor,e.getX(),e.getY()); //显示弹出式菜单
}

public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e){}
}

public static void main(String []args)
{
Notepad N=new Notepad();
}

}

‘叁’ 能编译运行java的简单文本编辑器

import java.awt.BorderLayout;

public class WordProcessSystem extends JFrame{
private JFileChooser chooser;
private JTextArea textArea;
private File file;
private String string = "";
private Font font;

public WordProcessSystem(){
super();
setTitle("文字处理系统");
setBounds(100, 100,600, 500);
getContentPane().setLayout(new BorderLayout());
getContentPane().setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("文件");

JMenuItem menuItem = new JMenuItem("新建");
menuItem.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String str1 = JOptionPane.showInputDialog("请输入新建文件名:");
try {
file = new File("E:\\", str1 + ".txt");
if(file.exists()){
JOptionPane.showMessageDialog(null, "文件名已存在!");
}
else{
file.createNewFile();
}
} catch (Exception e1) {
// TODO: handle exception
}
}
});

chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
JMenuItem menuItem1 = new JMenuItem("打开");
menuItem1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int result = chooser.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION){
String str = chooser.getSelectedFile().toString();
try {
file = new File(str);
readFromFile(file);
textArea.setText(string);
} catch (Exception e1) {
// TODO: handle exception
}
}
}
});
JMenuItem menuItem2 = new JMenuItem("退出");
menuItem2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
JMenuItem menuItem3 = new JMenuItem("保存");
menuItem3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String string = textArea.getText();
try {
writeToFile(file, string);
} catch (Exception e1) {
// TODO: handle exception
}
}
});
menuItem3.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
if(e.getKeyChar() == KeyEvent.VK_C){
// if(e.getKeyChar() == KeyEvent.VK_S){
String string = textArea.getText();
try {
writeToFile(file, string);
} catch (Exception e1) {
// TODO: handle exception
}
// }
}
}
});
JMenuItem menuItem4 = new JMenuItem("另存为");
menuItem4.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s1 = JOptionPane.showInputDialog("请输入保存文件路径和文件名:");
file = new File(s1);
System.out.println(file.getPath());
try {
writeToFile(file, string);
System.out.println("aaaa");
} catch (Exception e1) {
// TODO: handle exception
}
}

});

menu.add(menuItem);
menu.add(menuItem1);
menu.add(menuItem2);
menu.add(menuItem3);
menu.add(menuItem4);

JMenu menu2 = new JMenu("格式");
final JMenu menu3 = new JMenu("字体");
String []fontString = {"宋体","楷体","隶书"};
final JMenuItem []menu3_1 = new JMenuItem[fontString.length];
for(int i = 0;i < fontString.length;i++){
String changeString = "";
menu3_1[i] = new JMenuItem(fontString[i]);
menu3_1[i].setActionCommand(changeString + i);
menu3_1[i].addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method
switch (e.getActionCommand().charAt(0)) {
case '0':
font = new Font("宋体",Font.PLAIN,20);
textArea.setFont(font);
break;
case '1':
font = new Font("楷体",Font.PLAIN,18);
textArea.setFont(font);
break;
case '2':
font = new Font("隶书",Font.BOLD,18);
textArea.setFont(font);
break;
default:
break;
}
}});
menu3.add(menu3_1[i]);
}

JMenu menu4 = new JMenu("字号");
String []fontBig = {"10","15","20","25","30","35","40"};
final JMenuItem []menu4_1 = new JMenuItem[fontBig.length];
for(int i = 0;i < fontBig.length;i++){
String changeString = "";
menu4_1[i] = new JMenuItem(fontBig[i]);
menu4_1[i].setActionCommand(changeString + i);
menu4_1[i].addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method
switch (e.getActionCommand().charAt(0)) {
case '0':
font = new Font(menu3.getText(),Font.PLAIN,10);
textArea.setFont(font);
break;
case '1':
font = new Font(menu3.getText(),Font.PLAIN,15);
textArea.setFont(font);
break;
case '2':
font = new Font(menu3.getText(),Font.PLAIN,20);
textArea.setFont(font);
break;
case '3':
font = new Font(menu3.getText(),Font.PLAIN,25);
textArea.setFont(font);
break;
case '4':
font = new Font(menu3.getText(),Font.PLAIN,30);
textArea.setFont(font);
break;
case '5':
font = new Font(menu3.getText(),Font.PLAIN,35);
textArea.setFont(font);
break;
case '6':
font = new Font(menu3.getText(),Font.PLAIN,40);
textArea.setFont(font);
break;
default:
break;
}
}});
menu4.add(menu4_1[i]);
}

menu2.add(menu3);
menu2.add(menu4);

menuBar.add(menu);
menuBar.add(menu2);
setJMenuBar(menuBar);
textArea = new JTextArea();
textArea.setVisible(true);
// textArea.setFont(new Font("宋体",Font.BOLD,20));
add(textArea);

JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setSize(600, 410);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
add(scrollPane);
}

public void readFromFile(File f) throws IOException{
FileReader fReader = new FileReader(file);
BufferedReader bReader = new BufferedReader(fReader);
char []data = new char[10000];
int length = 0;
while((length = fReader.read(data)) > 0){
string += new String(data,0,length);
}
// string = new String("");
// while(true){

// String s1 = bReader.readLine();

// if(s1 == null){
// break;
// }
// string += (s1 + "\n");

bReader.close();
fReader.close();
}

public void writeToFile(File file,String string) throws IOException{
if(!file.exists()){
file.createNewFile();
}
FileWriter fWriter = new FileWriter(file);
fWriter.write(string);
fWriter.close();
}

public static void main(String[] args) {
WordProcessSystem wordProcessSystem = new WordProcessSystem();
wordProcessSystem.setVisible(true);
}
}

‘肆’ 求一个用Java编写的文本编辑器代码

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class MyTextEditor extends JFrame implements ActionListener,ItemListener,MouseListener
{
private File file;
private JTextArea textarea;
private JRadioButtonMenuItem rbmi_red,rbmi_blue,rbmi_green;
private JMenuItem menuitem_,menuitem_cut,menuitem_paste,menuitem_seek;
private JMenuItem menuitem_song,menuitem_fang,menuitem_kai;//字体变量
private JMenuItem menuitem_normal,menuitem_bold,menuitem_italic;//字形变量
private JMenuItem menuitem_20,menuitem_30,menuitem_40;//字号变量
private JMenuItem menuitem_exit,menuitem_infor;
private JPopupMenu popupmenu;
private JMenuItem menuitem_red,menuitem_green,menuitem_blue;
private JDialog dialog,dialog1;
private JButton button_seek;
private JTextField textfield_seek;
private JLabel label_seek,label_infor;
String seek;

public MyTextEditor()
{
super("文本编辑器");
this.setSize(400,300);
this.setLocation(360,300);
this.setDefaultCloseOperation(HIDE_ON_CLOSE);

Container ss=this.getContentPane();
this.textarea = new JTextArea();
JScrollPane dd=new JScrollPane(textarea);
ss.add(dd);
textarea.addMouseListener(this);
this.addMenu();
this.setVisible(true);
this.Dialog();
this.Dialog1();

this.file = null;
}

public MyTextEditor(String filename)
{
this();
if (filename!=null)
{
this.file = new File(filename);
this.setTitle(filename);
this.textarea.setText(this.readFromFile());
}
}

public MyTextEditor(File file)
{
this();
if (file!=null)
{
this.file = file;
this.setTitle(this.file.getName());
this.textarea.setText(this.readFromFile());
}
}

public void Dialog() //建立对话框的方法
{
dialog=new JDialog(this,"查找",true);
dialog.setLayout(new FlowLayout());
dialog.setSize(200,90);

label_seek=new JLabel("查找内容");
dialog.add(label_seek);

textfield_seek=new JTextField(10);
dialog.add(textfield_seek);

button_seek=new JButton("查找");
dialog.add(button_seek);
button_seek.addActionListener(this);

}
public void Dialog1()
{

dialog1=new JDialog(this,"专利",true);
dialog1.setLayout(new FlowLayout());
dialog1.setSize(200,100);

label_infor=new JLabel("刘同虎制作");
dialog1.add(label_infor);
}

public void addMenu()
{
JMenuBar menubar = new JMenuBar();
this.setJMenuBar(menubar);

JMenu menu_file = new JMenu("文件"); //文件菜单
menubar.add(menu_file);
JMenuItem menuitem_open = new JMenuItem("打开");
menu_file.add(menuitem_open);
menuitem_open.addActionListener(this);

JMenuItem menuitem_save = new JMenuItem("保存");
menu_file.add(menuitem_save);
menuitem_save.addActionListener(this);

JMenuItem menuitem_saveas = new JMenuItem("另存为");
menu_file.add(menuitem_saveas);
menuitem_saveas.addActionListener(this);

menuitem_exit=new JMenuItem("退出" );
menu_file.add(menuitem_exit);
menuitem_exit.addActionListener(this);

menuitem_infor=new JMenuItem("信息");
menu_file.add(menuitem_infor);
menuitem_infor.addActionListener(this);

JMenu menu_editor=new JMenu("编辑");//编辑菜单
menubar.add(menu_editor);

menuitem_seek=new JMenuItem("查找");
menu_editor.add(menuitem_seek);
menuitem_seek.addActionListener(this);

menuitem_=new JMenuItem("复制");
menuitem_.addActionListener(this);
menu_editor.add(menuitem_);

menuitem_cut=new JMenuItem("剪切");
menu_editor.add(menuitem_cut);
menuitem_cut.addActionListener(this);

menuitem_paste=new JMenuItem("粘贴");
menu_editor.add(menuitem_paste);
menuitem_paste.addActionListener(this);

JMenuItem menu_color=new JMenu("颜色");//颜色菜单
menu_editor.add(menu_color);

ButtonGroup buttongroup=new ButtonGroup();
rbmi_red=new JRadioButtonMenuItem("红",true);
buttongroup.add(rbmi_red);
menu_color.add(rbmi_red);
rbmi_red.addItemListener(this);

rbmi_blue=new JRadioButtonMenuItem("蓝",true);
buttongroup.add(rbmi_blue);
menu_color.add(rbmi_blue);
rbmi_blue.addItemListener(this);

rbmi_green=new JRadioButtonMenuItem("绿",true);
buttongroup.add(rbmi_green);
menu_color.add(rbmi_green);
rbmi_green.addItemListener(this);

JMenu menu_font=new JMenu("设置字体");//设置字体菜单
menubar.add(menu_font);

menuitem_song=new JMenuItem("宋体");
menu_font.add(menuitem_song);
menuitem_song.addActionListener(this);

menuitem_fang=new JMenuItem("仿宋");
menu_font.add(menuitem_fang);
menuitem_fang.addActionListener(this);

menuitem_kai=new JMenuItem("楷体");
menu_font.add(menuitem_kai);
menuitem_kai.addActionListener(this);

JMenu menu_style=new JMenu("设置字形");//设置字形菜单
menubar.add(menu_style);

menuitem_bold=new JMenuItem("粗体");
menu_style.add(menuitem_bold);
menuitem_bold.addActionListener(this);

menuitem_italic=new JMenuItem("斜体");
menu_style.add(menuitem_italic);
menuitem_italic.addActionListener(this);

JMenu menu_size=new JMenu("设置字号"); //设置字号菜单
menubar.add(menu_size);

menuitem_20=new JMenuItem("20");
menu_size.add(menuitem_20);
menuitem_20.addActionListener(this);

menuitem_30=new JMenuItem("30");
menu_size.add(menuitem_30);
menuitem_30.addActionListener(this);

menuitem_40=new JMenuItem("40");
menu_size.add(menuitem_40);
menuitem_40.addActionListener(this);

popupmenu=new JPopupMenu(); //快捷菜单
JMenuItem menuitem_red=new JMenuItem("红色");
popupmenu.add(menuitem_red);
menuitem_red.addActionListener(this);

JMenuItem menuitem_green=new JMenuItem("绿色");
popupmenu.add(menuitem_green);
menuitem_green.addActionListener(this);

menuitem_blue=new JMenuItem("蓝色");
popupmenu.add(menuitem_blue);
menuitem_blue.addActionListener(this);

textarea.add(popupmenu); //向文本区内添加快捷菜单

}

public void writeToFile(String lines) //写文件
{
try
{
FileWriter fout = new FileWriter(this.file);
fout.write(lines+"\r\n");
fout.close();
}
catch (IOException ioex)
{
return;
}
}

public String readFromFile() //读文件
{
try
{
FileReader fin = new FileReader(this.file);
BufferedReader bin = new BufferedReader(fin);
String aline="", lines="";
do
{
aline = bin.readLine();
if (aline!=null)
lines += aline + "\r\n";
} while (aline!=null);

bin.close();
fin.close();
return lines;
}
catch (IOException ioex)
{
return null;
}
}

‘伍’ 用JAVA写一个文本编辑器,要用到设计模式,急!

10分,还要一个完整带文档的,你当网络的这破分多值钱啊。

‘陆’ 如何用java写一个文本编辑器

JDK自带一个简单的Notepad,你可以研究一下他的源代码。
在%JAVA_HOME%\demo\jfc\Notepad 目录下
JDK自带一个稍复杂的Stylepad,你可以研究一下他的源代码。
在%JAVA_HOME%\demo\jfc\Stylepad目录下

‘柒’ 在Java中编写文本编辑器

http://www.pudn.com/downloads40/sourcecode/mobile/j2me/detail140240.html

‘捌’ 用JAVA设计一个简单文本编辑器

要求挺多

‘玖’ 如何用java编写一个简单的文本编辑器

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class f1 extends Frame implements ActionListener
{
private MenuBar menubar=new MenuBar();
private Menu filemenu=new Menu("文件");
private Menu editmenu=new Menu("编辑");
private Menu formmenu=new Menu("格式");
private MenuItem[] itemf=new MenuItem[4];
private MenuItem[] iteme=new MenuItem[6];
private MenuItem[] items=new MenuItem[2];
private TextArea tf=new TextArea();

public int a=0,b=0,c=0,style=Font.PLAIN,size=15;
public String s1="red:"+a+" "+"green:"+b+" "+"blue"+c,
s2="宋体";

public String[] sz1={"10","16","24","30","32","36"},
sz2={"宋体","黑体","幼圆","隶书","行楷","Arial","Georgia"},
sz3={"粗体","倾斜","常规","粗斜"};

JDialog dialog=new JDialog(this,"字体",true);
Container cp=dialog.getContentPane();
JLabel[] lb=new JLabel[8];
JLabel lb1=new JLabel(s1,JLabel.LEFT);
JButton b1=new JButton("确定"),
b2=new JButton("取消");
JComboBox jc1=new JComboBox(),
jc2=new JComboBox(),
jc3=new JComboBox();
JScrollBar jb1=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb2=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb3=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);

阅读全文

与用java写一个简易文本编译器相关的资料

热点内容
命令方块指令冰封剑 浏览:784
android中so文件 浏览:276
手工用气球做的捏捏乐解压神器 浏览:196
app升级后就闪退怎么办 浏览:35
手表上的乐涂app怎么下载 浏览:721
程序员身上的六宗罪是什么 浏览:145
游戏编程精粹6 浏览:69
修复ie的命令 浏览:602
linux服务器怎么查看地址 浏览:65
底部异地持仓源码 浏览:105
加密应用手机 浏览:798
程序员考试考什么科目 浏览:485
程序员必备文档编辑 浏览:960
踩水果解压大全 浏览:634
什么是dk服务器在 浏览:461
nusoapphp下载 浏览:929
黑莓原生解压rar 浏览:956
百度解压缩在哪 浏览:788
硬解压卡怎么用 浏览:183
新买的联想服务器怎么配置 浏览:757