用Java实现日历记事本源代码.doc
《用Java实现日历记事本源代码.doc》由会员分享,可在线阅读,更多相关《用Java实现日历记事本源代码.doc(65页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-date用Java实现日历记事本源代码用Java实现日历记事本源代码CalendarPad类import java.util.Calendar;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.Hashtable;public cla
2、ss 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
3、 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); 负责改变月.s
4、etMonth(month); title=new JLabel7; showDay=new JTextField42; for(int j=0;j7;j+) titlej=new JLabel(); titlej.setText(星期j); titlej.setBorder(BorderFactory.createRaisedBevelBorder(); leftCenter.add(titlej); title0.setForeground(Color.red); title6.setForeground(Color.blue); for(int i=0;i42;i+) showDayi=
5、new JTextField(); showDayi.addMouseListener(this); showDayi.setEditable(false); leftCenter.add(showDayi); 日历=Calendar.getInstance(); Box box=Box.createHorizontalBox(); box.add(负责改变年); box.add(负责改变月); leftNorth.add(box); leftPanel.setLayout(new BorderLayout(); leftPanel.add(leftNorth,BorderLayout.NOR
6、TH); leftPanel.add(leftCenter,BorderLayout.CENTER); leftPanel.add(new Label(请在年份输入框输入所查年份(负数表示公元前),并回车确定), 6 / 25 BorderLayout.SOUTH) ; leftPanel.validate(); Container con=getContentPane(); JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,rightPanel); con.add(split,BorderLayout
7、.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) notep
8、ad=new NotePad(this); rightPanel.add(notepad); 设置日历牌(year,month); 7 / 25 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
9、(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); 8 / 25 else 排列号码(星期几,28); public void 排列号码(int 星期几,int 月天数) for(
10、int i=星期几,n=1;i星期几+月天数;i+) showDayi.setText(+n); if(n=day) showDayi.setForeground(Color.green); showDayi.setFont(new Font(TimesRoman,Font.BOLD,20); else showDayi.setFont(new Font(TimesRoman,Font.BOLD,12); showDayi.setForeground(Color.black); if(i%7=6) showDayi.setForeground(Color.blue); if(i%7=0) sh
11、owDayi.setForeground(Color.red); 9 / 25 n+; for(int i=0;i星期几;i+) showDayi.setText(); for(int i=星期几+月天数;i42;i+) showDayi.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; note
12、pad.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(
13、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) p
14、ublic 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); 2、) Month类import javax.swing.*;import java.awt.*;import java.awt.event.*; 11 / 25
15、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(Colo
16、r.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=1) this.month=month; else this.month=1; s
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 实现 日历 记事本 源代码
限制150内