Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: need help with low priority thread to display time

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post need help with low priority thread to display time

    Test4.java

    Code:
    import javax.swing.*;
    import java.awt.*;
     
    public class Test4 extends JFrame  {
     
        public Test4() {
            super("Test Toolkit");
            setSize(700, 200);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
            FlowLayout beginButtons = new FlowLayout();
            setLayout(beginButtons);
            JLabel startLabels = new JLabel("Current System");
            TimePanel time = new TimePanel();
     
            add(startLabels);
     
     
            add(time);
     
     
            setVisible(true);
            }
     
        public static void main(String[] args) {
            Test4 StartWindow = new Test4();
        }
    }


    TimePanel.java

    Code:
    import javax.swing.*;
    import java.util.*;
     
    public class TimePanel extends JPanel {
        public TimePanel() {
            super();
            String currentTime = getTime();
            JLabel time = new JLabel("Time: ");
            JLabel current = new JLabel(currentTime);
            add(time);
            add(current);
        }
        String getTime() {
            String time;
            // get current time and date
            Calendar now = Calendar.getInstance();
            int hour = now.get(Calendar.HOUR_OF_DAY);
            int minute = now.get(Calendar.MINUTE);
            int month = now.get(Calendar.MONTH);
            int day = now.get(Calendar.DAY_OF_MONTH);
            int year = now.get(Calendar.YEAR);
     
            String monthName = "";
            switch (month) {
                case (1):
                    monthName = "January";
                    break;
                case (2):
                    monthName = "February";
                    break;
                case (3):
                    monthName = "March";
                    break;
                case (4):
                    monthName = "April";
                    break;
                case (5):
                    monthName = "May";
                    break;
                case (6):
                    monthName = "June";
                    break;
                case (7):
                    monthName = "July";
                    break;
                case (8):
                    monthName = "August";
                    break;
                case (9):
                    monthName = "September";
                    break;
                case (10):
                    monthName = "October";
                    break;
                case (11):
                    monthName = "November";
                    break;
                case (12):
                    monthName = "December";
            }
            time = monthName + " " + day + ", " + year + " " + hour + ":" + minute;
                return time;
        }
    }
    Last edited by copeg; July 18th, 2010 at 03:17 PM. Reason: Code tags


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: need help with low priority thread to display time

    Please do not post the same question elsewhere in the forums (your other post was removed), and in the future please use the code tags to make your code more readable.

    What is the problem/question?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: need help with low priority thread to display time

    Cross posted at need help with low priority thread to display time - Java Forums

    This OP appears to want someone to write code for him. It'd be nice if he hired a programmer to help him.

  4. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help with low priority thread to display time

    Thanks Norm, just wondering if anyone new one call or a how too, does not seem to be be asking for someone to write anything.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: need help with low priority thread to display time

    wondering if anyone knew one call or a how to
    'One call' to what?
    'how to' what?

    What coding problem do you need help with?
    You've posted code without asking a question about it, other than it could be missing some feature.

Similar Threads

  1. set time limit on running of a thread
    By z.zojaji in forum Threads
    Replies: 3
    Last Post: July 10th, 2010, 10:57 AM
  2. Display file name
    By Puk284 in forum Java Servlet
    Replies: 1
    Last Post: April 13th, 2010, 03:13 AM
  3. How to display ppt slides through java????
    By jj_crazy_1 in forum Java Theory & Questions
    Replies: 0
    Last Post: April 5th, 2010, 10:52 PM
  4. display time
    By kalees in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: January 1st, 2010, 07:40 AM
  5. How to display the contents of my queue?
    By rocafella5007 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 30th, 2009, 11:46 AM