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);