Results 1 to 2 of 2
  1. #1
    jaidod is offline Member
    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0

    Question Help please in digital clock

    well i create this much but i have problem with creating functions to work these elements to show the time. can anyone help with me. I just start doing java. i try to use if else code to work the time but i'm still confusing in that part.Thank You. Here is my code.

    import java.awt.*;
    import java.awt.event.*;
    import java.util.Date;
    import javax.swing.*;

    public class simplegraphics extends JFrame
    {

    int x=150,y=100,xdir=1,ydir=2 ;
    public simplegraphics()
    {
    boolean initial=true;
    setVisible(true);
    setSize(300,200);
    }
    public void paint(Graphics g)
    {

    int h = getHours();
    int m = getMinutes();

    g.translate(0,25);//move origin down to compromise for the title bar

    g.setColor(Color.white); //background color
    g.fillRect(0,0,getWidth(),getHeight());//background
    g.setColor(Color.white); //clears the old ball
    g.fillOval(x,y,20,20);


    /* g.setColor(Color.red); //draws a new ball
    g.drawLine(10,10,60,10);
    g.drawLine(10,10,10,40);
    g.drawLine(60,10,60,40);
    g.drawLine(10,40,60,40);
    g.drawLine(10,40,10,70);
    g.drawLine(10,70,60,70);
    g.drawLine(60,10,60,70);*/


    g.setColor(Color.red);
    draw_one(0, g);

    // draw_two(60, g);
    draw_zero(60, g);
    // draw_three (60,g);
    //draw_four (60,g);
    /* g.setColor(Color.red);
    g.drawLine(70,10,120,10);
    g.drawLine(70,10,70,40);
    g.drawLine(120,10,120,40);
    g.drawLine(70,40,120,40);
    g.drawLine(70,10,70,70);
    g.drawLine(70,70,120,70);
    g.drawLine(120,40,120,70);*/



    //draw_zero(120, g);
    //draw_five (120,g);
    //draw_six (120,g);
    //draw_zero (120,g);
    draw_one (120,g);
    /* g.setColor(Color.red);
    g.drawLine(130,10,180,10);
    g.drawLine(130,10,130,40);
    g.drawLine(180,10,180,40);
    g.drawLine(130,40,180,40);
    g.drawLine(130,10,130,70);
    g.drawLine(130,70,180,70);
    g.drawLine(180,40,180,70);*/



    // draw_eight(180, g);
    draw_seven(180, g);
    // draw_nine (180, g);
    /*
    g.setColor(Color.red);
    g.drawLine(190,10,240,10);
    g.drawLine(190,10,190,40);
    g.drawLine(240,10,240,40);
    g.drawLine(190,40,240,40);
    g.drawLine(190,10,190,70);
    g.drawLine(190,70,240,70);
    g.drawLine(240,40,240,70); */
    }

    public void draw_zero(int x, Graphics g)
    {
    g.drawLine(x+10,10,x+60,10); // Top
    g.drawLine(x+10,70,x+60,70); // Bottom

    g.drawLine(x+10,10,x+10,40); // Top left
    g.drawLine(x+60,10,x+60,40); // Top right

    g.drawLine(x+10,40,x+10,70); // Bottom left
    g.drawLine(x+60,40,x+60,70); // Bottom right
    }

    public void draw_one(int x, Graphics g)
    {
    g.drawLine(x+60,10,x+60,40); // Top right
    g.drawLine(x+60,40,x+60,70); // Bottom right
    }


    public void draw_two(int x, Graphics g)
    {
    g.drawLine(x+10,10,x+60,10); // Top
    g.drawLine(x+10,40,x+60,40); // Middle
    g.drawLine(x+10,70,x+60,70); // Bottom
    g.drawLine(x+60,10,x+60,40); // Top right
    g.drawLine(x+10,40,x+10,70); // Bottom left
    }

    public void draw_three(int x, Graphics g)
    {
    g.drawLine(x+10,10,x+60,10); // Top
    g.drawLine(x+10,40,x+60,40); // Middle
    g.drawLine(x+10,70,x+60,70); // Bottom
    g.drawLine(x+60,10,x+60,40); // Top right
    g.drawLine(x+60,40,x+60,70); // Bottom right
    }

    public void draw_four(int x, Graphics g)
    {

    g.drawLine(x+10,40,x+60,40); // Middle
    g.drawLine(x+10,10,x+10,40); // Top left
    g.drawLine(x+60,10,x+60,40); // Top right
    g.drawLine(x+60,40,x+60,70); // Bottom right
    }

    public void draw_five(int x, Graphics g)
    {
    g.drawLine(x+10,10,x+60,10); // Top
    g.drawLine(x+10,40,x+60,40); // Middle
    g.drawLine(x+10,70,x+60,70); // Bottom
    g.drawLine(x+10,10,x+10,40); // Top left
    g.drawLine(x+60,40,x+60,70); // Bottom right
    }

    public void draw_six(int x, Graphics g)
    {

    g.drawLine(x+10,10,x+60,10); // Top
    g.drawLine(x+10,40,x+60,40); // Middle
    g.drawLine(x+10,70,x+60,70); // Bottom
    g.drawLine(x+10,10,x+10,40); // Top left
    g.drawLine(x+10,40,x+10,70); // Bottom left
    g.drawLine(x+60,40,x+60,70); // Bottom right
    }

    public void draw_seven(int x, Graphics g)
    {
    g.drawLine(x+10,10,x+60,10); // Top
    g.drawLine(x+60,10,x+60,40); // Top right
    g.drawLine(x+60,40,x+60,70); // Bottom righ

    }

    public void draw_eight(int x, Graphics g)
    {
    g.drawLine(x+10,10,x+60,10); // Top
    g.drawLine(x+10,40,x+60,40); // Middle
    g.drawLine(x+10,70,x+60,70); // Bottom
    g.drawLine(x+10,10,x+10,40); // Top left
    g.drawLine(x+60,10,x+60,40); // Top right
    g.drawLine(x+10,40,x+10,70); // Bottom left
    g.drawLine(x+60,40,x+60,70); // Bottom right
    }

    public void draw_nine(int x, Graphics g)
    {

    g.drawLine(x+10,10,x+60,10); // Top
    g.drawLine(x+10,40,x+60,40); // Middle
    g.drawLine(x+10,70,x+60,70); // Bottom
    g.drawLine(x+10,10,x+10,40); // Top left
    g.drawLine(x+60,10,x+60,40); // Top right
    g.drawLine(x+60,40,x+60,70); // Bottom right
    }
    // to get hour
    public void setHours( int h ) throws Exception
    {
    if ( h >= 0 && h < 24 )
    hour = h;
    else
    throw( new Exception() );
    }

    // to get minutes
    public void setMinutes( int m ) throws Exception

    {
    if ( m >= 0 && m < 60 )
    minutes = m;
    else
    throw( new Exception() );
    }


    public static void main(String args[])
    {
    simplegraphics SG = new simplegraphics();
    int step=0;
    while(true)
    {
    if(step%500000==0)//the number 500000 doesn't matter but a smaller number will make the
    //animation, not the ball, speed up.
    {
    SG.repaint();
    }
    step++;
    }
    }
    }

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    10

    Default

    You're not telling us where should be the problem!!!

    How can our experts here help you if you don't even ask a specific question about your code?

    Be specific...

    kind regards,
    sukatoa

Similar Threads

  1. digital sign libraries
    By Shuru in forum Advanced Java
    Replies: 4
    Last Post: 11-07-2008, 09:01 AM
  2. need help print random digital
    By lowpro in forum New To Java
    Replies: 1
    Last Post: 12-31-2007, 07:47 AM
  3. need help print char and digital
    By lowpro in forum New To Java
    Replies: 4
    Last Post: 12-04-2007, 08:20 AM
  4. Pogo clock problem
    By tampacurt in forum New To Java
    Replies: 0
    Last Post: 11-17-2007, 03:18 AM
  5. dynamically updating clock
    By malakaherath in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 07:57 PM

Posting Permissions

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