记事本java课程设计(怎样用java编写一个记事本 ,具体步骤!)

本文目录
- 怎样用java编写一个记事本 ,具体步骤!
- 如何使用记事本编写java程序
- java程序设计,编写一个记事本程序
- java编写简单记事本
- 用java编辑日历记事本
- 急需日历记事本JAVA源代码
- 使用记事本开发java程序的步骤
- 急求java程序设计 日历记事本 的设计思路
- 日历记事本java,求大神指导
- java做日历记事本
怎样用java编写一个记事本 ,具体步骤!
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
public 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); // 关于对话框
JMenuBar menubar = new JMenuBar();// 菜单
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("关于") } };
void initMenu() {
for (int i = 0; i 《 menus.length; i++) {
menubar.add(menus);
for (int j = 0; j 《 menuitems.length; j++) {
menus);
menuitems.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, "你真的要结束吗", "结束程序",
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("关于")) {
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;
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 {
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 《 buttons.length; i++)
toolbar.add(buttons);
buttons.setToolTipText("复制");
buttons.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.copy();
}
});
buttons.setToolTipText("剪切");
buttons.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.cut();
}
});
buttons.setToolTipText("粘贴");
buttons.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text.paste();
}
});
this.getContentPane().add(toolbar, BorderLayout.NORTH);
}
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, "你真的要结束吗", "结束程序",
JOptionPane.YES_NO_OPTION);
if (s == JOptionPane.YES_OPTION)
System.exit(0);
}
});
f.setTitle("简单的记事本");
f.setSize(800, 600);
f.setVisible(true);
}
}
以前看到的一个程序
如何使用记事本编写java程序
很简单的啊,在记事本里写上相应的java代码,写好保存后将相应的文件名后缀改为****.java,然后用CMD去编译一下就可以了。
具体流程是这样的:
然后就可以去CMD那里编译和运行了。
在华信智原的JAVA课堂里面第一节课就会讲到这个基础的知识。
java程序设计,编写一个记事本程序
全实现,程序太长,发不上去,先实现基本的 图形用户界面
import java.awt.*;
import java.awt.event.*;
public class TestMenu {
public static void main (String args) {
new MenuFrame("新建"+" "+"文本文档"+".txt"+" "+"-"+" "+"记事本").launchFrame();
}
}
class MenuFrame extends Frame {
MenuBar mb = null;
MenuFrame (String s) {
super (s);
}
public void launchFrame() {
Menu file = new Menu ("文件");
Menu edit = new Menu ("");
Menu format = new Menu ("格式");
Menu help = new Menu ("帮助");
MenuItem newItem = new MenuItem ("新建");
newItem.addActionListener (new ActionListener () {
public void actionPerformed(ActionEvent e) {
final Frame ff = new Frame ("记事本");
ff.setMenuBar(mb);
ff.setBounds (300,300,400,200);
ff.setVisible (true);
ff. addWindowListener (new WindowAdapter () {
public void windowClosing(WindowEvent e) {
ff.setVisible (false);
}
} );
}
});
MenuItem saveItem = new MenuItem ("保存");
MenuItem exitItem = new MenuItem ("退出");
MenuItem helpTitle = new MenuItem ("帮助主题");
MenuItem line = new MenuItem ("-");
MenuItem about = new MenuItem ("关于记事本");
MenuItem copy = new MenuItem ("粘贴");
MenuItem serach = new MenuItem ("查找");
edit.add (copy);
edit.add (serach);
help.add (helpTitle);
help.add (line);
help.add (about);
exitItem.addActionListener (new ActionListener () {
public void actionPerformed(ActionEvent e) {
System.exit (0);
}
} );
file.add (newItem);
file.add (saveItem);
file.add (exitItem);
mb = new MenuBar();
mb.add (file);
mb.add (edit);
mb.add (format);
mb.add (help);
addWindowListener (new WindowAdapter () {
public void windowClosing(WindowEvent e) {
System.exit (0);
}
} );
setLayout (new FlowLayout());
setMenuBar (mb);
setBounds (300,300,400,200);
setVisible (true);
}
}
java编写简单记事本
方法/步骤
下载JDK,并安装成功,CMD测试Java环境安装成功。出现如下提示则Java环境安装成功
打开mycelipse进入主界面,点击左上角file--new---java project,新建一个Java项目,项目名字任意取,这里我取名为note--然后点击完成,创建Java项目
然后右键项目下的src--new---package,新建一个包,包名我定为notetest,然后点击完成
然后右键我们建立好的包notetest--new--class,包名为Note,点击完成
首先我们想导入工程所需要的包,以便编写程序时进行调用
package notepad;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
首先定义好编写程序时变量,我们设为成员变量方便以后调用
public class Notepad{
//屏幕分辨率
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
int height = Toolkit.getDefaultToolkit().getScreenSize().height;
//窗体
private Frame frm ;
//显示内容多行文本
private TextArea notetext;
//记事本菜单
private MenuBar mb;
//菜单
private Menu m ;
//菜单项
private MenuItem open,save;
为程序创建组件--Frame--菜单栏目--文本框TextArea
public Notepad(){init();}
private void init(){
frm = new Frame("模拟记事本");
//设置菜单
mb = new MenuBar();
m = new Menu("文件");
//显示文件的地方
notetext = new TextArea();
notetext.setBounds(30, 50, 750, 500);
frm.add(notetext);
myEvent();
为控件和按钮添加监听事件
private void myEvent() {
//打开菜单的事件处理
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//判断路径和文件名是否为空 如果为空结束程序
if(dir == null || name == null)
//如果不为空讲路径名和文件名封装到File对象里
file = new File(dir,name);
//使用字符缓冲读取文件
BufferedReader bfr = null;
try {
bfr = new BufferedReader(new FileReader(file));
});
save.addActionListener(new ActionListener(){
//获取路径和文件名
String dir =fd.getDirectory();
String name = fd.getFile();
//如果不为空讲路径名和文件名封装到File对象里
file = new File(dir,name);
}
BufferedWriter bfr= null;
}
});
}
}
然后创建主方法,开始测试程序,新建一个NoteDemo类
package notepad;
public class NoteDemo {
public static void main(String args) {
new Notepad();
}
}
用java编辑日历记事本
《html》
《head》
《title》HTML《/title》
《style type="text/css"》
#calender{
width:150;
height:170;
}
#currentTime{
border:1px dotted #999999;
width:80px;
text-align:center;
}
button{
border:1px solid #7baddd;
font:9pt Verdana,"宋体";
cursor: pointer;
}
table{
width:280px;
text-align:center;
}
《/style》
《script type="text/javascript"》
var daysOfMonth = new Array();
daysOfMonth = 31;
daysOfMonth = 28;
daysOfMonth = 31;
daysOfMonth = 30;
daysOfMonth = 31;
daysOfMonth = 30;
daysOfMonth = 31;
daysOfMonth = 31;
daysOfMonth = 30;
daysOfMonth = 31;
daysOfMonth = 30;
daysOfMonth = 31;
var monthchange=0;
var nowTime = new Date();
var nowYear =nowTime.getFullYear();
var nowMonth =nowTime.getMonth();
var nowDate =nowTime.getDate();
function genernate(year,month)
{
if(year==null||month==null)
{
year = nowYear;
month = nowMonth;
}
nowTime.setFullYear(year,month,1); if((nowYear%400==0)||((nowYear%4==0)&&((nowYear%100)!=0)))
daysOfMonth=29;
else
daysOfMonth=28;
var firstDay = nowTime.getDay();
var day = 1;
var result = "《table》";
result+="《thead》《tr》《th》日《/th》《th》一《/th》《th》二《/th》《th》三《/th》《th》四《/th》《th》五《/th》《th》六《/th》《/tr》《/thead》";
result+="《tbody》";
for(var i=0;i《6;i++)
{
result+="《tr》";
if(i!=0) firstDay=-1;
for(var j=0;j《7&&day《= daysOfMonth;j++)
{
if(j《firstDay)
result+="《td》 《/td》";
else
{
if((day==nowDate)&&(monthchange==0))
result+="《td》《span style=\"color:red;border:1px dotted #666666\"》"+day+"《/span》《/td》";
else
result+="《td》"+day+"《/td》";
day++;
}
}
result+="《tr》";
}
result+="《/tbody》";
result+="《/table》"; document.getElementById("calender").innerHTML = result;
setContent();
}
function preyear()
{
monthchange-=12;
genernate(--nowYear,nowMonth);
}
function nextyear()
{
monthchange+=12;
genernate(++nowYear,nowMonth);
}
function premonth()
{
--monthchange;
if(nowMonth==0)
{
nowMonth=11;
nowYear-=1;
}
else
nowMonth-=1;
genernate(nowYear,nowMonth);
}
function nextmonth()
{
++monthchange;
if(nowMonth==11)
{
nowMonth=0;
nowYear+=1;
}
else
nowMonth+=1;
genernate(nowYear,nowMonth);
}
function setContent()
{
document.getElementById("contentYear").innerHTML = nowYear;
document.getElementById("contentMonth").innerHTML = nowMonth+1;
}
function getCurrentTime()
{
var time = new Date();
var hours = time.getHours();
var minutes = time.getMinutes();
var second = time.getSeconds();
if((hours==0)&&(minutes==0)&&(second==0))
{
nowDate = time.getDate();
genernate(time.getFullYear(),time.getMonth());
}
document.getElementById("currentTime").innerHTML = time.toLocaleTimeString();
setTimeout("getCurrentTime()",500);
}
function currentDate()
{
var todayTime = new Date();
var todayYear =todayTime.getFullYear();
var todayMonth =todayTime.getMonth();
nowDate = todayTime.getDate();
monthchange=0;
nowYear = todayYear;
nowMonth = todayMonth;
genernate(todayYear,todayMonth);
}
《/script》
《/head》
《body onload="genernate();getCurrentTime();"》
《h3》自己做的小日历《/h3》
《div》
《div》《span》《span id="contentYear"》《/span》 年 《span id="contentMonth"》《/span》 月《/span》《/div》
《div》《button onclick="preyear();"》上一年《/button》《button onclick="nextyear();"》下一年《/button》《button onclick="premonth();"》上一月《/button》《button onclick="nextmonth();"》下一月《/button》《button onclick="currentDate();"》回到今天《/button》《/div》
《div id="calender"》《/div》
《/div》
《h3》当前时间《/h3》
《div id="currentTime"》《div》
《/body》
《/html》
急需日历记事本JAVA源代码
import java.util.Calendar;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Hashtable;
public class CalendarPad extends JFrame implements MouseListener
{
int year,month,day;
Hashtable hashtable;
File file;
JTextField showDay;
JLabel title;
Calendar 日历;
int 星期几;
NotePad notepad=null;
Month 负责改变月;
Year 负责改变年;
String 星期={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
JPanel leftPanel,rightPanel;
public CalendarPad(int year,int month,int day)
{
leftPanel=new JPanel();
JPanel leftCenter=new JPanel();
JPanel leftNorth=new JPanel();
leftCenter.setLayout(new GridLayout(7,7));
rightPanel=new JPanel();
this.year=year;
this.month=month;
this.day=day;
负责改变年=new Year(this);
负责改变年.setYear(year);
负责改变月=new Month(this);
负责改变月.setMonth(month);
title=new JLabel;
showDay=new JTextField;
for(int j=0;j《7;j++)
{
title=new JLabel();
title);
title.setBorder(BorderFactory.createRaisedBevelBorder());
leftCenter.add(title);
}
title.setForeground(Color.red);
title.setForeground(Color.blue);
for(int i=0;i《42;i++)
{
showDay=new JTextField();
showDay.addMouseListener(this);
showDay.setEditable(false);
leftCenter.add(showDay);
}
日历=Calendar.getInstance();
Box box=Box.createHorizontalBox();
box.add(负责改变年);
box.add(负责改变月);
leftNorth.add(box);
leftPanel.setLayout(new BorderLayout());
leftPanel.add(leftNorth,BorderLayout.NORTH);
leftPanel.add(leftCenter,BorderLayout.CENTER);
leftPanel.add(new Label("请在年份输入框输入所查年份(负数表示公元前),并回车确定"),
BorderLayout.SOUTH) ;
leftPanel.validate();
Container con=getContentPane();
JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
leftPanel,rightPanel);
con.add(split,BorderLayout.CENTER);
con.validate();
hashtable=new Hashtable();
file=new File("日历记事本.txt");
if(!file.exists())
{
try{
FileOutputStream out=new FileOutputStream(file);
ObjectOutputStream objectOut=new ObjectOutputStream(out);
objectOut.writeObject(hashtable);
objectOut.close();
out.close();
}
catch(IOException e)
{
}
}
notepad=new NotePad(this);
rightPanel.add(notepad);
设置日历牌(year,month);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setVisible(true);
setBounds(100,50,524,285);
validate();
}
public void 设置日历牌(int year,int month)
{
日历.set(year,month-1,1);
星期几=日历.get(Calendar.DAY_OF_WEEK)-1;
if(month==1||month==2||month==3||month==5||month==7
||month==8||month==10||month==12)
{
排列号码(星期几,31);
}
else if(month==4||month==6||month==9||month==11)
{
排列号码(星期几,30);
}
else if(month==2)
{
if((year%4==0&&year%100!=0)||(year%400==0))
{
排列号码(星期几,29);
}
else
{
排列号码(星期几,28);
}
}
}
public void 排列号码(int 星期几,int 月天数)
{
for(int i=星期几,n=1;i《星期几+月天数;i++)
{
showDay.setText(""+n);
if(n==day)
{
showDay.setForeground(Color.green);
showDay.setFont(new Font("TimesRoman",Font.BOLD,20));
}
else
{
showDay.setFont(new Font("TimesRoman",Font.BOLD,12));
showDay.setForeground(Color.black);
}
if(i%7==6)
{
showDay.setForeground(Color.blue);
}
if(i%7==0)
{
showDay.setForeground(Color.red);
}
n++;
}
for(int i=0;i《星期几;i++)
{
showDay.setText("");
}
for(int i=星期几+月天数;i《42;i++)
{
showDay.setText("");
}
}
public int getYear()
{
return year;
}
public void setYear(int y)
{
year=y;
notepad.setYear(year);
}
public int getMonth()
{
return month;
}
public void setMonth(int m)
{
month=m;
notepad.setMonth(month);
}
public int getDay()
{
return day;
}
public void setDay(int d)
{
day=d;
notepad.setDay(day);
}
public Hashtable getHashtable()
{
return hashtable;
}
public File getFile()
{
return file;
}
public void mousePressed(MouseEvent e)
{
JTextField source=(JTextField)e.getSource();
try{
day=Integer.parseInt(source.getText());
notepad.setDay(day);
notepad.设置信息条(year,month,day);
notepad.设置文本区(null);
notepad.获取日志内容(year,month,day);
}
catch(Exception ee)
{
}
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public static void main(String args)
{
Calendar calendar=Calendar.getInstance();
int y=calendar.get(Calendar.YEAR);
int m=calendar.get(Calendar.MONTH)+1;
int d=calendar.get(Calendar.DAY_OF_MONTH);
new CalendarPad(y,m,d);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Month extends Box implements ActionListener
{
int month;
JTextField showMonth=null;
JButton 下月,上月;
CalendarPad 日历;
public Month(CalendarPad 日历)
{
super(BoxLayout.X_AXIS);
this.日历=日历;
showMonth=new JTextField(2);
month=日历.getMonth();
showMonth.setEditable(false);
showMonth.setForeground(Color.blue);
showMonth.setFont(new Font("TimesRomn",Font.BOLD,16));
下月=new JButton("下月");
上月=new JButton("上月");
add(上月);
add(showMonth);
add(下月);
上月.addActionListener(this);
下月.addActionListener(this);
showMonth.setText(""+month);
}
public void setMonth(int month)
{
if(month《=12&&month》=1)
{
this.month=month;
}
else
{
this.month=1;
}
showMonth.setText(""+month);
}
public int getMonth()
{
return month;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==上月)
{
if(month》=2)
{
month=month-1;
日历.setMonth(month);
日历.设置日历牌(日历.getYear(),month);
}
else if(month==1)
{
month=12;
日历.setMonth(month);
日历.设置日历牌(日历.getYear(),month);
}
showMonth.setText(""+month);
}
else if(e.getSource()==下月)
{
if(month《12)
{
month=month+1;
日历.setMonth(month);
日历.设置日历牌(日历.getYear(),month);
}
else if(month==12)
{
month=1;
日历.setMonth(month);
日历.设置日历牌(日历.getYear(),month);
}
showMonth.setText(""+month);
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
public class NotePad extends JPanel implements ActionListener
{
JTextArea text;
JButton 保存日志,删除日志;
Hashtable table;
JLabel 信息条;
int year,month,day;
File file;
CalendarPad calendar;
public NotePad(CalendarPad calendar)
{
this.calendar=calendar;
year=calendar.getYear();
month=calendar.getMonth();
day=calendar.getDay();;
table=calendar.getHashtable();
file=calendar.getFile();
信息条=new JLabel(""+year+"年"+month+"月"+day+"日",JLabel.CENTER);
信息条.setFont(new Font("TimesRoman",Font.BOLD,16));
信息条.setForeground(Color.blue);
text=new JTextArea(10,10);
保存日志=new JButton("保存日志") ;
删除日志=new JButton("删除日志") ;
保存日志.addActionListener(this);
删除日志.addActionListener(this);
setLayout(new BorderLayout());
JPanel pSouth=new JPanel();
add(信息条,BorderLayout.NORTH);
pSouth.add(保存日志);
pSouth.add(删除日志);
add(pSouth,BorderLayout.SOUTH);
add(new JScrollPane(text),BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==保存日志)
{
保存日志(year,month,day);
}
else if(e.getSource()==删除日志)
{
删除日志(year,month,day);
}
}
public void setYear(int year)
{
this.year=year;
}
public int getYear()
{
return year;
}
public void setMonth(int month)
{
this.month=month;
}
public int getMonth()
{
return month;
}
public void setDay(int day)
{
this.day=day;
}
public int getDay()
{
return day;
}
public void 设置信息条(int year,int month,int day)
{
信息条.setText(""+year+"年"+month+"月"+day+"日");
}
public void 设置文本区(String s)
{
text.setText(s);
}
public void 获取日志内容(int year,int month,int day)
{
String key=""+year+""+month+""+day;
try
{
FileInputStream inOne=new FileInputStream(file);
ObjectInputStream inTwo=new ObjectInputStream(inOne);
table=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
}
catch(Exception ee)
{
}
if(table.containsKey(key))
{
String m=""+year+"年"+month+"月"+day+"这一天有日志记载,想看吗?";
int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(ok==JOptionPane.YES_OPTION)
{
text.setText((String)table.get(key));
}
else
{
text.setText("");
}
}
else
{
text.setText("无记录");
}
}
public void 保存日志(int year,int month,int day)
{
String 日志内容=text.getText();
String key=""+year+""+month+""+day;
String m=""+year+"年"+month+"月"+day+"保存日志吗?";
int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(ok==JOptionPane.YES_OPTION)
{
try
{
FileInputStream inOne=new FileInputStream(file);
ObjectInputStream inTwo=new ObjectInputStream(inOne);
table=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
table.put(key,日志内容);
FileOutputStream out=new FileOutputStream(file);
ObjectOutputStream objectOut=new ObjectOutputStream(out);
objectOut.writeObject(table);
objectOut.close();
out.close();
}
catch(Exception ee)
{
}
}
}
public void 删除日志(int year,int month,int day)
{
String key=""+year+""+month+""+day;
if(table.containsKey(key))
{
String m="删除"+year+"年"+month+"月"+day+"日的日志吗?";
int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(ok==JOptionPane.YES_OPTION)
{
try
{
FileInputStream inOne=new FileInputStream(file);
ObjectInputStream inTwo=new ObjectInputStream(inOne);
table=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
table.remove(key);
FileOutputStream out=new FileOutputStream(file);
ObjectOutputStream objectOut=new ObjectOutputStream(out);
objectOut.writeObject(table);
objectOut.close();
out.close();
text.setText(null);
}
catch(Exception ee)
{
}
}
}
else
{
String m=""+year+"年"+month+"月"+day+"无日志记录";
JOptionPane.showMessageDialog(this,m,"提示",JOptionPane.WARNING_MESSAGE);
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Year extends Box implements ActionListener
{
int year;
JTextField showYear=null;
JButton 明年,去年;
CalendarPad 日历;
public Year(CalendarPad 日历)
{
super(BoxLayout.X_AXIS);
showYear=new JTextField(4);
showYear.setForeground(Color.blue);
showYear.setFont(new Font("TimesRomn",Font.BOLD,14));
this.日历=日历;
year=日历.getYear();
明年=new JButton("下年");
去年=new JButton("上年");
add(去年);
add(showYear);
add(明年);
showYear.addActionListener(this);
去年.addActionListener(this);
明年.addActionListener(this);
}
public void setYear(int year)
{
this.year=year;
showYear.setText(""+year);
}
public int getYear()
{
return year;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==去年)
{
year=year-1;
showYear.setText(""+year);
日历.setYear(year);
日历.设置日历牌(year,日历.getMonth());
}
else if(e.getSource()==明年)
{
year=year+1;
showYear.setText(""+year);
日历.setYear(year);
日历.设置日历牌(year,日历.getMonth());
}
else if(e.getSource()==showYear)
{
try
{
year=Integer.parseInt(showYear.getText());
showYear.setText(""+year);
日历.setYear(year);
日历.设置日历牌(year,日历.getMonth());
}
catch(NumberFormatException ee)
{
showYear.setText(""+year);
日历.setYear(year);
日历.设置日历牌(year,日历.getMonth());
}
}
}
}
希望能帮到你,以上分为4个类。。分割线以标注了
使用记事本开发java程序的步骤
1.首先,先看看电脑是否设置为显示已知文件扩展名。
如果没有,要先设置一下。点击计算机,工具(T),文件夹选项(O),
查看,在高级设置一栏里找到隐藏已知文件扩展名,把前面的钩钩去掉。
2.点击鼠标右键,新建,文本文档,命名为:MyFirstJava.java
然后编写第一个程序代码,注意类名和文件名要一致,
还有划线部分首字母要大写。
3.写好程序之后,点击右上角的文件,另存为,出现下面的页面。
然后,要看你的jdk安装在哪(我的安装在D盘)。就可以把文件保存在D盘,还有文件名设置为MyFirstJava.java,保存类型设置为:所有文件。
]
4.保存好之后,关闭文件。点开时,在搜索程序和文件中输入cmd,
然后,Enter,Enter,就会出现下面的页面。
5.在控制台先输入d:(因为我的是在D盘,若是在C盘就输入c:,F盘就输入f:);
回车,再输入javac MyFirstJava.java(注意javac后空一格);
回车,在输入java MyFirstJava(java后面也有一个空格)。
这时,就会出来结果了!:)
6.运行结束都在D盘中(安装jdk的地方)
会出现一个MyFirstJave.Class 文件。
急求java程序设计 日历记事本 的设计思路
如果不限制实现的话,用access+jsp就可以搞定了,编码很简单,功能也很强大,归结于对数据库的增删改.
如果纯粹用java+awt+swing做起来则很复杂.不知道楼主到底需要什么.
我的思路就是在数据表中设置一个表
有时间和事件等字段,至于日历,有很多js脚本实现了的,你只需要选择时间的时候自动调用js脚本就可以了.如果按照我的思路,半天就可以搞定了.这样的功能也很强大,支持查询统计等功能.
实现的时候,如果有困难的话可以问我.
日历记事本java,求大神指导
需求并不清晰
,,,,,使用哪种界面做,这是1种知识
。。。。然后是日期的处理、判断、存储、……
java做日历记事本
电脑桌面上用于记录的办公软件推荐云便签敬业签:
云便签电脑版上直接在电脑桌面显示记事内容,可随手在电脑桌面上记事。
便签上有日志时间轴列表,所有的记事内容在时间轴上永久保存,误删的记事内容可通过时间轴找回。
在云便签网页版上支持日历总览的功能,可按月按天查看便签上的记事日程。

更多文章:
teammate(teammate,company,partner)
2026年10月11日 06:10
javascript arraybuffer(javascript可以把base64编码转换成二进制代码吗求示例代码!)
2026年10月11日 04:00
text函数公式(excel中round和text函数的区别是什么)
2026年10月11日 03:50
google chrome打不开(chrome浏览器打不开怎么回事 浏览器打不开的处理方法)
2026年10月11日 02:00
websocket整合springboot(Springboot整合Websocket遇到的坑)
2026年10月11日 01:40
drawerlayout(android 怎样让drawerlayout设置的侧滑菜单的内容充满屏幕)
2026年10月10日 19:20
xor四位数怎么运算(单片机怎样用C语言实现4个数字间的异或)
2026年10月10日 17:50
perl数组中最多的元素(用perl实现,得到一个数组中重复次数最多的元素)
2026年10月10日 17:00




