Results 1 to 2 of 2

Thread: how to buffer?

  1. #1
    brycepower1 is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Smile how to buffer?

    hey guys, i hit a wall, this program works perfectly however the program needs to be refreshed every second and i cant figure out how to fix this without it having an annoying refresh flicker

    if you have any ideas like a buffer or using swing method please help me out because i have no idea how to make a buffer or how to use the swing method

    thanks

    Java Code:
    import java.util.Date;
    import java.util.Locale;
    import java.text.DateFormat;
    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.text.SimpleDateFormat;
    import java.io.*;
    import java.util.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.awt.*;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.Dimension;
    import java.awt.Graphics2D;
    import java.util.Random;
    import java.lang.Math.*;
    
    
    
    public class clocks extends Applet{
      public static final int IDEAL_HEIGHT = 500;
    public static final int IDEAL_WIDTH = 500;
    
        class DoubleBufferedCanvas extends Canvas {
            
           /* public void update(Graphics g) {
                Graphics offgc;
                Image offscreen = null;
                Dimension d = size();
                
                // create the offscreen buffer and associated Graphics
                offscreen = createImage(d.width, d.height);
                offgc = offscreen.getGraphics();
                // clear the exposed area
                offgc.setColor(getBackground());
                offgc.fillRect(0, 0, d.width, d.height);
                offgc.setColor(getForeground());
                // do normal redraw
                paint(offgc);
                // transfer offscreen to window
                g.drawImage(offscreen, 0, 0, this);*/
            //}
        }
        int xminute;
        int yminute;
        int xsecond;
        int ysecond;
        int xhour;
        int yhour;
        String day;
        String month;
        String year;
        String halfday;
        int x = 1;
        public void paint(Graphics g){
            {
                {
                    Font font = new Font("Serif", Font.PLAIN, 14);
                    g.setFont(font);
                    Date dateNow = new Date ();
                    SimpleDateFormat dateformatDD = new SimpleDateFormat("dd");
                    SimpleDateFormat dateformatMM = new SimpleDateFormat("MM");
                    SimpleDateFormat dateformatYYYY = new SimpleDateFormat("yyyy");
                    SimpleDateFormat dateformathh = new SimpleDateFormat("hh");
                    SimpleDateFormat dateformatmm = new SimpleDateFormat("mm");
                    SimpleDateFormat dateformatss = new SimpleDateFormat("ss");
                    SimpleDateFormat dateformataa = new SimpleDateFormat("aa");
                    String day = new String( dateformatDD.format( dateNow ) );
                    String month = new String( dateformatMM.format( dateNow ) );
                    String year = new String( dateformatYYYY.format( dateNow ) );
                    String hou = new String( dateformathh.format( dateNow ) );
                    String minut = new String( dateformatmm.format( dateNow ) );
                    String secon = new String( dateformatss.format( dateNow ) );
                    String halfday = new String( dateformataa.format( dateNow ) );
                    String time = (month+"/"+day+"/"+year+"  "+hou+":"+minut+":"+secon+" "+halfday);    
                    g.setColor(Color.BLACK);
                    g.fillOval(100,100,300,300);  
                    g.setColor(Color.LIGHT_GRAY);
                    g.fillOval(110,110,280,280);  
                    g.setColor(Color.WHITE);   
                    g.fillOval(130,130,240,240); 
                    g.setColor(Color.BLACK);   
                    g.drawOval(130,130,240,240);  
                    g.fillOval(245,245,10,10);
                    g.setColor(Color.WHITE);
                    g.fillOval(241,111,18,18); //12
                    g.fillOval(177,128,18,18);//11
                    g.fillOval(128,177,18,18);//10
                    g.fillOval(111,241,18,18);//9
                    g.fillOval(128,305,18,18);//8
                    g.fillOval(177,354,18,18);//7
                    g.fillOval(241,371,18,18);//6
                    g.fillOval(305,354,18,18);//5
                    g.fillOval(354,305,18,18);//4
                    g.fillOval(371,241,18,18);//3
                    g.fillOval(354,177,18,18);//2
                    g.fillOval(305,128,18,18);//1 
                    g.setColor(Color.BLACK);                
                    g.drawOval(241,111,18,18); //12
                    g.drawOval(177,128,18,18);//11
                    g.drawOval(128,177,18,18);//10
                    g.drawOval(111,241,18,18);//9
                    g.drawOval(128,305,18,18);//8
                    g.drawOval(177,354,18,18);//7
                    g.drawOval(241,371,18,18);//6
                    g.drawOval(305,354,18,18);//5
                    g.drawOval(354,305,18,18);//4
                    g.drawOval(371,241,18,18);//3
                    g.drawOval(354,177,18,18);//2
                    g.drawOval(305,128,18,18);//1
                    g.drawString ("12", 243, 125);
                    g.drawString ("3", 377, 255);
                    g.drawString ("6", 247, 385);
                    g.drawString ("9", 117, 255);
                    g.drawString ("1", 312, 142);
                    g.drawString ("2", 360, 191);
                    g.drawString ("4", 360, 319);
                    g.drawString ("5", 311, 368);
                    g.drawString ("7", 183, 369);
                    g.drawString ("8", 134, 320);
                    g.drawString ("10", 130, 191);
                    g.drawString ("11", 180, 143);
                    font = new Font("Serif", Font.PLAIN, 36);
                    g.setFont(font); 
                    g.drawString (time, 75, 450); 
                    
                    int second = Integer.parseInt(secon)+0;
                    int minute = Integer.parseInt(minut)+0;                 
                    int hour = Integer.parseInt(hou)*60+minute+0;
                    {
                        xsecond = (int)(250+(110*(Math.sin(Math.toRadians(second*6)))));
                        ysecond = (int)(250+(-110*(Math.cos(Math.toRadians(second*6)))));
                    }
                    {
                        xminute = (int)(250+(95*(Math.sin(Math.toRadians(minute*6)))));
                        yminute = (int)(250+(-95*(Math.cos(Math.toRadians(minute*6)))));
                    }
                    {
                        xhour = (int)(250+(70*(Math.sin(Math.toRadians(hour*0.5)))));
                        yhour = (int)(250+(-70*(Math.cos(Math.toRadians(hour*0.5)))));
                    }
                    g.drawLine(250,250,xhour,yhour);
                    g.drawLine(250,250,xminute,yminute);
                    g.drawLine(250,250,xsecond,ysecond);
                }
            }
        }
    }
    Last edited by brycepower1; 05-10-2011 at 09:34 PM. Reason: refrasing

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. Please help with Double Buffer
    By DouboC@gmail.com in forum Java Applets
    Replies: 2
    Last Post: 01-10-2011, 02:57 AM
  2. AudioSound into a buffer
    By phil128 in forum Advanced Java
    Replies: 0
    Last Post: 12-13-2010, 01:03 PM
  3. Buffer Example help.
    By bert682 in forum Threads and Synchronization
    Replies: 0
    Last Post: 11-27-2009, 09:26 AM
  4. Buffer
    By QPRocky in forum Networking
    Replies: 2
    Last Post: 02-02-2009, 03:54 PM
  5. how to set the value of BUFFER SIZE
    By oregon in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 03:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •