no error, but nothing shows up - function main wrong?

Hey, I'm compiling this program and I have no error but the applet shows, then disappears without showing anything! It should show 2 clocks!
import java.awt.*;
import javax.swing.*;
import java.util.*;

public class StillClock extends JPanel {
  private int hour;
  private int minute;
  private int second;

  public static void main( String arg[] ) {
        StillClock SC = new StillClock(4, 20, 45) ;
        StillClock SC2 = new StillClock(22, 46, 15) ;
    }

  /** Construct a default clock with the current time*/
  public StillClock() {
    setCurrentTime();
  }

  /** Construct a clock */
  public StillClock(int hour, int minute, int second) {
    this.hour = hour;
    this.minute = minute;
    this.second = second;
  }

  /** Return hour */
  public int getHour() {
    return hour;
  }

  /** Set a new hour */
  public void setHour(int hour) {
    this.hour = hour;
    repaint();
  }

  /** Return minute */
  public int getMinute() {
    return minute;
  }

  /** Set a new minute */
  public void setMinute(int minute) {
    this.minute = minute;
    repaint();
  }

  /** Return second */
  public int getSecond() {
    return second;
  }

  /** Set a new second */
  public void setSecond(int second) {
    this.second = second;
    repaint();
  }

  /** Draw the clock */
    @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    // Initialize clock parameters
    int clockRadius =
      (int)(Math.min(getWidth(), getHeight()) * 0.8 * 0.5);
    int xCenter = getWidth() / 2;
    int yCenter = getHeight() / 2;

    // Draw circle
    g.setColor(Color.black);
    g.drawOval(xCenter - clockRadius, yCenter - clockRadius,
      2 * clockRadius, 2 * clockRadius);
    g.drawString("12", xCenter - 5, yCenter - clockRadius + 12);
    g.drawString("9", xCenter - clockRadius + 3, yCenter + 5);
    g.drawString("3", xCenter + clockRadius - 10, yCenter + 3);
    g.drawString("6", xCenter - 3, yCenter + clockRadius - 3);

    // Draw second hand
    int sLength = (int)(clockRadius * 0.8);
    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.65);
    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.blue);
    g.drawLine(xCenter, yCenter, xMinute, yMinute);

    // Draw hour hand
    int hLength = (int)(clockRadius * 0.5);
    int xHour = (int)(xCenter + hLength *
      Math.sin((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));
    int yHour = (int)(yCenter - hLength *
      Math.cos((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));
    g.setColor(Color.green);
    g.drawLine(xCenter, yCenter, xHour, yHour);
  }

  public void setCurrentTime() {
    // Construct a calendar for the current date and time
    Calendar calendar = new GregorianCalendar();

    // Set current hour, minute and second
    this.hour = calendar.get(Calendar.HOUR_OF_DAY);
    this.minute = calendar.get(Calendar.MINUTE);
    this.second = calendar.get(Calendar.SECOND);
  }

    @Override
  public Dimension getPreferredSize() {
    return new Dimension(200, 200);
  }
}
Edited by: Christopher on May 28, 2011 03:05

How do you run that? If you run it as a normal program via main(), I expect that it ends when the hand ends.

You are creating two JPanels but does not create a window frame/for they appear in. If you try this

JFrame frame = new JFrame();
frame.setLayout(new FlowLayout());
frame.add(SC);
frame.add(SC2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);

You will see a window with your clock in them.

Published by: Peter Lawrey may 28, 2011 12:40

Tags: Java

