日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java日历记事本ppt_JAVA做的日历记事本

發(fā)布時間:2025/3/19 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java日历记事本ppt_JAVA做的日历记事本 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

展開全部

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

class TextEditorFrame extends JFrame{

File file=null;

Color color=Color.red;

TextEditorFrame(){

initTextPane();

initAboutDialog();

initToolBar();

initMenu();

}

void initTextPane(){

getContentPane().add(new JScrollPane(text));

}

JTextPane text=new JTextPane(); //這是用來做文本框的

JFileChooser filechooser=new JFileChooser(); //文件選擇框

JColorChooser colorchooser=new JColorChooser();//

JDialog about=new JDialog(this); //關(guān)于對話框

JMenuBar menubar=new JMenuBar();//菜單32313133353236313431303231363533e58685e5aeb931333262363039

JMenu[] menus=new JMenu[]{

new JMenu("文件"),

new JMenu("編輯"),

new JMenu("幫助")

};

JMenuItem menuitems[][]=new JMenuItem[][]{{

new JMenuItem("新建"),

new JMenuItem("打開"),

new JMenuItem("保存"),

new JMenuItem("退出")

},

{

new JMenuItem("復制"),

new JMenuItem("剪切"),

new JMenuItem("粘貼"),

new JMenuItem("顏色")

},

{

new JMenuItem("關(guān)于")

}

};

void initMenu(){

for(int i=0;i

menubar.add(menus[i]);

for(int j=0;j

menus[i].add(menuitems[i][j]);

menuitems[i][j].addActionListener( action );

}

}

this.setJMenuBar(menubar);

}

ActionListener action=new ActionListener(){ //when here have not wrong:

public void actionPerformed(ActionEvent e){

JMenuItem mi=(JMenuItem)e.getSource();

String id=mi.getText();

if(id.equals("新建")){

text.setText("");

file=null;

}else if(id.equals("打開")){

if(file !=null)filechooser.setSelectedFile(file);

int returnVal=filechooser.showOpenDialog(TextEditorFrame.this);

if(returnVal==JFileChooser.APPROVE_OPTION){

file=filechooser.getSelectedFile();

openFile();

}

}else if(id.equals("保存")){

if(file!=null) filechooser.setSelectedFile(file);

int returnVal=filechooser.showSaveDialog(TextEditorFrame.this);

if(returnVal==JFileChooser.APPROVE_OPTION){

file=filechooser.getSelectedFile();

saveFile();

}

}else if(id.equals("退出")){

TextEditorFrame f=new TextEditorFrame();

int s=JOptionPane.showConfirmDialog(f,"你真的要結(jié)束嗎","結(jié)束程序",JOptionPane.YES_NO_CANCEL_OPTION);

if(s==JOptionPane.YES_OPTION)

System.exit(0);

}else if(id.equals("剪切")){

text.cut();

}else if(id.equals("復制")){

text.copy();

}else if(id.equals("粘貼")){

text.paste();

}else if(id.equals("color")){

color=JColorChooser.showDialog(TextEditorFrame.this,"",color);

text.setForeground(color);

}else if(id.equals("關(guān)于")){

about.setSize(200,150);

about.show();

}

}

};

void saveFile(){

try{

FileWriter fw=new FileWriter(file);

fw.write(text.getText());

fw.close();

}

catch(Exception e){e.printStackTrace();}

}

void openFile(){

try{

FileReader fr=new FileReader(file);

int len=(int)file.length();

char []buffer=new char[len];

fr.read(buffer,0,len);

fr.close();

text.setText(new String(buffer));

}catch(Exception e){e.printStackTrace();}

}

void initAboutDialog(){

about.getContentPane().add(new JLabel("作者-覃樹新:記事本Q1.0版本"));

about.setModal(true);

about.setSize(200,100);

}

JToolBar toolbar=new JToolBar();//我來加上工具條

JButton [] buttons=new JButton[]{

new JButton("", new ImageIcon("qin.jpg")),

new JButton("", new ImageIcon("shu.jpg")),

new JButton("", new ImageIcon("xin.jpg"))

};

void initToolBar(){

for(int i=0;i

toolbar.add(buttons[i]);

buttons[0].setToolTipText("復制");

buttons[0].addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

text.copy();

}

});

buttons[1].setToolTipText("剪切");

buttons[1].addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

text.cut();

}

});

buttons[2].setToolTipText("粘貼");

buttons[2].addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

text.paste();

}

});

this.getContentPane().add(toolbar,BorderLayout.NORTH);

}

}

public class F{

public static void main(String args[]){

TextEditorFrame f=new TextEditorFrame();

f.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e)

{

TextEditorFrame f=new TextEditorFrame();

int s=JOptionPane.showConfirmDialog(f,"你真的要結(jié)束嗎","結(jié)束程序",JOptionPane.YES_NO_OPTION);

if(s==JOptionPane.YES_OPTION)

System.exit(0);}

});

f.setTitle("簡單的記事本");

f.setSize(800,600);

f.show();

}

}

本回答被提問者采納

已贊過

已踩過<

你對這個回答的評價是?

評論

收起

總結(jié)

以上是生活随笔為你收集整理的java日历记事本ppt_JAVA做的日历记事本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。