java课程设计_简单日历程序
JAVA日历记事本课程设计报告

Java日历记事本课程设计报告在设计日历记事本时,需要编写6个JA V A源文件:CalendarWindow.java、CalendarPad.java、NotePad.java、CalendarImage.java、Clock.java和CalendarMesssage.java效果图如下. CalendarWindow类import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*;import java.io.*;public class CalendarWindow extends JFrame implements ActionListener,MouseListener,FocusListener{int year,month,day;CalendarMessage calendarMessage;CalendarPad calendarPad;NotePad notePad;JTextField showYear,showMonth;JTextField[] showDay;CalendarImage calendarImage;String picturename;Clock clock;JButton nextYear,previousYear,nextMonth,previousMonth;JButton saveDailyRecord,deleteDailyRecord,readDailyRecord;JButton getPicture;File dir;Color backColor=Color.white ;public CalendarWindow(){dir=new File("./dailyRecord");dir.mkdir();showDay=new JTextField[42];for(int i=0;i<showDay.length;i++){showDay[i]=new JTextField();showDay[i].setBackground(backColor);showDay[i].setLayout(new GridLayout(3,3));showDay[i].addMouseListener(this);showDay[i].addFocusListener(this);}calendarMessage=new CalendarMessage();calendarPad=new CalendarPad();notePad=new NotePad();Calendar calendar=Calendar.getInstance();calendar.setTime(new Date());year=calendar.get(Calendar.YEAR);month=calendar.get(Calendar.MONTH)+1;day=calendar.get(Calendar.DAY_OF_MONTH);calendarMessage.setYear(year);calendarMessage.setMonth(month);calendarMessage.setDay(day);calendarPad.setCalendarMessage(calendarMessage);calendarPad.setShowDayTextField(showDay);notePad.setShowMessage(year,month,day);calendarPad.showMonthCalendar();doMark();calendarImage=new CalendarImage();calendarImage.setImageFile(new File("flower.jpg"));clock=new Clock();JSplitPane splitV1=new JSplitPane(JSplitPane.VERTICAL_SPLIT,calendarPad,calendarImage);JSplitPane splitV2=new JSplitPane(JSplitPane.VERTICAL_SPLIT,notePad,clock);JSplitPane splitH=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,splitV1,splitV2);add(splitH,BorderLayout.CENTER);showYear=new JTextField(""+year,6);showYear.setFont(new Font("TimesRoman",Font.BOLD,12));showYear.setHorizontalAlignment(JTextField.CENTER);showMonth=new JTextField(""+month,4);showMonth.setFont(new Font("TimesRoman",Font.BOLD,12)); showMonth.setHorizontalAlignment(JTextField.CENTER); nextYear=new JButton("下年");previousYear=new JButton("上年");nextMonth=new JButton("下月");previousMonth=new JButton("上月");nextYear.addActionListener(this);previousYear.addActionListener(this);nextMonth.addActionListener(this);previousMonth.addActionListener(this);JPanel north=new JPanel();north.add(previousYear);north.add(showYear);north.add(nextYear);north.add(previousMonth);north.add(showMonth);north.add(nextMonth);add(north,BorderLayout.NORTH);saveDailyRecord=new JButton("保存日志"); deleteDailyRecord=new JButton("删除日志"); readDailyRecord=new JButton("读取日志"); saveDailyRecord.addActionListener(this); deleteDailyRecord.addActionListener(this); readDailyRecord.addActionListener(this);JPanel pSouth=new JPanel();pSouth.add(saveDailyRecord);pSouth.add(deleteDailyRecord);pSouth.add(readDailyRecord);add(pSouth,BorderLayout.SOUTH);getPicture=new JButton("选择日历图像");getPicture.addActionListener(this);pSouth.add(getPicture);add(pSouth,BorderLayout.SOUTH);setVisible(true);setBounds(60,60,660,480);validate();setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e){if(e.getSource()==nextYear){year++;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==previousYear){year--;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==nextMonth){month++;if(month<1) month=12;showMonth.setText(""+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==previousMonth){month--;if(month<1) month=12;showMonth.setText(""+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==showYear){String s=showYear.getText().trim();char a[]=s.toCharArray();boolean boo=false;for(int i=0;i<a.length;i++)if(!(Character.isDigit(a[i])))boo=true;if(boo==true)JOptionPane.showMessageDialog(this, "您输入了非法年份","警告",JOptionPane.WARNING_MESSAGE);else if(boo==false)year=Integer.parseInt(s);showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==saveDailyRecord){notePad.save(dir,year,month,day);doMark();}else if(e.getSource()==deleteDailyRecord){notePad.delete(dir,year,month,day);doMark();}else if(e.getSource()==readDailyRecord){notePad.read(dir,year,month,day);}else if (e.getSource() ==getPicture ) {FileDialog fd=new FileDialog(this,"打开文件对话框");fd.setVisible(true);String fileopen = null, filename = null;fileopen = fd.getDirectory();filename = fd.getFile();calendarImage.setImageFile(new File(fileopen,filename));}}public void mousePressed(MouseEvent e){JTextField text=(JTextField)e.getSource();String str=text.getText().trim();try{ day=Integer.parseInt(str);}catch(NumberFormatException exp){}calendarMessage.setDay(day);notePad.setShowMessage(year,month,day);}public void mouseReleased(MouseEvent e){}public void mouseEntered(MouseEvent e){}public void mouseExited(MouseEvent e){}public void mouseClicked(MouseEvent e){}public void focusGained(FocusEvent e){Component com=(Component)e.getSource();com.setBackground(Color.pink);}public void focusLost(FocusEvent e){Component com=(Component)e.getSource();com.setBackground(backColor);}public void doMark(){for(int i=0;i<showDay.length;i++){showDay[i].removeAll();String str=showDay[i].getText().trim();try{int n=Integer.parseInt(str);if(isHaveDailyRecord(n)==true){JLabel mess=new JLabel("有");mess.setFont(new Font("TimesRoman",Font.PLAIN,11));mess.setForeground(Color.blue);showDay[i].add(mess);}}catch(Exception exp){}}calendarPad.repaint();calendarPad.validate();}public boolean isHaveDailyRecord(int n){String key=""+year+""+month+""+n;String [] dayFile=dir.list();boolean boo=false;for(int k=0;k<dayFile.length;k++){if(dayFile[k].equals(key+".txt")){boo=true;break;}}return boo;}public String getPicture_address() {String address = null;try {InputStream outOne = new FileInputStream("picture_address.txt");ObjectInputStream outTwo = new ObjectInputStream(outOne);try {address = (String) outTwo.readObject();} catch (Exception ex) {}outTwo.close();} catch (IOException eee) {}if (address != null) {return address;} else {return "picture.jpg";}}public void actionPerformed1(ActionEvent e) {if (e.getActionCommand().equals("更改图片背景")) {FileDialog dia = new FileDialog(this, "选择图片", FileDialog.LOAD);dia.setModal(true);dia.setVisible(true);if ((dia.getDirectory() != null) && (dia.getFile() != null)) {try {FileOutputStream inOne = new FileOutputStream("picture_address.txt");ObjectOutputStream inTwo = new ObjectOutputStream(inOne);inTwo.writeObject(dia.getDirectory() + dia.getFile());inTwo.close();} catch (IOException ee) {}String picturename = getPicture_address();calendarImage.setImageFile(new File(picturename));}}public static void main(String args[]){new CalendarWindow();}}CalendarPad类import javax.swing.*;import java.awt .*;import java.awt.event.*;import java.util.*;import javax.swing.JPanel;public class CalendarPad extends JPanel{int year,month,day;CalendarMessage calendarMessage;JTextField[] showDay;JLabel title[];String[] 星期={"SUN 日","MON 一","TUE 二","WED 三","THU 四","FRI 四","SAT 六"};JPanel north,center;public CalendarPad(){setLayout(new BorderLayout());north=new JPanel();north.setLayout(new GridLayout(1,7));center=new JPanel();center.setLayout(new GridLayout(6,7));add(center ,BorderLayout.CENTER );add(north,BorderLayout.NORTH );title=new JLabel[7];for(int j=0;j<7;j++){title[j]=new JLabel();title[j].setFont(new Font("TimesRoman",Font.BOLD ,12));title[j].setText(星期[j]);title[j].setHorizontalAlignment(JLabel.CENTER);title[j].setBorder(BorderFactory.createRaisedBevelBorder());north.add(title[j]);}title[0].setForeground(Color.red);title[6].setForeground(Color.blue);}public void setShowDayTextField(JTextField[]text){showDay=text;for(int i=0;i<showDay.length;i++){showDay[i].setFont(new Font("TimesRoman",Font.BOLD ,15));showDay[i].setHorizontalAlignment(JTextField.CENTER);showDay[i].setEditable(false);center.add(showDay[i]);}}public void setCalendarMessage (CalendarMessage calendarMessage){ this.calendarMessage=calendarMessage;}public void showMonthCalendar(){String[] a=calendarMessage.getMonthCalendar();for(int i=0;i<42;i++)showDay[i].setText(a[i]);validate();}}CalendarMesssage类import java.util.Calendar;public class CalendarMessage {int year=-1,month=-1,day=-1;public int getYear(){return year;}public void setMonth(int month){if(month<=12&&month>=1)this.month=month;elsethis.month =1;}public int getMonth(){return month;}public void setDay(int day){this.day =day;}public int getDay(){return day ;}public String []getMonthCalendar(){String[] day=new String[42];Calendar rili =Calendar.getInstance();rili.set(year, month-1,1);int 星期几=rili.get(Calendar.DAY_OF_WEEK )-1;int dayAmount=0;if(month==1||month==3||month==5||month==7||month==8||month==10||month== 12)dayAmount=31;if(month==4||month==6||month==9||month==11)dayAmount=30;if(month==2)if(((year%4==0)&&(year%100!=0)||year%400==0))dayAmount=29;elsedayAmount=28;for(int i=0;i<星期几;i++)day[i]="";for(int i=星期几,n=1;i<星期几+dayAmount;i++){day[i]=String.valueOf(n);n++;}for(int i=星期几+dayAmount;i<42;i++)day[i]="";return day;}public void setYear(int year) {this.year = year;}}NotePad类import java.awt.*;import javax.swing.*;import javax.swing.border.Border;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import java.io.*;import java.awt.event.*;public class NotePad extends JPanel implements ActionListener {JTextArea text;JTextField showMessage;JPopupMenu menu;JMenuItem itemCopy, itemCut, itemPaste, itemClear, btn;public NotePad() {showMessage = new JTextField();showMessage.setHorizontalAlignment(JTextField.CENTER);showMessage.setFont(new Font("TimesRoman", Font.BOLD, 16));showMessage.setForeground(Color.blue);showMessage.setBackground(Color.pink);showMessage.setBorder(BorderFactory.createRaisedBevelBorder());showMessage.setEditable(false);menu = new JPopupMenu();itemCopy = new JMenuItem("复制");itemCut = new JMenuItem("剪切");itemPaste = new JMenuItem("粘贴");itemClear = new JMenuItem("清空");btn = new JMenuItem("字体");itemCopy.addActionListener(this);itemCut.addActionListener(this);itemPaste.addActionListener(this);itemClear.addActionListener(this);btn.addActionListener(this);menu.add(itemCopy);menu.add(itemCut);menu.add(itemPaste);menu.add(itemClear);menu.add(btn);text = new JTextArea(10, 10);text.addMouseListener(new MouseAdapter() {public void mousePressed(MouseEvent e) {if (e.getModifiers() == InputEvent.BUTTON3_MASK)menu.show(text, e.getX(), e.getY());}});setLayout(new BorderLayout());add(showMessage, BorderLayout.NORTH);add(new JScrollPane(text), BorderLayout.CENTER);}public void setShowMessage(int year, int month, int day) {showMessage.setText("" + year + "年" + month + "月" + day + "日");showMessage.setForeground(Color.blue);showMessage.setFont(new Font("宋体", Font.BOLD, 15));}public void save(File dir, int year, int month, int day) {String dailyContent = text.getText();String fileName = "" + year + "" + month + "" + day + ".txt";String key = "" + year + "" + month + "" + day;String[] dayFile = dir.list();boolean boo = false;for (int k = 0; k < dayFile.length; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}}if (boo) {String m = "" + year + "年" + month + "月" + day+ "已有日志,将新的内容添加到日志吗?";int ok = JOptionPane.showConfirmDialog(this, m, "",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if (ok == JOptionPane.YES_OPTION) {try {File f = new File(dir, fileName);RandomAccessFile out = new RandomAccessFile(f, "rw");long fileEnd = out.length();byte[] bb = dailyContent.getBytes();out.seek(fileEnd);out.write(bb);out.close();} catch (IOException exp) {}}} else {String m = "" + year + "年" + month + "月" + day + "还没有日志,保存日志吗?";int ok = JOptionPane.showConfirmDialog(this, m, "询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if (ok == JOptionPane.YES_OPTION) {try {File f = new File(dir, fileName);RandomAccessFile out = new RandomAccessFile(f, "rw");long fileEnd = out.length();byte[] bb = dailyContent.getBytes();out.seek(fileEnd);out.write(bb);out.close();} catch (IOException exp) {}}}}public void delete(File dir, int year, int month, int day) {String key = "" + year + "" + month + "" + day;String[] dayFile = dir.list();boolean boo = false;for (int k = 0; k < dayFile.length; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}}if (boo) {String m = "删除" + year + "年" + month + "月" + day + "日的日志吗?";int ok = JOptionPane.showConfirmDialog(this, m, "询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if (ok == JOptionPane.YES_OPTION) {String fileName = "" + year + "" + month + "" + day + ".txt";File deleteFile = new File(dir, fileName);deleteFile.delete();}}else {String m = "" + year + "" + month + "" + day + "";JOptionPane.showMessageDialog(this, m, "提示",JOptionPane.WARNING_MESSAGE);}}public void read(File dir, int year, int month, int day) {String fileName = "" + year + "" + month + "" + day + ".txt";String key = "" + year + "" + month + "" + day;String[] dayFile = dir.list();boolean boo = false;for (int k = 0; k < dayFile.length; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}}if (boo) {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(null);try {File f = new File(dir, fileName);FileReader inOne = new FileReader(f);BufferedReader inTwo = new BufferedReader(inOne);String s = null;while ((s = inTwo.readLine()) != null)text.append(s + "\n");inOne.close();inTwo.close();} catch (IOException exp) {}}} else {String m = "" + year + "" + month + "" + day + "";JOptionPane.showMessageDialog(this, m, "提示",JOptionPane.WARNING_MESSAGE);}}public void actionPerformed(ActionEvent e) {if (e.getSource() == itemCopy)text.copy();else if (e.getSource() == itemCut)text.cut();else if (e.getSource() == itemPaste)text.paste();else if (e.getSource() == itemClear)text.setText(null);if (e.getSource() == btn) {JFontDialog nFD = new JFontDialog("选择字体");nFD.setModal(true);nFD.setVisible(true);text.setFont(nFD.myFont);}}}class JFontDialog extends JDialog {private static final long serialVersionUID = 1L;JList fontpolics, fontstyle, fontsize;JTextField fontpolict, fontstylet, fontsizet;String example;JLabel FontResolvent;JButton buttonok, buttoncancel;Font myFont;public JFontDialog(String title) {Container container = getContentPane();container.setLayout(new BorderLayout());JPanel panel = new JPanel();panel.setLayout(new GridLayout(2, 1));JPanel FontSet, FontView;FontSet = new JPanel(new GridLayout(1, 4));FontView = new JPanel(new GridLayout(1, 2));example = "AaBbCcDdEe";FontResolvent = new JLabel(example, JLabel.CENTER);FontResolvent.setBackground(Color.WHITE);ListSelectionListener selectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) {if (((JList) e.getSource()).getName().equals("polic")) {fontpolict.setText((String) fontpolics.getSelectedValue());FontResolvent.setFont(new Font(fontpolict.getText(),FontResolvent.getFont().getStyle(), FontResolvent.getFont().getSize()));}if (((JList) e.getSource()).getName().equals("style")) {fontstylet.setText((String) fontstyle.getSelectedValue());FontResolvent.setFont(new Font(FontResolvent.getFont().getFontName(), fontstyle.getSelectedIndex(),FontResolvent.getFont().getSize()));}if (((JList) e.getSource()).getName().equals("size")) {fontsizet.setText((String) fontsize.getSelectedValue());try {Integer.parseInt(fontsizet.getText());} catch (Exception excepInt) {fontsizet.setText(FontResolvent.getFont().getSize()+ "");}FontResolvent.setFont(new Font(FontResolvent.getFont().getFontName(), FontResolvent.getFont().getStyle(),Integer.parseInt(fontsizet.getText())));}}};KeyListener keyListener = new KeyListener() {public void keyPressed(KeyEvent e) {if (e.getKeyCode() == 10) {if (((JTextField) e.getSource()).getName().equals("polic")) {FontResolvent.setFont(new Font(fontpolict.getText(),FontResolvent.getFont().getStyle(),FontResolvent.getFont().getSize()));}if (((JTextField) e.getSource()).getName().equals("style")) {fontstylet.setText((String) fontstyle.getSelectedValue());FontResolvent.setFont(new Font(FontResolvent.getFont().getFontName(), fontstyle.getSelectedIndex(),FontResolvent.getFont().getSize()));}if (((JTextField) e.getSource()).getName().equals("size")) {try {Integer.parseInt(fontsizet.getText());} catch (Exception excepInt) {fontsizet.setText(FontResolvent.getFont().getSize()+ "");}FontResolvent.setFont(new Font(FontResolvent.getFont().getFontName(), FontResolvent.getFont().getStyle(), Integer.parseInt(fontsizet.getText())));}}}public void keyReleased(KeyEvent e) {}public void keyTyped(KeyEvent e) {}};// 字体JPanel Fontpolic = new JPanel();Border border = BorderFactory.createLoweredBevelBorder();border = BorderFactory.createTitledBorder(border, "字体");Fontpolic.setBorder(border);Font[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();int taille = fonts.length;String[] policnames = new String[taille];for (int i = 0; i < taille; i++) {policnames[i] = fonts[i].getName();}fontpolics = new JList(policnames);fontpolics.setName("polic");fontpolics.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontpolics.addListSelectionListener(selectionListener);fontpolics.setVisibleRowCount(6);fontpolict = new JTextField(policnames[0]);fontpolict.setName("polic");fontpolict.addKeyListener(keyListener);JScrollPane jspfontpolic = new JScrollPane(fontpolics);Fontpolic.setLayout(new BoxLayout(Fontpolic, BoxLayout.PAGE_AXIS)); Fontpolic.add(fontpolict);Fontpolic.add(jspfontpolic);// 样式JPanel Fontstyle = new JPanel();border = BorderFactory.createLoweredBevelBorder();border = BorderFactory.createTitledBorder(border, "样式");Fontstyle.setBorder(border);String[] styles = { "PLAIN", "BOLD", "ITALIC", "BOLD ITALIC" };fontstyle = new JList(styles);fontstyle.setName("style");fontstyle.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontstyle.addListSelectionListener(selectionListener);fontstyle.setVisibleRowCount(6);fontstylet = new JTextField(styles[0]);fontstylet.setName("style");fontstylet.addKeyListener(keyListener);JScrollPane jspfontstyle = new JScrollPane(fontstyle);Fontstyle.setLayout(new BoxLayout(Fontstyle, BoxLayout.PAGE_AXIS)); Fontstyle.add(fontstylet);Fontstyle.add(jspfontstyle);// 大小JPanel Fontsize = new JPanel();border = BorderFactory.createLoweredBevelBorder();border = BorderFactory.createTitledBorder(border, "大小");Fontsize.setBorder(border);String[] sizes = { "10", "14", "18", "22", "26", "30" };fontsize = new JList(sizes);fontsize.setName("size");fontsize.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontsize.addListSelectionListener(selectionListener);fontsize.setVisibleRowCount(6);fontsizet = new JTextField(sizes[0]);fontsizet.setName("size");fontsizet.addKeyListener(keyListener);JScrollPane jspfontsize = new JScrollPane(fontsize);Fontsize.setLayout(new BoxLayout(Fontsize, BoxLayout.PAGE_AXIS)); Fontsize.add(fontsizet);Fontsize.add(jspfontsize);FontSet.add(Fontpolic);FontSet.add(Fontstyle);FontSet.add(Fontsize);FontView.add(FontResolvent);panel.add(FontSet);panel.add(FontView);JPanel panelnorth = new JPanel();panelnorth.setLayout(new FlowLayout());buttonok = new JButton("确定");buttoncancel = new JButton("取消");panelnorth.add(buttonok);panelnorth.add(buttoncancel);buttonok.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {myFont = FontResolvent.getFont();JFontDialog.this.setVisible(false);}});buttoncancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {JFontDialog.this.setVisible(false);}});container.add(panel, BorderLayout.CENTER);container.add(panelnorth, BorderLayout.SOUTH);setSize(400, 300);}}CalendarImage类import javax.swing.*;import java.io.*;import java.awt.*;public class CalendarImage extends JPanel{File imageFile;Image image;Toolkit tool;CalendarImage(){tool=getToolkit();}public void setImageFile(File f){imageFile=f;try{ image=tool.getImage(imageFile.toURI().toURL());}catch(Exception exp){}repaint();}public void paintComponent(Graphics g){super.paintComponent(g);int w=getBounds().width;int h=getBounds().height;g.drawImage(image, 0, 0, w, h, this);}}Clock类import java.applet.Applet;import java.applet.AudioClip;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.geom.Line2D;import java.io.File;import .MalformedURLException;import .URI;import .URL;import java.util.Date;import javax.swing.JPanel;public class Clock extends JPanel implements ActionListener { Date date;javax.swing.Timer secondTime;int hour,munite,second;Line2D secondLine,muniteLine,hourLine;Line2D m=new Line2D.Double(0,0,0,0);Line2D s=new Line2D.Double(0,0,0,0);int a,b,c,width,height;double pointSX[]=new double[60],pointSY[]=new double[60],pointMX[]=new double[60],pointMY[]=new double[60],pointHX[]=new double[60],pointHY[]=new double[60];Clock(){setBackground(Color.cyan);initPoint();secondTime=new javax.swing.Timer(1000,this);secondLine=new Line2D.Double(0,0,0,0);muniteLine=new Line2D.Double(0,0,0,0);hourLine=new Line2D.Double(0,0,0,0);secondTime.start();}private void initPoint(){width=getBounds().width;height=getBounds().height;pointSX[0]=0;pointSY[0]=-height/2*5/6;pointMX[0]=0;pointMY[0]=-(height/2*4/5);pointHX[0]=0;pointHY[0]=-(height/2*2/3);double angle=6*Math.PI/180;for(int i=0;i<59;i++){pointSX[i+1]=pointSX[i]*Math.cos(angle)-Math.sin(angle)*pointSY[i];pointSY[i+1]=pointSY[i]*Math.cos(angle)+pointSX[i]*Math.sin(angle);pointMX[i+1]=pointMX[i]*Math.cos(angle)-Math.sin(angle)*pointMY[i];pointMY[i+1]=pointMY[i]*Math.cos(angle)+pointMX[i]*Math.sin(angle);pointHX[i+1]=pointHX[i]*Math.cos(angle)-Math.sin(angle)*pointHY[i];pointHY[i+1]=pointHY[i]*Math.cos(angle)+pointHX[i]*Math.sin(angle);}for(int i=0;i<60;i++){pointSX[i]=pointSX[i]+width/2;pointSY[i]=pointSY[i]+height/2;pointMX[i]=pointMX[i]+width/2;pointMY[i]=pointMY[i]+height/2;pointHX[i]=pointHX[i]+width/2; pointHY[i]=pointHY[i]+height/2;}}public void paintComponent(Graphics g){super.paintComponent(g);initPoint();for(int i=0;i<60;i++){int m=(int)pointSX[i];int n=(int)pointSY[i];if(i%5==0){if(i==0||i==15||i==30||i==45){int k=10;g.setColor(Color.orange);g.fillOval(m-k/2, n-k/2, k, k);}else{int k=7;g.setColor(Color.orange );g.fillOval(m-k/2, n-k/2, k, k);}}else{int k=2;g.setColor(Color.black);g.fillOval(m-k/2, n-k/2, k, k);}}g.fillOval(width/2-5, height/2-5, 10, 10);Graphics2D g_2d=(Graphics2D)g;g_2d.setColor(Color.red);g_2d.draw(secondLine);BasicStroke bs=newBasicStroke(2f,BasicStroke.CAP_ROUND,BasicStroke.JOIN_MITER);g_2d.setStroke(bs);g_2d.setColor(Color.blue);g_2d.draw(muniteLine);bs=newBasicStroke(2f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER);g_2d.setStroke(bs);g_2d.setColor(Color.orange);g_2d.draw(hourLine);bs=newBasicStroke(4f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER);g_2d.setStroke( bs);}public void actionPerformed(ActionEvent e){if(e.getSource()==secondTime){date=new Date();String s=date.toString();。
Java程序日历记事本系统课程设计

目录1.课程设计目的………………………………………………………………页码2.课程设计题目描述和要求…………………………………………页码3.课程设计报告内容…………………………………………………………页码3.1总体设计……………………………………………………………………页码3.2详细设计……………………………………………………………………页码3.3编码实现……………………………………………………………………页码3.4系统测试……………………………………………………………………页码3.5系统运行……………………………………………………………………页码4.总结…………………………………………………………………………页码参考文献………………………………………………………………………页码1.课程设计目的1.学习Java程序开发的环境搭建与配置,并且在实际运用中学习和和掌握Java程序开发的过程2.通过课程设计进一步掌握Java程序设计语言的基础内容,如用户图形界面设计等3.通过亲自设计,编写,调试程序来扩展知识面和动手操作能力2.课程设计题目描述和要求设计一个日历记事本.具体要求如下:1.可以设置日历的日期2. 可以判断当前日期是否有日志记录3. 对有日志记录的日期,可以对该日期的日志记录进行修改和删除4. 对没有日志记录的日期,可以创建并保存新建的日志记录3.课程设计报告内容3.1总体设计1> 功能图2> 流程图3> 类图3.2详细设计表1 日历记事本系统主面板与日历板模块(CalendarPad.java)表2 日历记事本系统年设置模块(Year.java)表3 日历记事本系统月设置模块(Month.java)表4 日历记事本系统记事本模块(NotePad.java)3.3编码实现1.日历记事本系统主面板与日历板模块(CalendarPad.java)该模块设计主要主要包含以下成员变量:年(year)月(month)日(day)存放日期的表(Hashtable)存放日志的文件(File)主要方法有:创建程序主面板的构造方法(CalendarPad)处理ActionEvent事件的接口方法(actionPerformed)程序开始运行的main()方法。
java课程设计日历记事本

java课程设计日历记事本湖南人文科技学院计算机系2009年6月19日- 1 -::1;(1)为用户提供一个简便的日历记事本;(2)对java技术的进一步了解和简单的运用;(3)初步的接触软件工程;26月8日分析课题、分配任务;对题目进行初步分析 6月9日建立模型,完成整体设计以及功能模块分析 6月10日确立每个类的功能,完成对算法的分析 6月11日完成CalendarPad类的设计6月12日完成对Year类的设计6月13日完成对Month类的设计6月14日完成对NotePad类的设计6月15日紧系程序测试与修改6月16日完成设计,整理说明书6月19日打包发布程序设计成绩:(教师填写)指导老师:(签字)2009年月日- 2 -摘要 ..................................................................... ................................................................... - 4 - 1. 引言 ..................................................................... ...................................................................... - 5 - 2.设计目的与任务 ..................................................................... ................................................... - 5 - 3.设计方案...................................................................... ............................................................... - 6 -3.1 总体设计 ..................................................................... ................................................... - 6 -3.2设计要求 ..................................................................... .................................................... - 6 -3.3系统的主要功能...................................................................... ....................................... - 6 -3.4系统功能结构图...................................................................... ....................................... - 6 -3.5运行功能(截图) ................................................................... ..................................... - 7 -4.结束语 ..................................................................... .................................................................... - 9 - 5.致谢 ..................................................................... .................................................................... - 9 - 6.参考文献...................................................................... ............................................................. - 10 - 7.附录A:源程序 ..................................................................... .................................................... - 11 - 8附录B:编码规范 ..................................................................... ............................................. - 24 -- 3 -本课程设计通过代码实现将理论知识和具体实践相结合,巩固提高了对JAVA的相关方法与概念的理解,使学生的发散思维及动手能力进一步加强,加强对计算机及软件工程的进一步了解。
日历表java课程设计

日历表java课程设计一、教学目标本课程旨在通过Java编程语言实现一个简单的日历表应用程序,帮助学生掌握基本的编程概念和技能,培养他们的逻辑思维能力和问题解决能力。
具体的教学目标如下:1.了解Java编程语言的基本语法和结构。
2.掌握面向对象编程的基本概念,如类、对象、封装、继承和多态。
3.学习日历表的基本结构和功能,包括年、月、日和星期等信息。
4.能够使用Java编程语言编写简单的程序。
5.学会使用Java编程语言实现日历表的基本功能,如显示当前日期、切换月份等。
6.掌握使用Java编程语言处理日期和时间的常用方法。
情感态度价值观目标:1.培养学生的团队合作意识和沟通能力,通过小组合作完成日历表项目。
2.培养学生的创新思维和问题解决能力,鼓励他们提出新的想法和改进方案。
3.培养学生的学习兴趣和自信心,让他们感受到编程的乐趣和成就感。
二、教学内容本课程的教学内容主要包括Java编程语言的基本概念和语法、面向对象编程的原理和方法、日历表的基本结构和功能。
具体的教学大纲如下:1.Java编程语言的基本概念和语法:–数据类型、变量和常量–运算符和表达式–控制语句(条件语句、循环语句)–函数和方法2.面向对象编程的原理和方法:–类和对象的概念–属性和方法的封装–继承和多态的原理和应用3.日历表的基本结构和功能:–年、月、日和星期的表示方法–日历表的布局和设计–日历表的功能实现(显示当前日期、切换月份等)三、教学方法为了提高学生的学习兴趣和主动性,本课程将采用多种教学方法相结合的方式进行教学。
具体的教学方法如下:1.讲授法:教师通过讲解Java编程语言的基本概念和语法、面向对象编程的原理和方法,为学生提供系统的知识结构。
2.案例分析法:教师通过分析具体的日历表案例,引导学生理解和掌握日历表的设计和实现方法。
3.实验法:学生通过编写Java程序实现日历表的功能,培养他们的实际编程能力和问题解决能力。
4.小组讨论法:学生分组合作完成日历表项目,通过讨论和交流促进团队合作和沟通能力的发展。
java日历小程序课程设计

java日历小程序课程设计【标题】Java日历小程序课程设计【摘要】本文将详细介绍一种基于Java编程语言的日历小程序的设计和实现。
通过该小程序,用户可以方便地查看日期、周数和节假日,并进行简单的日程安排。
本文将分为以下几个部分进行介绍:需求分析、系统设计、界面设计、功能实现和测试。
通过阅读本文,读者将了解到如何使用Java编写一个简单实用的日历小程序。
【关键词】Java编程语言、日历小程序、需求分析、系统设计、界面设计、功能实现、测试【正文】一、需求分析日历小程序的主要功能是显示当前日期、周数和节假日,并提供简单的日程安排功能。
用户可以通过界面直观地查看日历信息,并添加、编辑和删除日程。
具体需求如下:1. 显示当前日期:程序启动时,显示当前日期,包括年、月、日。
2. 显示当前周数:程序启动时,显示当前所在周数。
3. 显示节假日信息:根据国家或地区的节假日规定,显示当天是否为节假日。
4. 查看日历:用户可以通过界面查看指定年份和月份的日历信息。
5. 添加日程:用户可以添加新的日程安排,包括日期、时间和内容。
6. 编辑日程:用户可以编辑已有的日程安排,修改日期、时间和内容。
7. 删除日程:用户可以删除已有的日程安排。
二、系统设计1. 技术选型:本系统采用Java编程语言进行开发。
使用Java的面向对象特性,实现日历小程序的各项功能。
2. 架构设计:采用MVC(Model-View-Controller)架构模式,将数据、界面和逻辑分离,提高代码的可维护性和可扩展性。
3. 数据存储:使用SQLite数据库存储日程信息,包括日期、时间和内容。
4. 外部接口:通过调用第三方API获取节假日信息,并根据返回的数据判断当天是否为节假日。
三、界面设计1. 主界面:显示当前日期、周数和节假日信息。
提供查看日历、添加日程、编辑日程和删除日程的入口。
2. 日历界面:根据用户选择的年份和月份,显示对应的日历信息。
用户可以通过左右滑动切换月份。
java课程设计_简单日历程序

课程设计题目2. 题目说明通过编写一个基于JAVA的应用系统综合实例,自定义一个日历组件显示日期和时间并进行适当的功能扩充,实践Java语言编程技术。
3. 系统设计2.1 设计目标一个完整的程序应具有以下功能:1)显示当月日历、当前日期、当前时间;2)可查寻任意月以及任意年的日历;3)使用图形化界面能够弹出对话框;5)正常退出程序。
2.2 设计思想设计一个类用来构成日历系统的主窗口,然后编写一个框架类显示时间和提示信息。
在设计中应用了多种容器和控件。
2.3 系统模块划分图1:简易日历的程序结构图2.3.1初始化:public void init()完成界面初始化,形成一个以挂历形式显示当前日期的窗口。
2.3.2 日历描述:(1)public void updateView()改变日期后完成更新界面;(2)获取系统日期并传递日期数据而且在人工改变日期后得出当天是周几;(3)public static void main(String[] args)主函数完成系统各算法的调用并对主窗口的一些属性进行设置;2.3.3 滚动时间:将时间以文本的形式在文本框中滚动播出,并能改变滚动的速度。
4. 使用类及接口仅仅简单说明类的功能,详细资料请参看《JavaTM 2 Platform Standard Ed. 6》的电子文档,常规的接口与包则省略不屑。
//以下是日历程序块中使用的类package fancy;import java.awt.*;import java.util.*; //主要用此包中的日期和时间类import javax.swing.*;//以下是对滚动时间程序块所使用的类和接口,用到定时器类Timer、//用于监听鼠标单击(焦点改变)事件//用于响应鼠标单击(焦点改变)事件、//让用户从一个有序序列中选择一个数字或者一个对象值的单行输入字段。
//在指定时间间隔触发一个或多个 ActionEvent, 创建一个 Timer 对象,在该对象上注册一个或多个动作侦听器,以及使用 start 方法启动该计时器。
java日历课程设计详细设计