Similar Questions

  • Flex in a week: run the mxml, but nothing shows

    Hello

    I do the flex in a week course. Pain in the ass to see the design mode is gone but good no worries.

    In any case, I run the mxml and nothing shows. I also ran the swf that was produced and Yes - empty. However, the code seems fine so I am confused.

    < / s:Application >

    <? XML version = "1.0" encoding = "utf-8"? >

    " < = xmlns:fx s:Application ' http://ns.Adobe.com/MXML/2009 "

    xmlns:s = "library://ns.adobe.com/flex/spark".

    xmlns:MX = "library://ns.adobe.com/flex/mx".

    minWidth = "955" = "850" minHeight >

    <!-exercise 1.01: implementation of your project-> files

    <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

    < fx:Style source = "Styles.css" / >

    <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

    <!-statements ~ ~ ~->

    < fx:Declarations >

    <! - Place non-visual elements (e.g., services, items of value) here - >

    < / fx:Declarations >

    <!-UI components ~ ~ ~->

    < s:Label x = "10" y = "34".

    width = "690" height = "40".

    Text = "" Employee Portal: vehicle request form ""

    styleName = "titleHeader" / >

    < s:Form x = "10" y = "70" >

    < s:FormItem label = "employee:" >

    < s:DropDownList / >

    < / s:FormItem >

    < s:FormItem label = "office phone:" >

    < s:TextInput / >

    < / s:FormItem >

    < s:FormItem label = "Mobile phone:" >

    < s:TextInput / >

    < / s:FormItem >

    < s:FormHeading label = "Dates" / >

    < s:FormItem label = "pickup Date:" >

    < mx:DateChooser / >

    < / s:FormItem >

    < s:FormItem label = "Date of return:" >

    < mx:DateChooser / >

    < / s:FormItem >

    < s:FormItem >

    < s:Button label = "Submit Request" / >

    < / s:FormItem >

    < / s:Form >

    Are you sure that you run the mxml right? A few time to create a new also helps. Sometimes templates html (js files) are absent from this cause an error javascript and nothing to load. Usually, the own generation project done. If you right click on the generated swf file that shows?

  • HP Pavilion a6750f turns on but nothing shows up on monitor

    Hello. recently whenever I try to start my computer, the unit will start and the power led is on (also light in the back is green), and the fans start to run in what appears to be at full speed. However, nothing shows up on the monitor connected to it and no beeps. I would like to know when my computer would work and when nothing display because when the computer was going to start and work, fans stopped for one or two seconds after turning on the pc, and then the fans would start again. If the fan does not stop for a few seconds, I knew that the pc does nothing (what happened).  This problem has happened several times to me and how my brother used to face was cold start quickly (hold the power button until it stops) and start again until the fans stopped. This no longer works. I wonder if certain connected USB flash drives appear to be the problem; they have not worked when I plugged (on any computer). I checked all the cables, tried to re-plugging into another outlet (they both failed). the cables seem alright, but I have not yet checked inside the motherboard.  This pc is about 2, almost 3 years. any help is appreciated.

    First of all, I would like to remove all devices and cables.

    Then reinstall only the power, the monitor, the keyboard and mouse. If it starts, then isolate the problem by adding 1 element at a time.

    If not start, I unplug the power cord and remove the memory. Add 1 to the first slot closest to the CPU. Then plug the power back and re - start. If it starts, repeat the process to find the memory defective barrette.

  • Attempts to cancel the issue of the iTunes Store, I bought by the error, but it shows me massage like this: this purchase is not eligible for a refund. Please I need help. Thank you

    Try to cancel an article that I bought by the error, but the end of any process it says this: this purchase is not eligible for a refund.

    How can I cancel or refund this purchase?

    Thank you!

    Purchases are considered final (especially if they have been downloaded), if 'report a problem' does not (http://reportaproblem.apple.com) you can try to contact iTunes support via this page and see if they will refund/credit you: http://www.apple.com/support/itunes/contact/

  • My bluetooth and wlan refused lights. I've linked enabling the setting but nothing shows up there. What can I do to fix this...

    I tried to activate the console bluetooth, WiFi or just off bluetooth completely. I tried to use the command Setup but nothing happens. Wireless bluetooth and wlan settings are simply empty.

    Is there a hardware button or a FN key on your keyboard? It might look like a satellite dish or even signal bar, please understand this part. But if there is a button, press it and check if all of the parameters of return on.

    Concerning

  • When I try to download AE or Premiere its says download free trial but nothing shows

    I tried to install the free trial of After Effects and Premiere Pro. When I click Download trial its says on the next page "is downloading now..." "but nothing happens for a long time. My creative cloud opens as well, but there is nothing on these software only Photoshop I have installed before

    I use Windows 7 and the browser I was using was Google chrome before but later, I tried Internet Explorer.

    Hi ivanateles,

    You might want to try to download the available direct download links to: http://prodesigntools.com/adobe-cc-2014-direct-download-links.html

    Please make sure you follow the instructions mentioned on the page before you start the download.

    Kind regards

    Rave

  • Why do I receive flag showing that I have a problem and insert the disc. but nothing shows

    Why do I get a red flaag showing I have a problem and to insert the blank disc aa, what I do, but the flag persists?

    Hello

    • What disk you insert?
    • What are the instructions?
    • How long have you been faced with the question?
    • Are there changes to the computer?
    • The problem is present in Safe Mode and clean the boot?
     
    I suggest you run the Analysis System File Checker and see if TI the problem still occurs. To do this, please see the following article.
  • 3 updates, but nothing shows

    Update Windows indicate that 3 updates is available. When I check what type of updates, there is nothing in there. Is this possible or do I have some malicious programs trying to lure me download something?

    Never seen before and windows update icon that opens down I have the 'clock' corner and even windows update seems real.

    Vista SP2 from basic home, HP G5000

    Hi jiipen,

    I suggest that you run the system preparation tool, to download this tool, click on the link below:
    http://www.Microsoft.com/downloads/details.aspx?FamilyId=eee94693-9aa6-4278-ace6-f2f9b7732bf1&displaylang=en

    You can also try reseting component of Windows Update.
    To do this:

    1. click on the following link: http://support.microsoft.com/kb/971058
    2. click on run in the file download dialog box and follow the steps described in the fix it Wizard.

    Thank you, and in what concerns:
    Swati K - Microsoft support technician

  • When I change the type, I do not see what is available. The screen drop happens, but nothing shows up except the default fonts.

    Screen Shot 2015-01-11 at 9.53.42 AM copy.jpg

    Magic,

    This should fix:

    Open system preferences and go to accessibility. Then select display in the source on the left side list, then check the box transparency reduced.

    It was introduced in this #15 post by TheUlser:

    https://forums.Adobe.com/message/6854594#6854594

    It has been described on this page from Adobe:

    http://capitalmacservice.com/font-preview-working-Illustrator-CS-5-Yosemite-fix/

    It may also depend on the monitor, as shown in the message #29 by Loncar in the same thread.

    Of course, this also affects other things so there can be a downside to it.

  • Satellite P300 - on power turns on, but nothing happens on the screen

    Hello

    I have a Toshiba Satellite P300-1F0, yesterday it was working fine, I turn it off nothing extraordinary happens.
    Although later, when I went to turn on I pressed the power button, but the screen was not working, I tried to connect an external display but nothing showed on this subject, although the power of lights was turned on, the drive CD opened and closed as normally don't and I could hear the fans work.

    That I realize windows 7 welcome sounds were not playing even after a few minutes with the laptop turned on and the laser mouse was working only for a few seconds before it shuts down.
    It was when I started to believe that this was not a screen problem, but something else.

    I have read a few forums and I tried to unplug the power cable, remove the battery, press the power button for 60 seconds and turn it on and it worked, it worked fine, I used the computer for a few hours without any problem.

    Today the same problem has occurred, and I tried to set the same way as I did yesterday, hold the power button for 60 seconds, but this time it did not work. I retried it for 3 to 5 times and nothing.
    After a few hours, leaving the computer is off, resting, I retried the process and now it worked.
    Now I'm afraid to turn off the laptop, because I need a lot of time and patience range to activate.

    What could be the problem and how do I solve it?
    Can you help me?

    cumpliments,
    Adriano

    > I have read a few forums and I tried to unplug the power cable, remove the battery, press the power button for 60 seconds and turn it on and it worked, it worked fine, I used the computer for a few hours without any problem.

    Yes, this workaround is sometimes useful to bring back the unity of life.

    > What could be the problem and how do I solve it?
    It's hard to say what causes this. Satellite P300 is an older model mobile phone, so it is possible that among the pieces of equipment begins to malfunction.
    It would be interesting to know if the use of the various modules of RAM would change the functionality of the laptop. If you have compatible RAM modules spare you can test it.

    In the worst case, it could be possible that beginning of motherboard laptop malfunction.
    It would be the worst case I hope for you that it s not mobo related issue.

    PS: Check if your BIOS is up to date. In case this is not the latest version, try to update the BIOS.

  • don't not running disc can hear the rotating disc but nothing on the screen

    Remember - this is a public forum so never post private information such as numbers of mail or telephone!

    Ideas: we're not serious what the dvd is for place in the taskbar and you can hear fine but nothing shows up on the screen tried to use good media tried to type in the Run dialog box, but does not recognize.

    • You have problems with programs
    • Error messages
    • Recent changes to your computer
    • What you have already tried to solve the problem

    It comes with Vista, upgrade install and activate Forum.

    http://social.answers.Microsoft.com/forums/en-us/vistahardware/threads

    They will help you with your question in Vista Hardware and drivers Forum above.

    See you soon.

    Mick Murphy - Microsoft partner

  • Satellite Pro P100-124 starts upward, but nothing on the screen

    Hello world

    I'm a newbie here & laptop but my companion got a satellite Pro P100 (Toshiba Satellite Pro P100-124 PSPA4E-001001EN) & it is my asked for help. Here's the problem:

    Laptop starts to go through the procedure of starting with lights coming and cd player starts to work the rotation of fans, but nothing shows up on the screen

    I said it could be the graphics card but could do with a starting point, I'm PC savvy but on the desktop, it's my first attempt at a portable computer so please be nice...

    Hello

    Have you tried this thing?

    ->, remove the battery and unplug the AC adapter from the portable computer
    -> waiting for ~ 30 min 1 h
    -> connect the two parts again and try to turn on the device

    If this will not help, then it would mean that a hardware problem serious causes this problem and you will need to contact a Toshiba ASP technician to know exactly what s wrogn.

    Good luck

  • iPad pro list 3 updates in waiting but nothing downloads

    can one please tell me why my new iPad Pro shows there is 3 updates to install, but nothing shows downloading or waiting for download.  My Internet connection works fine.

    Greetings drongo999,

    Thank you for using communities Support from Apple!

    It appears from your question, that you see a badge on the App Store, showing three app updates available, but when open you not seen all the apps that need to update. If this is correct, there are a couple of different troubleshooting steps that I would recommend.

    First of all, to completely close the App Store using the instructions in the following article.

    Force an app to close iOS - Apple Support

    The App Store has been closed, restart your iPhone.

    Restart your iPhone, iPad or iPod touch - Apple Support

    Once your iPhone has rebooted, you still see the badge informing you that you have updates available? If so, are there available updates when you open the App Store?

    Have a great day!

  • QML no compilation errors, but a run-time error, how to debug?

    Code QML without compiling error, but not show debug in C++ code show that qml-> hasErrors() took, but the I don't know what error cause of line. any ideas? I am looking for debug QML, but it seems only break in javascript, don't create not procedure.

    Momentics you need to open a "QNX Outlook Information System" [window-> open point of view]

    Right-click on the target and select "start SSH session".

    In this SSH session, after logging in, type ' slog2info w | grep ' 9000' '

    Look for a message on the QML problem.

  • my iphone 5 c opens more after that I was invited to be updated with itunes. now, the display shows only itunes usb cable and logo. read some tips here, but nothing happened. any help will be much appreciated.

    My iPhone 5 c opens more after that I was invited to be updated with iTunes. now the display shows iTunes logo and the USB cable. I have read and applied some tips here, but nothing happened. Any help will be much appreciated. Thank you.

    https://discussions.Apple.com/message/30014877#30014877http ://

    Read the post from sierrawren . It helped me to fix my phone. Now it works perfectly fine. Hope it can help others too.

Maybe you are looking for