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 11-19-2007, 10:54 PM
Member
 
Join Date: Nov 2007
Posts: 17
michcio has a little shameless behaviour in the past
help me with JFrame and JLabel
hello!
I have been trying, with some friends help, for a couple of days now to make a "countdown" program. The main point of this program was to see a time running down in a window. I have tried to make my own window with JFrame and successed. (I have done a new label and everything) But now the problem is how to get the label updated so I can see the time "running" down. I have tested with "setText" from the main platform JLabel but I have not succesed. Maybe the foult is that I use a Calendar platform from java.util to count how much time it's left.
I realy need help with this problem.
Ty... Michal
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-19-2007, 11:12 PM
Member
 
Join Date: Nov 2007
Posts: 17
michcio has a little shameless behaviour in the past
here is my program:


package minapplikation;
import java.util.*;
import javax.swing.*;
import java.awt.*;
public class countdown {

public static void main(String [] arg)
throws Exception{
String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
if (ids.length == 0)
System.exit(0);

SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
Calendar calendar = new GregorianCalendar(pdt);
Date trialTime = new Date();
JLabel emptyLabel = new JLabel();

int a = calendar.get(Calendar.DAY_OF_YEAR);
int dagarkvar = 0;
if(a>50)
dagarkvar = 402-a;
else
dagarkvar = 46-a;

int b = calendar.get(Calendar.HOUR) + 9;

int c = calendar.get(calendar.MINUTE);

int d = calendar.get(Calendar.SECOND);

int timmarkvar = 24 - b;
int minkvar = 60 - c;
int sekkvar = 60 - d;

JFrame frame = new JFrame("LOST");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

for(int i=0; i<=3; i++){
emptyLabel.setText(" tid kvar till LOST: " + dagarkvar + " dagar, " + timmarkvar +
" timmar, " + minkvar + " minuter, " + sekkvar + " sekunder ");

SwingUtilities.updateComponentTreeUI(emptyLabel);
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}

}
}

Last edited by michcio : 11-19-2007 at 11:14 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-19-2007, 11:51 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
import java.util.*; import javax.swing.*; import java.awt.*; public class CountdownRx implements Runnable { JLabel emptyLabel; SimpleTimeZone pdt; private void start() { Thread thread = new Thread(this); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); } public void run() { while(true) { try { Thread.sleep(500); } catch(InterruptedException e) { break; } updateLabel(); } } private void updateLabel() { Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); int a = calendar.get(Calendar.DAY_OF_YEAR); int dagarkvar = 0; if(a>50) dagarkvar = 402-a; else dagarkvar = 46-a; int b = calendar.get(Calendar.HOUR) + 9; int c = calendar.get(calendar.MINUTE); int d = calendar.get(Calendar.SECOND); int timmarkvar = 24 - b; int minkvar = 60 - c; int sekkvar = 60 - d; emptyLabel.setText(" tid kvar till LOST: " + dagarkvar + " dagar, " + timmarkvar + " timmar, " + minkvar + " minuter, " + sekkvar + " sekunder "); } private JLabel getLabel() { String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); if (ids.length == 0) System.exit(0); pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); emptyLabel = new JLabel(); return emptyLabel; } public static void main(String[] arg) throws Exception{ CountdownRx test = new CountdownRx(); JFrame frame = new JFrame("LOST"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(test.getLabel(), BorderLayout.CENTER); frame.setSize(400,125); frame.setVisible(true); test.start(); } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-20-2007, 12:25 AM
Member
 
Join Date: Nov 2007
Posts: 17
michcio has a little shameless behaviour in the past
hum I have tried to compile the prog. that you have send. It compiled without errors but when I'm trying to run it one appears:

java.lang.NoClassDefFoundError: minapplikation/CountdownRx
Exception in thread "main"
Java Result: 1
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-20-2007, 01:16 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
minapplikation/CountdownRx
I didn't put a package statement in the class I posted.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-20-2007, 08:44 AM
Member
 
Join Date: Nov 2007
Posts: 17
michcio has a little shameless behaviour in the past
oh how stupid of me I missed it... and it works now ty very very much for help
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
JLabel .setActionCommand stevemcc AWT / Swing 1 03-28-2008 05:16 AM
Problems with JLabel 2 geork New To Java 2 02-03-2008 09:40 PM
How to use JLabel with html leonard AWT / Swing 1 08-06-2007 05:43 PM
JLabel Jack AWT / Swing 2 07-02-2007 02:55 PM
JLabel Freddie AWT / Swing 2 05-29-2007 03:19 PM


All times are GMT +3. The time now is 11:18 AM.


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