How do i draw a clock showing 3'0 Clock??

Hi
This is the code for a clock im drawing. However, i need it to show 3'0 clock, with the second hand at 7, but now all the needle is pointing at 12. How and what do i change? Hope someone can explain to me clearly what to do cos' im quite blur.
import java.awt.*;
import javax.swing.*;
class DisplayClock extends JFrame
public static void main(String[] args)
int hour = 0;
int minute = 0;
int second = 0;
if (args.length > 3) {
System.out.println("Usage: java DisplayClock hour minute second");
System.exit(0);
else if (args.length == 3)
hour = new Integer(args[0]).intValue();
minute = new Integer(args[1]).intValue();
second = new Integer(args[2]).intValue();
else if (args.length == 2)
hour = new Integer(args[0]).intValue();
minute = new Integer(args[1]).intValue();
else if (args.length == 3)
hour = new Integer(args[0]).intValue();
DisplayClock frame = new DisplayClock();
frame.setTitle("3 O'Clock");
frame.getContentPane().add(new DrawClock(hour, minute, second));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setVisible(true);
class DrawClock extends JPanel
private int hour;
private int minute;
private int second;
protected int xCenter, yCenter;
protected int clockRadius;
public DrawClock(int hour, int minute, int second)
this.hour = hour;
this.minute = minute;
this.second = second;
public void paintComponent(Graphics g) {
super.paintComponent(g);
clockRadius = (int)(Math.min(getSize().width, getSize().height)*0.7*0.5);
xCenter = (getSize().width)/2;
yCenter = (getSize().height)/2;
//Draw numbers on Clock
g.drawString("12", xCenter-5, yCenter-clockRadius);
g.drawString("9", xCenter-clockRadius-80, yCenter+3);
g.drawString("3", xCenter+clockRadius+75, yCenter+3);
g.drawString("6", xCenter-3, yCenter+clockRadius+10);
//Draw second hand
int sLength = (int)(clockRadius*0.9);
int xSecond = (int)(xCenter + sLength*Math.sin(second*(2*Math.PI/60)));
int ySecond = (int)(yCenter - sLength*Math.cos(second*(2*Math.PI/60)));
g.setColor(Color.red);
g.drawLine(xCenter, yCenter, xSecond, ySecond);
//Draw minute hand
int mLength = (int)(clockRadius*0.75);
int xMinute = (int)(xCenter + mLength*Math.sin(minute*(2*Math.PI/60)));
int yMinute = (int)(yCenter - mLength*Math.cos(minute*(2*Math.PI/60)));
g.setColor(Color.black);
g.drawLine(xCenter, yCenter, xMinute, yMinute);
//Draw hour hand
int hLength = (int)(clockRadius*0.75);
int xHour = (int)(xCenter +                
hLength*Math.sin((hour+minute/60.0)*(2*Math.PI/12)));
int yHour = (int)(yCenter -                
hLength*Math.cos((hour+minute/60.0)*(2*Math.PI/12)));
g.setColor(Color.black);
g.drawLine(xCenter, yCenter, xHour, yHour);
}

Before people complain...
import java.awt.*;
import javax.swing.*;
class DisplayClock extends JFrame
public static void main(String[] args)
int hour = 0;
int minute = 0;
int second = 0;
if (args.length > 3) {
System.out.println("Usage: java DisplayClock hour minute second");
System.exit(0);
else if (args.length == 3)
hour = new Integer(args[0]).intValue();
minute = new Integer(args[1]).intValue();
second = new Integer(args[2]).intValue();
else if (args.length == 2)
hour = new Integer(args[0]).intValue();
minute = new Integer(args[1]).intValue();
else if (args.length == 3)
hour = new Integer(args[0]).intValue();
DisplayClock frame = new DisplayClock();
frame.setTitle("3 O'Clock");
frame.getContentPane().add(new DrawClock(hour, minute, second));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setVisible(true);
class DrawClock extends JPanel
private int hour;
private int minute;
private int second;
protected int xCenter, yCenter;
protected int clockRadius;
public DrawClock(int hour, int minute, int second)
this.hour = hour;
this.minute = minute;
this.second = second;
public void paintComponent(Graphics g) {
super.paintComponent(g);
clockRadius = (int)(Math.min(getSize().width, getSize().height)*0.7*0.5);
xCenter = (getSize().width)/2;
yCenter = (getSize().height)/2;
//Draw numbers on Clock
g.drawString("12", xCenter-5, yCenter-clockRadius);
g.drawString("9", xCenter-clockRadius-80, yCenter+3);
g.drawString("3", xCenter+clockRadius+75, yCenter+3);
g.drawString("6", xCenter-3, yCenter+clockRadius+10);
//Draw second hand
int sLength = (int)(clockRadius*0.9);
int xSecond = (int)(xCenter + sLength*Math.sin(second*(2*Math.PI/60)));
int ySecond = (int)(yCenter - sLength*Math.cos(second*(2*Math.PI/60)));
g.setColor(Color.red);
g.drawLine(xCenter, yCenter, xSecond, ySecond);
//Draw minute hand
int mLength = (int)(clockRadius*0.75);
int xMinute = (int)(xCenter + mLength*Math.sin(minute*(2*Math.PI/60)));
int yMinute = (int)(yCenter - mLength*Math.cos(minute*(2*Math.PI/60)));
g.setColor(Color.black);
g.drawLine(xCenter, yCenter, xMinute, yMinute);
//Draw hour hand
int hLength = (int)(clockRadius*0.75);
int xHour = (int)(xCenter +
hLength*Math.sin((hour+minute/60.0)*(2*Math.PI/12)));
int yHour = (int)(yCenter -
hLength*Math.cos((hour+minute/60.0)*(2*Math.PI/12)));
g.setColor(Color.black);
g.drawLine(xCenter, yCenter, xHour, yHour);
}

Similar Messages

  • Perspective Grid: How do I draw a cube showing only its TOP and its FRONT?

    Can I create this with Illustrator's Perspective Grid? the 1-, 2-, and 3-point perspectives don't seem to be what I need...

    Yes you can draw it with perspective grid.
    Set up perspective grid
    Draw a square and rotate it 45°
    then drag square into perspective grid
    Make a copy by pressing Alt and 5 and moving up
    (to measure the distance you could place a copy of the square from step one on one of the sides in perspective grid)
    Then use the pen tool to draw the front side by connecting the dots.

  • Perspetive Grid: how do I draw a cube showing only the TOP side and the FRONT side using perspective grid?

    My problem is that 1-, 2-, and 3-point perspectives do not semm to provide the perspective I need. and suggestions?

    There's no attachment.
    You need to upload your sketch via the forum web interface.

  • Login Window clock shows incorrect time, clock time fixes itself after log in...

    Good Evening,
    This morning I turned on my MacBook Pro and while I was typing my password to log in, I noticed that the time in the login window clock had a wrong setting. The time displayed was 4 hours delayed in relation to my time zone. However, after logging into my user account I looked and the menu bar and when the clock got displayed, the correct time of my time zone appeared.
    I don't know what could have caused this issue. The only thing I know is that yesterday evening, I was using my MacBook Pro with Windows 7 via Bootcamp and used it for a prolonged time (about 5 hours), and then shutdown the computer and did not touch the computer until this morning. Could these issues be related? I know OS X and Windows measure their times differently because the former OS calculates time in relation to UTC and the latter OS calculates the time using the actual zone you have specified in the time settings.
    Other than that the issue has not manifested itself again since this morning but I haven't booted into Windows just yet.
    Thanks for your time!

    Make sure the time and date are correct.
    Open System Preferences > Date & Time then select the Date & Time tab.
    Select:   Set date and time automatically
    Then select the Time Zone tab.
    Select:  Set time zone automatically using current location
    If that doesn't help, open the Finder. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following:
    ~/Library/Preferences/com.apple.systemuiserver.plist
    Click Go then move the coml.apple.systemuiserver.plist file to the Trash.
    Then restart your Mac and check the time ...

  • I just updated my 3gs to iOS5 and it keeps on saying cannot activate iphone.. after searching videos how to activate it.. i can't tap my three fingers because there is no clock showing on my screen. how do i go about it? help please.

    i just updated my 3gs to iOS5 and it keeps on saying cannot activate iphone.. after searching videos how to activate it.. i can't tap my three fingers because there is no clock showing on my screen. how do i go about it? help please.

    i have the exact same problem and im still currently trying to figure out how to activate it

  • HT201274 i have choosen erase all content option on my iphone 4s but its only showing a small clock rotating, can u tell me how much time will it take.

    i have choosen erase all content option on my iphone 4s but its only showing a small clock rotating, can u tell me how much time will it take.

    Let it do the rotating thing for about 10-15 min. If it is still doing this, try wiping the phone in iTunes.

  • How do you get ical to show on your home screen?

    How do you get ical to show on your home screen? I deleted it from my homescreen (somehow) and i want to get it back.

    Just open the International preferences panel, go to Times, Customize, and click on the leftmost number (hours). A small triangle lights up, and a pop-up list of various formats opens. Just select the one you like (1-24 or 01-24). Make sure to set the Date & Time preferences to 24-hour clock first.

  • How do I get it to show the date & time.

    How do I get it to show the date & time at all times. I don't want to have to click on the day & time to get the date. In the OS 10.4 I could at least get it in the "analog" format. Under leopard it just show a little clock that can't be read.
    I just want to see the time and date at all times in the upper corner on the screen

    Please see my post in your first posting at http://discussions.apple.com/thread.jspa?threadID=1237022&tstart=0
    David

  • Widget world clock shows incorrect time

    widget world clock shows incorrect time.. how can i fix this?

    There are two possibilities: (1) your computer's time is wrong. Open System Preferences, select the Date & Time tab, and either set the time manually or select a time server. If you choose the time server click on the Time Zone tab and choose your correct time zone. (2) click on the i on the World Clock widget and select a city near you (that's in the same time zone as yours.)

  • How to use Draw documnet wizar to a  user form?

    Hi all,
             I  have created one form with matrix.I want to get a  copy of sales quotation's data in my form. How to get through coding.
    (How to use Draw document wizard through coding)
             My form using UDO.Just like In my form i have created one button .If i click that button the list of sales quotations for the particular cutomer has to be displayed.
              From that i have to select one quotation,that data has to be filled   in my form.
             Please help me.How to do that?
            What is the menu ID for Draw document wizard.If i get that how can i link it with the my form having datas using UDO.
             Please help me to solve this problem
    Regards
    V.Rangarajan

    Hi,
    If you want to search for a specific menu ID you only have to activate the "System Information" with the B1 menu View -> System Information. After that when you use the Menus in the top of B1 application (all menus included the same ones as in the Modules form) you will be able to ee the MenuIDs in the bottom of B1 application.
    If you want to open a document form with information inside it I will say to better create a grid with the list of documents you want to show everytime (please have a look to UI API Grid item in help file, there is also a sample in the SDK UI samples) and make one of the columns a LinkButton, when the user will click in the link button the document form will open automatically. You have also many posts talking about how to create a link button in a grid, please use the search capabitility of this forum.
    Hope it helps
    Trinidad.

  • I just got a new iPad air and also own an iPhone 5. I'm receiving most of my text messages on the iPhone, but some but not all are also showing up on my iPad. I don't want them on my iPad, any suggestions on how to get them to stop showing up n my iPad?

    I just got a new iPad air and also own an iPhone 5. I'm receiving most of my text messages on the iPhone, but some are now also showing up on my iPad. I don't want them on my iPad, any suggestions on how to get them to stop showing up n my iPad?

    Go to settings>messages>send and receive at>you can be reached by iMessages at> Uncheck your phone number and you can select your Apple ID emal address if you want to use that for messages.

  • I downloaded a WMA audiobook from library using Overdrive. It shows up on my Itunes listing of Audiobooks on my Ipod, but on the actual Ipod it only shows up on Playlists. How do I get it to show up under Audiobooks?

    I downloaded a WMA audiobook from library using Overdrive. It shows up on my Itunes listing of Audiobooks on my Ipod, but on the actual Ipod it only shows up on Playlists.  It is marked as an audiobook in Options | Media Kind.  It is also marked to Remeber Position, but it does not do that. How do I get it to show up under Audiobooks and remember the position?  I have a 4th Gen Ipod running Ios5

    Check out the instructions for a work around on this post: https://discussions.apple.com/message/18702732#18702732
    This worked for me.  I would like to see Apple fix this issue, as it isn't very fun to have to do this for every downloaded book.

  • I have audio books on my ipod, but when I hook it up to my computer they don't show up so I can't take them off or anything.  Now I am out of space.  How do I get them to show up on the itunes sync screens?

    I have audio books that are on my ipod touch, but when I hook it up to my computer to make changes they don't show up.  I can't add new music, because it keeps telling me I am out of room.  When I go to the book tab at the top it doesn't show any so I can't take them off.  How do I get them to show up?

    iDevices are not and have never been backup devices.
    Authorizing a computer does not cause media to magically appear.
    Media is only where the user puts it.
    Copy the ENTIRE iTunes folder from the old computer to the new computer.

  • When I open an event, including flagged items, the photos appear one by one, not as thumbnails, so I can't export more than one phot at a time. How do I get iPhoto to show the thumbnails?

    When I open an event, including flagged items, the photos appear one by one, not as thumbnails, so I can't export more than one phot at a time. How do I get iPhoto to show the thumbnails?
    I've tried rebuilding the thumbnail database, but that hasn't helped.

    What version of iPhoto and system are you running?
    Try moving the Zoom slider at the bottom of the iPhoto window all the way to the left.  Does that let more than one photo display in the window?
    OT

  • When a tab is close, firefox next shows the tab to the right. How do I get firefox to show the tab to the LEFT of the closed tab?

    I have 3 tabs open named 1, 2 and 3. If I close tab 2, Firefox will automatically show tab 3. How do I get Firefox to show tab 1 instead of tab 3? Basically, move to the left instead of the right?
    I searched about:config using words like: tab, open, close, next, left and right and compared the results on
    http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries to get a good idea of what each entry did. Learned a lot and reconfigured other aspects of Firefox in the process! But, I would really like to alter the way Firefox processes tab closures.
    Thank you.

    You can look at these extensions:
    *Tab Control: https://addons.mozilla.org/firefox/addon/1480
    *Tabberwocky: https://addons.mozilla.org/firefox/addon/14439
    *Tab Mix Plus: https://addons.mozilla.org/firefox/addon/1122

Maybe you are looking for

  • IPhone 5S Microphone Problem

    Hello Everyone, Well one, I have a little concern with my iPhone 5S 16gb Black for Sprint. I am noticing that from day 1 people have said that they have trouble hearing me and are experiencing a muffled effect on my voice. I end up having to speak re

  • What does symbol can't be resolved mean?

    Hi again. I'm looking through another tutorial and have written in a test program. I keep going over the toot(tutorial) and I can't seem to find any syntactical errors, but according to DOS I'm getting a "cannot resolve symbol" and the arrow indicato

  • Unable to copy DVD with home movies

    I am able to play a DVD that has home movies on it on my Imac and MacBook Pro. I am not able to import into IMovie to try some editing and I cannot copy or burn another disk to share. The copy company stated there was no copy protection on the disk.

  • Setting Margins for Mailing Labels in Reports 6i

    I would like to know how to configure the margins (vertical/horizontal properties) for different mailing label formats. I am unable to correctly set them to use for Avery labels. MS Access has a great label wizard that brings up a variety of mailing

  • Initializing Vector with ResultSet(TO SLOW!)

    Hi Im creating a JTable from two Vectors. I need to initialize the one vector from a resultset. This is way to slow for large result sets. Heres my loop: private Vector getData(int columns[]) throws Exception      rows = new Vector(queue.count);