java日历课程设计详细设计一、教学目标本课程旨在通过Java编程语言实现一个简单的日历功能,让学生掌握Java基本语法、面向对象编程思想以及常用数据结构。
同时,培养学生的编程兴趣,提高解决实际问题的能力。
1.掌握Java基本语法和关键字。
2.理解面向对象编程的基本概念,如类、对象、封装、继承和多态。
3.熟悉常用数据结构,如数组、链表、栈和队列。
4.能够运用Java语法和面向对象编程思想编写简单的程序。
5.能够运用常用数据结构解决实际问题。
6.学会使用Java开发工具和调试技巧。
情感态度价值观目标:1.培养学生的编程兴趣,提高自主学习能力。
2.培养学生团队合作精神,学会与他人分享和交流。
3.培养学生解决问题的能力,培养创新思维。
二、教学内容本课程的教学内容主要包括Java基本语法、面向对象编程思想和常用数据结构。
具体安排如下:1.Java基本语法:介绍Java编程语言的基本语法,包括数据类型、运算符、控制语句等。
2.面向对象编程:讲解面向对象编程的基本概念,如类、对象、封装、继承和多态。
通过实例让学生理解并掌握这些概念。
3.常用数据结构:介绍数组、链表、栈和队列等常用数据结构,并通过实例让学生学会运用这些数据结构解决实际问题。
4.日历实现:利用所学知识,让学生动手实现一个简单的日历功能,巩固所学知识,提高解决实际问题的能力。
三、教学方法本课程采用讲授法、案例分析法和实验法等多种教学方法,以激发学生的学习兴趣和主动性。
1.讲授法:通过讲解Java基本语法、面向对象编程思想和常用数据结构,让学生掌握理论知识。
2.案例分析法:通过分析实际案例,让学生学会运用所学知识解决实际问题。
3.实验法:让学生动手实践,实现日历功能,提高学生的实际编程能力。
四、教学资源1.教材:选用权威、实用的Java编程教材,为学生提供理论知识的学习材料。
2.参考书:提供相关领域的参考书籍,丰富学生的知识体系。
3.多媒体资料:制作精美的PPT,直观展示知识点,帮助学生更好地理解。
日历记事本-JAVA课程设计

