title: Making a digital clock in Java
body: <p>I'm making a digital clock for a project and I have four classes: <code>DigitalTimeUI</code>, which is the JFrame class, <code>TitlePanel</code>, <code>DigitPanel</code>, and <code>ColonPanel</code>, which are JPanels for the item stated.  When it is finished, it should look like this:</p>
  
  <p><img src="https://i.stack.imgur.com/3Ivbj.png" alt="enter image description here"></p>
  
  <p>The part I am stuck on is adding the <code>DigitPanel</code>s to the frame in the UI class. Here's what I have in the main class right now:</p>
  
  <pre><code>public class DigitalTimeUI extends JFrame {
  
  public static GregorianCalendar currentDate;
  final static int CLOCKWIDTH = 605;
  final static int CLOCKHEIGHT = 200;
  
  public static void main(String[] args) {
      int numOfDigits = 6;
      int startingX = 0;
      int startingY = 0;
  
      Font clockFont = new Font("Tahoma", Font.BOLD, 72);
      JFrame clock = new JFrame();
  
      clock.setSize(CLOCKWIDTH, CLOCKHEIGHT);
      clock.setVisible(true);
      clock.setResizable(false);
      clock.setDefaultCloseOperation(EXIT_ON_CLOSE);
  
      TitlePanel titlePanel = new TitlePanel();
      JLabel title = new JLabel("DIGITAL CLOCK");
      title.setFont(clockFont);
      title.setForeground(Color.BLACK);
      titlePanel.add(title);
      clock.add(titlePanel);
  
      DigitPanel digitPanel = new DigitPanel();
      JLabel digit;
      startingY = 115;
      while (numOfDigits &gt; 0) {
          if ((numOfDigits % 2) == 0) {
              startingX += 5;
              digit = new JLabel(String.valueOf(0));
  
          }
  
      }
    }
  }
  </code></pre>
  
  <p>The code is kind of a mess right now, I've still got some cleaning up to do after I get that last part figured out.  That bottom part is just some scrap from my attempts to display the 6 digit fields.  I think the main problem I'm having is finding a way to split up the time returned from <code>GregorianCalendar</code> and put them into 6 different boxes, then an efficient way to put them into the frame using a while loop or whatnot. </p>
  
  <p><strong>To clarify:</strong>  The above picture was given to me by the instructor as a guideline to go by when formatting my clock.  It also has 9 panels in it.  The "DIGITAL TIME" is a panel of the <code>TitlePanel</code> class.  The digit boxes are of the <code>DigitPanel</code> class and there are 6 of them.  The colon boxes are of the <code>ColonPanel</code> class and there are two of them.  The issue I am having is with splitting up the time into 6 different boxes.  Like, where the picture shows "48", I need a way to take the value from <code>GregorianCalendar.MINUTE</code> or whatever and split it into a 4 and an 8 to put into each of those boxes. Thanks.</p>