duang简易日历记事本

时间:2018-08-06 17:42:41
【文件属性】:

文件名称:duang简易日历记事本

文件大小:20KB

文件格式:JAVA

更新时间:2018-08-06 17:42:41

日历记事本

利用java语言开发建议日历记事本程序。 public class CalendarPad extends JFrame implements MouseListener{ int year,month,day; Hashtable hashtable; File file; static JTextField showDay[]; JLabel title[]; Calendar calendar; int week; NotePad notepad=null; Month changemonth; Year changeyear; String 星期[]={"日","一","二","三","四","五","六"}; JPanel leftPanel,rightPanel; //以下是定义CalendarPad方法 public CalendarPad(int year,int month,int day) { super("Duang日历记事本"); //设置窗体标题 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; changeyear=new Year(this); changeyear.setYear(year); changemonth=new Month(this); changemonth.setMonth(month); title=new JLabel[7]; //定义显示星期标签 showDay=new JTextField[42]; for(int j=0;j<7;j++) { title[j]=new JLabel(); title[j].setText(星期[j]); //定义显示星期标签 title[j].setBorder(BorderFactory.createRaisedBevelBorder()); //定义边框为斜面边框(凸) leftCenter.add(title[j]); //显示星期标签 } title[0].setForeground(Color.red); //将周日显示为红色 title[6].setForeground(Color.red); //将周六显示为红色 for(int i=0;i<42;i++) { showDay[i]=new JTextField(); showDay[i].addMouseListener(this); //添加鼠标进入 showDay[i].setEditable(false); //设置为不可编辑标签 leftCenter.add(showDay[i]); } calendar=Calendar.getInstance(); Box box=Box.createHorizontalBox(); box.add(changeyear); //添加改变年控件 box.add(changemonth); //添加改变月控件 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"); //新建"日历记事本.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); set_calendar(year,month); addWindowListener(new WindowAdapter() //注册监听器 { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); //设置主面板可见 setBounds(500,100,600,285); //设置主面板大小及位置 validate(); }


网友评论