解决方案 »

  1.   

    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;
        Clock clock; 
        JButton nextYear,previousYear,nextMonth,previousMonth;
        JButton saveDailyRecord,deleteDailyRecord,readDailyRecord;
        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();  //给有日志的号码做标记,见后面的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);
           showYear.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);
           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>12) month=1;
              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);
        }
        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){ //见后面的isHaveDailyRecord()方法
                      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 static void main(String args[]){
           new CalendarWindow();
        }
    }  
    这是我在csdn上找到的闹铃java代码,不知道如何添加
      

  2.   

    3l代码打错了。package Clock;
    import java.awt.*; 
    import java.awt.event.*; 
    import java.util.*; 
    import javax.swing.event.*; 
    import javax.swing.*; 
    import javax.swing.Timer; 
    /**  * <p>Title: 时钟</p>  * <p>Description: 本实例演示使用图形绘制一个图形时钟</p>  * <p>Copyright: Copyright  2003</p>  
     * * <p>Filename: Clock.java</p>  * @version 1.0 */
    public class Clock extends JFrame implements ActionListener{    
    Timer timer;    
    int x,y,old_X,old_Y, r,x0,y0,w,h,ang;    
    int sdo,mdo,hdo,old_M,old_H;    
    TimeZone tz =TimeZone.getTimeZone("JST");    
    final double RAD=Math.PI/180.0;  
    public static void main(String[] args){    
    Clock cl = new Clock();  }
    /** *<br>方法说明:实现ActionListener类必须过载的方法 *<br>输入参数: *<br>返回类型: */  
    public void actionPerformed(ActionEvent e) {            
    timer.restart();    
    }
    /** *<br>方法说明:构造器,显示窗体,并添加了一个秒表 *<br>输入参数: *<br>返回类型: */  
    Clock(){    super("Clock");    
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);    
    setBackground(new Color(0,0,192));    setSize(300,300);    
    show();    int delay = 1000;   
    //窗体添加事件监听,监听秒表的触发  
    ActionListener taskPerformer = new ActionListener() {     
    public void actionPerformed(ActionEvent evt) {        
    repaint();      
    }    };    
    new Timer(delay, taskPerformer).start();  }
    /** *<br>方法说明:绘制图形 *<br>输入参数: *<br>返回类型: */  
    public void paint( Graphics g ) {    
    Insets insets = getInsets();     
         int L0 = (insets.left)/2, T0 = (insets.top)/2;     
         int hh,mm,ss;     
         String st;    
         h=getSize().height;     
         //绘制圆形     
         g.setColor(Color.white);    
         g.drawOval(L0+30,T0+30,h-60,h-60);     
         g.drawOval(L0+32,T0+32,h-64,h-64);     
         r=h/2-30;     
         x0=30+r-5+L0;     
         y0=30+r-5-T0;     
         ang=60;     
         for (int i=1; i<=12; i++) {        
          x=(int)((r+10)*Math.cos(RAD*ang)+x0);        
          y=(int)((r+10)*Math.sin(RAD*ang)+y0);        
          g.drawString(""+i,x,h-y);        
          ang-=30;     
          }     
         x0=30+r+L0; y0=30+r+T0;     
         //获取时间     
         Calendar now=Calendar.getInstance();     
         hh=now.get(Calendar.HOUR_OF_DAY);//小时    
         mm=now.get(Calendar.MINUTE);//分钟   
         ss=now.get(Calendar.SECOND);// 秒     
         g.setColor(Color.pink);     
         g.fillRect(L0,T0,60,28);//填充的矩形   
         g.setColor(Color.blue);     
         if (hh < 10) st="0"+hh;     
         else st=""+hh;     
         if (mm < 10) st=st+":0"+mm; else st=st+":"+mm;     
         if (ss < 10) st=st+":0"+ss; else st=st+":"+ss;     
         g.drawString(st,L0,T0+25);     
         //计算时间和图形的关系     
         sdo=90-ss*6;     
         mdo=90-mm*6;     
         hdo=90-hh*30-mm/2;     
         //擦除秒针     
         if (old_X > 0) {        
          g.setColor(getBackground());       
          g.drawLine(x0,y0,old_X,(h-old_Y));     
          } else {       
                 old_M=mdo;        
                 old_H=hdo;     }     
         //绘制秒针     
         g.setColor(Color.yellow);     
         x=(int)((r-8)*Math.cos(RAD*sdo)+x0);    
         y=(int)((r-8)*Math.sin(RAD*sdo)+y0)-2*T0;     
         g.drawLine(x0,y0,x,(h-y));     
         old_X=x;     
         old_Y=y;     
         //擦除分针和时针     
         if (mdo != old_M) {       
          line(g,old_M,(int)(r*0.7),getBackground());       
          old_M=mdo;     }     
         if (hdo != old_H) {      
               line(g,old_H,(int)(r*0.5),getBackground());      
               old_H=hdo;     }     
         //绘制分针     
         line(g,mdo,(int)(r*0.7),Color.green);     
         //绘制时针     
         line(g,hdo,(int)(r*0.5),Color.red);  } 
         // end paint
         /** *<br>方法说明:绘制线,用于绘制时针和分针 *<br>输入参数: 
         *<br>返回类型: */   
           public void line(Graphics g, int t, int n, Color c) {      
            int [] xp = new int[4];      
            int [] yp = new int[4];     
            xp[0]=x0;      
            yp[0]=y0;      
            xp[1]=  (int)((n-10)*Math.cos(RAD*(t-4))+x0);      
            yp[1]=h-(int)((n-10)*Math.sin(RAD*(t-4))+y0);      
            xp[2]=  (int)( n    *Math.cos(RAD* t   )+x0);      
            yp[2]=h-(int)( n    *Math.sin(RAD* t   )+y0);      
            xp[3]=  (int)((n-10)*Math.cos(RAD*(t+4))+x0);      
            yp[3]=h-(int)((n-10)*Math.sin(RAD*(t+4))+y0);      
            g.setColor(Color.red);      
            g.fillPolygon(xp,yp,4);   } }
    这个是找到的闹铃
      

  3.   

    不是,我是学英语的。不知道为什么要学java
    我也不想学,最近期末有个课程设计
    你说我这种专门学文的怎么能弄懂java啊,所以想找人帮忙啊
      

  4.   

    不是,我是学英语的。不知道为什么要学java
    我也不想学,最近期末有个课程设计
    你说我这种专门学文的怎么能弄懂java啊,所以想找人帮忙啊
    好的吧,能够理解,首先你要学会新建java工程,或者java类,而且你要有eclipse myEclipse 20XX之类的开发工具(对于工程来说很方便),再来你就要知道 public 类里面有且只有一个Public static void main(String[] args)方法,并且每一个.java文件中只能有一个public的类,然后就是 public 类的类名必须与.java的名字相同,如果你是使用比较成熟的开发工具,比如说上面那两种,画红线的地方就是错的地方,你把鼠标放在红线上,就能看到错误,你是英语系的,应该能看得懂错误。例如:如果是因为没有引用相关的包,那么你就可以看到import + 相应的包名的选项(包名一般来说是java.*.*)的形式,如果是你工程里面的包,就有可能是另一种命名形式,你注意观察一下你的工程。