Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-11-2008, 06:11 AM
Member
 
Join Date: Apr 2008
Posts: 1
jaidod is on a distinguished road
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++;
}
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-17-2008, 05:05 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help print random digital lowpro New To Java 1 12-31-2007 07:47 AM
need help print char and digital lowpro New To Java 4 12-04-2007 08:20 AM
Pogo clock problem tampacurt New To Java 0 11-17-2007 03:18 AM
dynamically updating clock malakaherath New To Java 2 08-01-2007 08:57 PM
digital sign libraries Shuru Advanced Java 2 05-14-2007 05:10 PM


All times are GMT +3. The time now is 07:49 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org