该类创建动态日历记事本的主窗口,该类含有main方法,是程序的入口程序,CalenderWindow类的成员变量中有5种重要类型的对象,CalendarPad、NotePad、Calendarlmage、Clock、CalendarMessage 对象。
2.2.2Cale nderMessage.java该类用来刻画和“日期”有关的数据。
2.2.3Cale nderPad.java该类是JPanel类的子类,所创建的对象是CalendarWindow类的重要成员之一,用来表示”日历”,即负责显示和修改Cale ndarMessage对象中的日期数据。
2.2.4Notepad.java该类是JPanel的一个子类,创建的对象表示“记事本”,提供编辑读取和保存阐述日志的功能。
2.2.5Cale ndarlmage.java该类所创建的对象是CalendarWindow类的成员之一,负责绘制图像。
2.2.6Clock.java该类创建的对象是CalendarWindow类的成员之一,负责显示时钟。
日历记事本用到的一些重要的类以及之间的关系如图1所示。
图1类之间的组合关系图 2.3功能模块此设计共有以下几个功能模块。
2.3.1年份改变选择日期保存并标记有”显示日志删除并去掉有图2流程图2.5类、方法、属性说明2.5.1CalendarWindow 类(1)成员变量•year,mo nth和day是int型数据,它们的值分别确定年份、月份和日期。
-calendarMessage是CalendarMessage对象,该对象可以处理和日期有关的数据。
-calendarPad是CalendarPad对象,该对象可以显示和日期有关的数据。
-notePad是NotePad对象,具有编辑、读取、保存和删除日志的功能。
-showYear和showMonth是JTextField 类创建的文本框,用来显示年份和月份。
-showDay数组的每个单元是JTextField类创建的用来显示日期的文本框。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
课程设计题目2. 题目说明通过编写一个基于JAVA的应用系统综合实例,自定义一个日历组件显示日期和时间并进行适当的功能扩充,实践Java语言编程技术。
3. 系统设计2.1 设计目标一个完整的程序应具有以下功能:1)显示当月日历、当前日期、当前时间;2)可查寻任意月以及任意年的日历;3)使用图形化界面能够弹出对话框;5)正常退出程序。
2.2 设计思想设计一个类用来构成日历系统的主窗口,然后编写一个框架类显示时间和提示信息。
在设计中应用了多种容器和控件。
2.3 系统模块划分图1:简易日历的程序结构图2.3.1初始化:public void init()完成界面初始化,形成一个以挂历形式显示当前日期的窗口。
2.3.2 日历描述:(1)public void updateView()改变日期后完成更新界面;(2)抽象类java.util.Calendar获取系统日期并传递日期数据而且在人工改变日期后得出当天是周几;(3)public static void main(String[] args)主函数完成系统各算法的调用并对主窗口的一些属性进行设置;2.3.3 滚动时间:将时间以文本的形式在文本框中滚动播出,并能改变滚动的速度。
4. 使用类及接口仅仅简单说明类的功能,详细资料请参看《JavaTM 2 Platform Standard Ed. 6》的电子文档,常规的接口与包则省略不屑。
//以下是日历程序块中使用的类package fancy;import java.awt.*;import java.awt.event.*;import java.util.*; //主要用此包中的日期和时间类import javax.swing.*;import javax.swing.event.*;import javax.swing.table.*;//以下是对滚动时间程序块所使用的类和接口,用到定时器类Timerimport java.awt.Color;import java.awt.FlowLayout;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.event.FocusListener;、//用于监听鼠标单击(焦点改变)事件import java.awt.event.FocusEvent;//用于响应鼠标单击(焦点改变)事件、import javax.swing.JFrame;import javax.swing.JTextField;import javax.swing.JSpinner;//让用户从一个有序序列中选择一个数字或者一个对象值的单行输入字段。
import javax.swing.JPanel;import javax.swing.Timer;//在指定时间间隔触发一个或多个 ActionEvent, 创建一个 Timer 对象,在该对象上注册一个或多个动作侦听器,以及使用 start 方法启动该计时器。
并配合事件监听器支持时间的滚动播放。
import javax.swing.event.ChangeListener;import javax.swing.event.ChangeEvent;5. 运行结果与分析图2:初始界面显示日历。
图3:点击查看时间按钮,弹出时间消息对话框。
图4:滚动显示当前时间。
6. 程序源代码/*** @(#) MyCalendar.java* @author fancy*///日历使用的类import java.awt.BorderLayout;import java.awt.Color;import ponent;import java.awt.Container;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.util.Calendar;import javax.swing.JApplet;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JSpinner;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.ListSelectionModel;import javax.swing.Timer;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.table.AbstractTableModel;import javax.swing.table.TableCellRenderer;import javax.swing.table.TableModel;//日历public class MyCalendar extends JApplet{public static final String WEEK_SUN = "SUN";public static final String WEEK_MON = "MON";public static final String WEEK_TUE = "TUE";public static final String WEEK_WED = "WED";public static final String WEEK_THU = "THU";public static final String WEEK_FRI = "FRI";public static final String WEEK_SAT = "SAT";public static final Color background = Color.yellow;public static final Color foreground = Color.black;public static final Color headerBackground = Color.blue; public static final Color headerForeground = Color.white; public static final Color selectedBackground = Color.blue;public static final Color selectedForeground = Color.white;private JPanel cPane;private JLabel yearsLabel;private JSpinner yearsSpinner;private JLabel monthsLabel;private JComboBox monthsComboBox;private JTable daysTable;private AbstractTableModel daysModel;private Calendar calendar;private JButton button1;public MyCalendar() {cPane = (JPanel) getContentPane();}public void init() {cPane.setLayout(new BorderLayout());calendar = Calendar.getInstance();calendar = Calendar.getInstance();JButton button1=new JButton(" 单击此处查看时间 ");button1.setBounds(10,10,10,10);cPane.add(button1,BorderLayout.SOUTH);button1.addActionListener(new java.awt.event.ActionListener(){public void actionPerformed(ActionEvent e) {RollbyJFrame myrili=new RollbyJFrame();JOptionPane.showMessageDialog(null, "您点击了"+e.getActionCommand().toString()+"按钮");}});yearsLabel = new JLabel("Year: ");yearsSpinner = new JSpinner();yearsSpinner.setEditor(new JSpinner.NumberEditor(yearsSpinner, "0000"));yearsSpinner.setValue(newInteger(calendar.get(Calendar.YEAR)));yearsSpinner.addChangeListener(new ChangeListener() {public void stateChanged(ChangeEvent changeEvent) {int day = calendar.get(Calendar.DAY_OF_MONTH);calendar.set(Calendar.DAY_OF_MONTH, 1);calendar.set(Calendar.YEAR, ((Integer) yearsSpinner.getValue()).intValue());int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);calendar.set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);updateView();}});JPanel yearMonthPanel = new JPanel();cPane.add(yearMonthPanel, BorderLayout.NORTH);yearMonthPanel.setLayout(new BorderLayout());yearMonthPanel.add(new JPanel(), BorderLayout.CENTER);JPanel yearPanel = new JPanel();yearMonthPanel.add(yearPanel, BorderLayout.WEST);yearPanel.setLayout(new BorderLayout());yearPanel.add(yearsLabel, BorderLayout.WEST);yearPanel.add(yearsSpinner, BorderLayout.CENTER);monthsLabel = new JLabel("Month: ");monthsComboBox = new JComboBox();for (int i = 1; i <= 12; i++) {monthsComboBox.addItem(new Integer(i));}monthsComboBox.setSelectedIndex(calendar.get(Calendar.MONTH)); monthsComboBox.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent actionEvent) { int day = calendar.get(Calendar.DAY_OF_MONTH);calendar.set(Calendar.DAY_OF_MONTH, 1);calendar.set(Calendar.MONTH,monthsComboBox.getSelectedIndex());int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);calendar.set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);updateView();}});JPanel monthPanel = new JPanel();yearMonthPanel.add(monthPanel, BorderLayout.EAST);monthPanel.setLayout(new BorderLayout());monthPanel.add(monthsLabel, BorderLayout.WEST);monthPanel.add(monthsComboBox, BorderLayout.CENTER);daysModel = new AbstractTableModel() {public int getRowCount() {return 9;}public int getColumnCount() {return 7;}public Object getValueAt(int row, int column) {if (row == 0) {return getHeader(column);}row--;Calendar calendar = (Calendar) MyCalendar.this.calendar.clone();calendar.set(Calendar.DAY_OF_MONTH, 1);int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1;int index = row * 7 + column;int dayIndex = index - moreDayCount + 1;if (index < moreDayCount || dayIndex > dayCount) { return null;} else {return new Integer(dayIndex);}}};daysTable = new CalendarTable(daysModel, calendar);daysTable.setCellSelectionEnabled(true);daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);daysTable.setDefaultRenderer(daysTable.getColumnClass(0), new TableCellRenderer() {public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,boolean hasFocus, int row, int column) {String text = (value == null) ? "" : value.toString(); JLabel cell = new JLabel(text);cell.setOpaque(true);if (row == 0) {cell.setForeground(headerForeground);cell.setBackground(headerBackground);} else {if (isSelected) {cell.setForeground(selectedForeground);cell.setBackground(selectedBackground);} else {cell.setForeground(foreground);cell.setBackground(background);}}return cell;}});updateView();cPane.add(daysTable, BorderLayout.CENTER);}public static String getHeader(int index) {switch (index) {case 0:return WEEK_SUN;case 1:return WEEK_MON;case 2:return WEEK_TUE;case 3:return WEEK_WED;case 4:return WEEK_THU;case 5:return WEEK_FRI;case 6:return WEEK_SAT;default:return null;}}public void updateView() {daysModel.fireTableDataChanged();daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH),calendar.get(Calendar.WEEK_OF_MONTH));daysTable.setColumnSelectionInterval(calendar.get(Calendar.DAY_OF_WEEK) - 1,calendar.get(Calendar.DAY_OF_WEEK) - 1);}public static class CalendarTable extends JTable {private Calendar calendar;public CalendarTable(TableModel model, Calendar calendar) {super(model);this.calendar = calendar;}public void changeSelection(int row, int column, boolean toggle, boolean extend) {super.changeSelection(row, column, toggle, extend);if (row == 0) {return;}Object obj = getValueAt(row, column);if (obj != null) {calendar.set(Calendar.DAY_OF_MONTH,((Integer)obj).intValue());}}}public static void main(String[] args) {JFrame frame = new JFrame("简易时间日历");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);MyCalendar myCalendar = new MyCalendar();myCalendar.init();frame.getContentPane().add(myCalendar);frame.setLocation(330,80);frame.setSize(360, 212);frame.setVisible(true);}//滚动字public static class RollbyJFrame extends JFrameimplements ActionListener, FocusListener, javax.swing.event.ChangeListener{private JTextField text;private JSpinner spinner;private Timer timer;private JButton button;public RollbyJFrame(){super("滚动时间");this.setSize(360,100);this.setBackground(java.awt.Color.lightGray);this.setLocation(700,120);Container c=getContentPane();JButton button=new JButton("修改速度");this.add(button,"East");button.addActionListener(this);Calendar now = Calendar.getInstance();int hour=now.get(Calendar.HOUR);int minute=now.get(Calendar.MINUTE);int year=now.get(Calendar.YEAR);int month=now.get(Calendar.MONTH);int day=now.get(Calendar.DAY_OF_MONTH);text = new JTextField(" Hello 当前时间是:"+hour+":"+minute+" "+year+"/"+month+"/"+day);this.add(text,"Center");text.addFocusListener(this); //注册焦点事件监听器timer = new Timer(136,this);timer.start();JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));this.add(panel,"South");spinner = new JSpinner();spinner.setValue(timer.getDelay());panel.add(spinner);spinner.addChangeListener(this);this.setVisible(true);}public void focusGained(FocusEvent e) //获得焦点时 {if (e.getSource()==text){timer.stop();}}public void focusLost(FocusEvent e) //失去焦点时 {if (e.getSource()==text){timer.restart();}}public void stateChanged(ChangeEvent e){if (e.getSource()==spinner){timer.setDelay(new Integer(""+spinner.getValue())); //设置延时的时间间隔}}public void actionPerformed(ActionEvent e) //定时器定时执行事件{if (e.getSource()==button);else{String temp = text.getText();temp = temp.substring(1) + temp.substring(0,1);text.setText(temp);}}public void buttondown(ActionEvent e) //单击事件 {if (e.getSource()==button){} ;}}}。