java课程设计文本编辑器
❶ 在Java中编写文本编辑器
http://www.pudn.com/downloads40/sourcecode/mobile/j2me/detail140240.html
❷ 求一个用java的swing 编写的文本编辑器!谢谢大家!
//就10个财富值?还要求那么多,傻了你,测试已通过,望采纳
importjava.awt.*;
/**
*2015年1月日下午6:11:28
*@authorseason
*
*/
{
=1L;
privateJPanelcontentPane;
privateJTextAreatxtrJanuaryBy=newJTextArea("January02,2015By12052010,lookatthis,haiyan,ididit");
privateStringmyFontName;
privateintmyFontSize=15;
privateintmyFontType=0;
privateintmyFontColor;
private Fontf=null;
/**
*Launchtheapplication.
*/
publicstaticvoidmain(String[]args){
MyFontmyview=newMyFont();
myview.setVisible(true);
}
/**
*Createtheframe.
*/
publicMyFont(){
init();//初始化界面
}
publicvoidinit(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,558,300);
contentPane=newJPanel();
contentPane.setBorder(newEmptyBorder(5,5,5,5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanelColor=newJPanel();
Color.setBounds(10,10,215,46);
contentPane.add(Color);
Color.setLayout(null);
/**
*字体颜色监听
*/
finalJRadioButtonrdbtnRed=newJRadioButton("Red");
rdbtnRed.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==rdbtnRed){
myFontColor=1;
change(myFontColor,f);
}
}
});
rdbtnRed.setBounds(5,5,61,23);
Color.add(rdbtnRed);
finalJRadioButtonrdbtnBlue=newJRadioButton("Blue");
rdbtnBlue.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==rdbtnBlue){
myFontColor=2;
change(myFontColor,f);
}
}
});
rdbtnBlue.setBounds(68,5,68,23);
Color.add(rdbtnBlue);
finalJRadioButtonrdbtnGray=newJRadioButton("Gray");
rdbtnGray.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==rdbtnGray){
myFontColor=3;
change(myFontColor,f);
//txtrJanuaryBy.setFont(f);
}
}
});
rdbtnGray.setBounds(138,5,71,23);
Color.add(rdbtnGray);
ButtonGroupbuttongroup=newButtonGroup();
buttongroup.add(rdbtnGray);
buttongroup.add(rdbtnBlue);
buttongroup.add(rdbtnRed);
txtrJanuaryBy.setLineWrap(true);
txtrJanuaryBy.setWrapStyleWord(true);
txtrJanuaryBy.setBounds(10,113,522,126);
contentPane.add(txtrJanuaryBy);
JPanelpanel=newJPanel();
panel.setBounds(235,10,151,46);
contentPane.add(panel);
panel.setLayout(null);
/**
*字体形状监听
*/
JCheckBoxchckbxMy=newJCheckBox("Italic");
chckbxMy.setFont(newFont("宋体",Font.ITALIC,12));
chckbxMy.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
f=newFont(myFontName,2,myFontSize);
change(myFontColor,f);
}
});
chckbxMy.setBounds(69,6,61,23);
panel.add(chckbxMy);
finalJCheckBoxcheckBox_1=newJCheckBox("Bold");
checkBox_1.setFont(newFont("宋体",Font.BOLD,12));
checkBox_1.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
f=newFont(myFontName,1,myFontSize);
change(myFontColor,f);
}
});
checkBox_1.setBounds(6,6,61,23);
panel.add(checkBox_1);
String[]myFont={"宋体","utf-8","others"};
@SuppressWarnings({"rawtypes","unchecked"})
finalJComboBoxcomboBox=newJComboBox(myFont);
/**
*字体监听
*/
comboBox.addItemListener(newItemListener(){
publicvoiditemStateChanged(ItemEvente){
myFontName=comboBox.getSelectedItem().toString();
f=newFont(myFontName,myFontType,myFontSize);
change(myFontColor,f);
}
});
comboBox.setBounds(399,20,73,21);
contentPane.add(comboBox);
/**
*字体大小监听
*/
String[]mySize={"10","20","30"};
@SuppressWarnings({"rawtypes","unchecked"})
finalJComboBoxcomboBox_1=newJComboBox(mySize);
comboBox_1.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
myFontSize=Integer.parseInt(comboBox_1.getSelectedItem().toString());
f=newFont(myFontName,myFontType,myFontSize);
change(myFontColor,f);
}
});
comboBox_1.setBounds(482,20,50,21);
contentPane.add(comboBox_1);
=newJButton("ChangeBackGroupColor");
btnChangeBackgroupColor.setContentAreaFilled(false);
btnChangeBackgroupColor.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
changeBackGroupColor();
}
});
btnChangeBackgroupColor.setFont(newFont("Consolas",Font.BOLD,14));
btnChangeBackgroupColor.setBounds(10,66,215,23);
contentPane.add(btnChangeBackgroupColor);
}
/**
*changeTODO改变字体
*@paramcolorType
*@parammyFontvoid
*/
publicvoidchange(intcolorType,FontmyFont){
txtrJanuaryBy.setFont(myFont);
if(colorType==1){
txtrJanuaryBy.setForeground(Color.red);
}elseif(colorType==2){
txtrJanuaryBy.setForeground(Color.blue);
}else{
txtrJanuaryBy.setForeground(Color.gray);
}
}
/**
*changeBackGroupColorTODO随机产生RGB,改变文本框背景颜色
*void
*/
(){
//随机产生三基色
intred=(int)(Math.random()*255);
intgreen=(int)(Math.random()*255);
intblack=(int)(Math.random()*255);
Colorcolor=newColor(red,green,black);
txtrJanuaryBy.setBackground(color);
}
}
❸ 用JAVA设计一个简单文本编辑器
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*; //Date needed
import java.io.PrintWriter;
public class NotePad extends JFrame
{
JTextArea jta;
class newl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.setText("");
}
}
class openl implements ActionListener
{ public void actionPerformed(ActionEvent e)
{
JFileChooser jf=new JFileChooser();
jf.showOpenDialog(NotePad.this);
}
}
//保存文件的监听
class savel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFileChooser jf = new JFileChooser();
jf.showSaveDialog(NotePad.this);
}
}
//打印的监听 ?
class printl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// PrintWriter p = new PrintWriter(NotePad.this);
}
}
//退出记事本的监听
class exitl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);//退出
}
}
//拷贝的监听
class copyl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.copy();
}
}
//粘贴的监听
class pastel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.paste();
}
}
//剪切的监听
class cutl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.cut();
}
}
//查找的监听
//添加日期的监听
class datel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Date d=new Date();
jta.append(d.toString());
}
}
//构造函数
public NotePad()
{
jta=new JTextArea("",24,40);
JScrollPane jsp=new JScrollPane(jta);
JMenuBar jmb=new JMenuBar();
JMenu mFile=new JMenu("File");
JMenu mEdit=new JMenu("Edit");
JMenuItem mNew=new JMenuItem("New",KeyEvent.VK_N);
mNew.addActionListener(new newl());
mFile.add(mNew);
JMenuItem mOpen=new JMenuItem("Open",KeyEvent.VK_O);
mOpen.addActionListener(new openl());
mFile.add(mOpen);
JMenuItem mSave=new JMenuItem("Save");
mSave.addActionListener(new savel());
mFile.add(mSave);
mFile.addSeparator(); //添加分割线
JMenuItem mPrint = new JMenuItem("Print");
mPrint.addActionListener(new printl());
mFile.add(mPrint);
mFile.addSeparator(); //添加分割线
JMenuItem mExit=new JMenuItem("Exit");
mExit.addActionListener(new exitl());
mFile.add(mExit);
mFile.setMnemonic(KeyEvent.VK_F);
//编辑菜单的子菜单的处理
JMenuItem jmi;
jmi=new JMenuItem("Copy");
jmi.addActionListener(new copyl());
mEdit.add(jmi);
jmi=new JMenuItem("Cut");
jmi.addActionListener(new cutl());
mEdit.add(jmi);
jmi=new JMenuItem("Paste");
jmi.addActionListener(new pastel());
mEdit.add(jmi);
mEdit.addSeparator(); //添加分割线
jmi=new JMenuItem("Find");
mEdit.add(jmi);
jmi=new JMenuItem("FindNext");
mEdit.add(jmi);
mEdit.addSeparator();
jmi=new JMenuItem("Select All");
mEdit.add(jmi);
jmi=new JMenuItem("Date/Time");
jmi.addActionListener(new datel());
mEdit.add(jmi);
jmb.add(mFile);
jmb.add(mEdit);
this.setJMenuBar(jmb);
this.getContentPane().add(jsp);
this.setSize(200,200);
this.setVisible(true);
}
//主函数,程序入口点
public static void main(String s[])
{
new NotePad();
}
}
❹ 用java设计一个 文本编辑器
1.1 可以用列表 将程序中的函数列出-----这个好做,JList,JTable,JLabel等都可以。
1.2 点击列表项 可以还原到程序的相关行----什么意思?
2.1 新建函数时 可以弹出对话框 用以输入函数名和函数体-----这也好做,前者用JTextfield,后者就看你是函数意义了。
2.2 并在程序中自动生成代码----什么代码?好像和1.2同,意义不清。
你这里的函数的概念是什么?都包括什么符号?多变量?微积分?泛涵?
总要有各定域才好。你的应用对象是中学生?大学生?还是财会人员?
要对这里的函数有个明确表示,不然输入函数体的时候会有很多 exception的。
当然如果是编程的函数的概念就好办了。只需要动态编译所输入的代码,看能否过就好。
但话又说回来,面向对象的编程,就java来说重载,复用,还有继承,抽象,这个涵数和其他的关系如何考虑啊?
能说说问题的出处?目的?需求?。。。。。。
谢谢。
❺ 用java写一个文本编辑器(要有以下基本8个功能)
发给你了
❻ java课程设计:文本编辑器
网上很多伙计
❼ 求JAVA编写的文本编辑器。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*; //Date needed
import java.io.PrintWriter;
public class NotePad extends JFrame
{
JTextArea jta;
class newl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.setText("");
}
}
class openl implements ActionListener
{ public void actionPerformed(ActionEvent e)
{
JFileChooser jf=new JFileChooser();
jf.showOpenDialog(NotePad.this);
}
}
//保存文件的监听
class savel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFileChooser jf = new JFileChooser();
jf.showSaveDialog(NotePad.this);
}
}
//打印的监听 ?
class printl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// PrintWriter p = new PrintWriter(NotePad.this);
}
}
//退出记事本的监听
class exitl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);//退出
}
}
//拷贝的监听
class copyl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.copy();
}
}
//粘贴的监听
class pastel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.paste();
}
}
//剪切的监听
class cutl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.cut();
}
}
//查找的监听
//添加日期的监听
class datel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Date d=new Date();
jta.append(d.toString());
}
}
//构造函数
public NotePad()
{
jta=new JTextArea("",24,40);
JScrollPane jsp=new JScrollPane(jta);
JMenuBar jmb=new JMenuBar();
JMenu mFile=new JMenu("File");
JMenu mEdit=new JMenu("Edit");
JMenuItem mNew=new JMenuItem("New",KeyEvent.VK_N);
mNew.addActionListener(new newl());
mFile.add(mNew);
JMenuItem mOpen=new JMenuItem("Open",KeyEvent.VK_O);
mOpen.addActionListener(new openl());
mFile.add(mOpen);
JMenuItem mSave=new JMenuItem("Save");
mSave.addActionListener(new savel());
mFile.add(mSave);
mFile.addSeparator(); //添加分割线
JMenuItem mPrint = new JMenuItem("Print");
mPrint.addActionListener(new printl());
mFile.add(mPrint);
mFile.addSeparator(); //添加分割线
JMenuItem mExit=new JMenuItem("Exit");
mExit.addActionListener(new exitl());
mFile.add(mExit);
mFile.setMnemonic(KeyEvent.VK_F);
//编辑菜单的子菜单的处理
JMenuItem jmi;
jmi=new JMenuItem("Copy");
jmi.addActionListener(new copyl());
mEdit.add(jmi);
jmi=new JMenuItem("Cut");
jmi.addActionListener(new cutl());
mEdit.add(jmi);
jmi=new JMenuItem("Paste");
jmi.addActionListener(new pastel());
mEdit.add(jmi);
mEdit.addSeparator(); //添加分割线
jmi=new JMenuItem("Find");
mEdit.add(jmi);
jmi=new JMenuItem("FindNext");
mEdit.add(jmi);
mEdit.addSeparator();
jmi=new JMenuItem("Select All");
mEdit.add(jmi);
jmi=new JMenuItem("Date/Time");
jmi.addActionListener(new datel());
mEdit.add(jmi);
jmb.add(mFile);
jmb.add(mEdit);
this.setJMenuBar(jmb);
this.getContentPane().add(jsp);
this.setSize(200,200);
this.setVisible(true);
}
//主函数,程序入口点
public static void main(String s[])
{
new NotePad();
}
}
❽ 用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_copy,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_copy=new JMenuItem("复制");
menuitem_copy.addActionListener(this);
menu_editor.add(menuitem_copy);
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编写一个简单的文本编辑器
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);