Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7581947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:19:11+00:00 2026-05-30T18:19:11+00:00

How could i go about adding more containers to my Jframe? Heres my line

  • 0

How could i go about adding more containers to my Jframe? Heres my line of code, I would like to make a clock in one window that contains other clocks in side of the same jframe, heres my code:

 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.util.Calendar;  
 public class CopyOftheclock {
public static void main(String[] args) {
    JFrame clock = new TextClockWindow();
    clock.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    clock.setVisible(true);
     }
}


 @SuppressWarnings("serial")
 class TextClockWindow extends JFrame {
 private JTextField timeField;
   public TextClockWindow() {
    timeField = new JTextField(7);
    timeField.setFont(new Font("sansserif", Font.PLAIN, 48));

    Container content = this.getContentPane();
    content.setLayout(new FlowLayout());
    content.add(timeField); 

    this.setTitle("Norway");
    this.pack();
    javax.swing.Timer t = new javax.swing.Timer(1000,
          new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  String a = "";
                  Calendar now = Calendar.getInstance();
                  int h = now.get(Calendar.HOUR_OF_DAY);
                    if (h==24)
                    {
                        h=8;
                        a = "A.M";
                    }
                    if (h==1)
                    {
                        h=9;
                        a = "A.M";
                    }
                    if (h==2)
                    {
                        h=10;
                        a = "A.M";
                    }
                    if (h==3)
                    {
                        h=11;
                        a = "A.M";
                    }
                    if (h==4)
                    {
                        h=12;
                        a = "P.M";
                    }
                    if (h==5)
                    {
                        h=1;
                        a = "P.M";
                    }
                    if (h==6)
                    {
                        h=2;
                        a = "P.M";
                    }
                    if (h==7)
                    {
                        h=3;
                        a = "P.M";
                    }
                    if (h==8)
                    {
                        h=4;
                        a = "P.M";
                    }
                    if (h==9)
                    {
                        h=5;
                        a = "P.M";
                    }
                    if (h==10)
                    {
                        h=6;
                        a = "P.M";
                    }
                    if (h==11)
                    {
                        h=7;
                        a = "P.M";
                    }
                    if (h==12)
                    {
                        h=8;
                        a = "P.M";
                    }
                    if (h==13)
                    {
                        h=9;
                        a = "P.M";
                    }
                    if (h==14)
                    {
                        h=10;
                        a = "P.M";
                    }
                    if (h==15)
                    {
                        h=11;
                        a = "P.M";
                    }
                    if (h==16)
                    {
                        h=12;
                        a = "P.M";
                    }
                    if (h==17)
                    {
                        h=1;
                        a = "A.M";
                    }
                    if (h==18)
                    {
                        h=2;
                        a = "A.M";
                    }
                    if (h==19)
                    {
                        h=3;
                        a = "A.M";
                    }
                    if (h==20)
                    {
                        h=4;
                        a = "A.M";
                    }
                    if (h==21)
                    {
                        h=5;
                        a = "A.M";
                    }
                    if (h==22)
                    {
                        h=6;
                        a = "A.M";
                    }
                    if (h==23)
                    {
                        h=7;
                        a = "A.M";
                    }
                  int m = now.get(Calendar.MINUTE);
                  int s = now.get(Calendar.SECOND);
                  timeField.setText("" + h + ":" + m + ":" + s + " " + a);
              }

          });
    t.start();
     }
 }

If you guys could help me get this to work i would really appreciate it!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:19:12+00:00Added an answer on May 30, 2026 at 6:19 pm

    1) For displaying non-editable, text use JLabel rather than JTextField.

    2) For less code, use the methods of SimpleDateFormat.

    3) Use proper LayoutManager; in your case (maybe) GridLayout would let all JComponent have the same Dimension on the screen.

    4) All GUI related code in the main public static void main(String[] args) { should be wrapped into invokeLater(); more in Initial Threads.

    5) Maybe for the rest this thread could be useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could any one suggest good Python-related podcasts out there, it could be anything about
Could any body offer me any reason about that? If we do it like
Could anyone please tell me why the following line about filter init method invocation
A solution of one of our business problems would be to store about 500
I was adding zero-or-more and one-or-more modifiers to my PEG parser, which is straightforward
I want to create a high performance server in C# which could take about
Could anybody brief about user_token functionality in Auth module? What is a use and
How could I go about keeping track of the number of times a word
How could I go about calling a method on a static class given the
The location text from Twitter could be just about anything. Sometimes Twitter clients set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.