Page 3 of 3 FirstFirst 123
Results 41 to 56 of 56

Thread: Clock Troubles

  1. #41
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    If you put that at the end of the paint-method you create an infinite loop, eventually leading to a breakdown (can't quite remember the name of the error). It's interesting that there isn't an after-image of the hands of the clock, as that was one of the effects I was expecting. It could be because of all those drawOval that clears the hands before you paint them again though. Try drawing a black rectangle over the time right before you print it out and the afterimages should vanish from there too.

    EDIT: Technically it's an infinite recursion and not an infinite loop, I suppose.

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

    Default

    interesting i actually have it so it will make a filled white circle for the clock i think you might be right about that, let me try it with the time quick

    alright so the time problem is fixed... however the flickering problem is still there
    Last edited by brycepower1; 05-10-2011 at 11:26 PM. Reason: update

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

    Default

    know anything about buffers or swing methods? i heard from some people that they might fix this

  4. #44
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    Buffers can also fix flickering, yes, but still require a new update-class. In essence, what you do with a buffer is that you create an image and paints on that one instead of painting directly to the applet. When you're done drawing to the image, you draw that image in its entirety to the applet. This will solve all cases of after-image effects (and will make the graphics appear instantaneously in the applet, whereas drawing directly to the applet could result in visible delays if you draw a lot).

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

    Default

    hmm well i have to go for alittle while

    if you have any more ideas on how to make an update class without flickers please let me know =)

  6. #46
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    That update-method should do the trick when it comes to removing flicker... You placed it in the same class as your paint-method, yes? All the ways to remove flicker are based on that update-method (doublebuffering requires it too), although others might have other suggestions?

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

    Default

    still having problems.... this is how i have it set up
    with this configuration their is no image being displayed
    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 {
        }
        int xminute;
        int yminute;
        int xsecond;
        int ysecond;
        int xsecondtip;
        int ysecondtip;
        int xhour;
        int yhour;
        String day;
        String month;
        String year;
        String hour;
        String minute;
        String second;
        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); 
                    
                    if (isShowing()) {
                        paint(g);
                    }
                    
                    g.setColor(Color.WHITE);
                    g.fillRect(0,0,500,500);
                    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.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)))));
                    }
                    {
                        xsecondtip = (int)(250+(-20*(Math.sin(Math.toRadians(second*6)))));
                        ysecondtip = (int)(250+(20*(Math.cos(Math.toRadians(second*6)))));
                    }
                    g.drawLine(250,250,xhour,yhour);
                    g.drawLine(250,250,xminute,yminute);
                    g.drawLine(250,250,xsecond,ysecond);
                    g.drawLine(250,250,xsecondtip,ysecondtip);
                    g.setColor(Color.WHITE);
                    g.fillOval(245,245,10,10);
                    g.setColor(Color.BLACK);  
                    g.drawOval(245,245,10,10);    
                }
            }
        }
    }

  8. #48
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    With that code, there's no surprise nothing is shown. Why do you have a call to paint(g) in your paint method?

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

    Default

    isn't that were i was supposed to put the line of code you gave me?

    were do i need to move it then?

  10. #50
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    Put this method in your class:
    Java Code:
        public void update(Graphics g) {
            if (isShowing()) {
                paint(g);
            }
        }
    Remove the call to paint (and the if(isShowing)) in the paint-method, and leave the paint-method be. That one doesn't need to be changed anymore.

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

    Default

    i placed it at the beginning like so:
    Java Code:
    
    
    
    public class clocks extends Applet{
    
        public void update(Graphics g) {
            if (isShowing()) {
                paint(g);
            }
        }
    but the page is not refreshing at all maybe it goes after the other class?

  12. #52
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    Shouldn't matter where it goes. You removed the
    Java Code:
                    if (isShowing()) {
                        paint(g);
                    }
    from paint as well?

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

    Default

    yes i removed that line of code

  14. #54
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    Then I see no reason for why it shouldn't work. Try commenting out the update-method and see if it starts showing then?

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

    Default

    yeah it shows then, maybe we are going about this the wrong way, the number will need to be erased to be replaced so... do you know if their is a way to make repaint or update only work on individual classes? and perhaps how to slow down the refresh?

    hopefully then i will not need to worry about buffering then

    perhaps repaint(long tm); but it is different than repaint(); and im not quite sure how to implement it into my code i keep on getting a .class expected error
    Last edited by brycepower1; 05-12-2011 at 08:18 AM.

  16. #56
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    repaint(long tm) repaints the object after a delay, so that one wouldn't do much, unfortunately. Try removing the isShowing-check to see if that one messes it up. It shouldn't, but it's the only idea I've got right now.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. 24 hour clock to 12 hour clock project.
    By bs3ac in forum New To Java
    Replies: 4
    Last Post: 01-08-2013, 10:10 AM
  2. Integer troubles
    By Tb0h in forum New To Java
    Replies: 11
    Last Post: 08-13-2009, 04:56 PM
  3. Gif decoding/LZW troubles
    By hellochar in forum Advanced Java
    Replies: 2
    Last Post: 07-14-2009, 11:26 PM
  4. Image troubles
    By Theodoreb in forum New To Java
    Replies: 24
    Last Post: 07-14-2009, 12:41 AM
  5. subclass troubles
    By xf021209 in forum New To Java
    Replies: 12
    Last Post: 04-20-2009, 11:46 PM

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
  •