Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1263

Re: pls hlep, can't get output

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From markspace <-@.>
Newsgroups comp.lang.java.help
Subject Re: pls hlep, can't get output
Date Mon, 17 Oct 2011 22:53:32 -0700
Organization A noiseless patient Spider
Lines 111
Message-ID <j7j48v$fk2$1@dont-email.me> (permalink)
References <16b2abac-4141-4153-9f24-05770f056b97@r2g2000prh.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 18 Oct 2011 05:53:35 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="16002"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/h+r6o90IqnMPJrtGs/Np1a4aaCuxbBE="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1
In-Reply-To <16b2abac-4141-4153-9f24-05770f056b97@r2g2000prh.googlegroups.com>
Cancel-Lock sha1:HwA0UOM61F/n7ii8jI6CYTSBCQM=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.help:1263

Show key headers only | View raw


On 10/17/2011 9:00 PM, kk wrote:
> This is program.But problem is that there is no output.I faded to
> catch the problem.


This seems to work.  To use a Timer, you have to set up the Timer with a 
1000 second delay, start it, and then ask the component be redrawn by 
calling its repaint() method.  That's all I did, besides removing the 
loop.  Read carefully and make sure you understand.

Oh, and your AWT Canvas is thread safe, but the JFrame is not.  Please 
read up on multithreading in Swing.


package quicktest;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Calendar;


class ClockDemo extends Canvas
{

    Timer timer = new Timer( 1000, new TimerTick() );

    int xmou = 200; //set the center of circle
    int ymou = 200; //set the center of circle
    double theta = -0.1047; //theta for second's hand
    int x = xmou;  //x position of Second's hand
    int y = ymou;  //y position of second's hand
    int p, b;
    int h;
    boolean flag = true;
    /*ClockDemo(){
    //super();
    setSize(500,500);
    setBackground(Color.PINK);
    setVisible(true);
    }*/

    public ClockDemo()
    {
       timer.start();
    }

    @Override
    public void paint( Graphics g )
    {
       DrawLine( g, xmou, ymou, x, y );
    }

    public void DrawLine( Graphics g, int startX, int startY, int endX, 
int endY )
    {
       h = 80;
       System.out.println( "h:" + h );
       //g.drawLine(200,200,165,248);
       g.drawLine( startX, startY, endX, endY );
       newpoint();
       //this.repaint(startX,startY,endX,endY);
    }

    public void newpoint()
    {
       //creating a Calendarvariable for getting current time
       Calendar now = Calendar.getInstance();

       //for second hand
       //h=60;
       x = xmou;
       y = ymou;
       theta = -0.1047;
       theta = theta * now.get( Calendar.SECOND );
       System.out.println( "theta:" + theta );
       p = (int) ( Math.sin( theta ) * h );
       b = (int) ( Math.cos( theta ) * h );
       System.out.println( "p:" + p + " " + "b:" + b );
       x = x - p;
       y = y - b;

    }

    private class TimerTick implements ActionListener {
       public void actionPerformed( ActionEvent e ) {
          repaint();
       }
    }
}


public class CanvasTest
{
    public static void main( String... arg )
    {
       final ClockDemo comp = new ClockDemo();
       SwingUtilities.invokeLater( new Runnable() {
          public void run() {
             JFrame jf = new JFrame( "Clock Demo" );
             jf.add( comp );
             jf.setSize( 500, 500 );
             jf.setVisible( true );
             jf.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
          }
       } );
    }
}

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

pls hlep, can't get output kk <kcool.99x@gmail.com> - 2011-10-17 21:00 -0700
  Re: pls hlep, can't get output markspace <-@.> - 2011-10-17 22:03 -0700
  Re: pls hlep, can't get output markspace <-@.> - 2011-10-17 22:53 -0700
  Re: pls hlep, can't get output Roedy Green <see_website@mindprod.com.invalid> - 2011-10-19 15:22 -0700

csiph-web