I'm making a digital clock for a project and I have four classes: DigitalTimeUI
, which is the JFrame class, TitlePanel
, DigitPanel
, and ColonPanel
, which are JPanels for the item stated. When it is finished, it should look like this:
The part I am stuck on is adding the DigitPanel
s to the frame in the UI class. Here's what I have in the main class right now:
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 > 0) {
if ((numOfDigits % 2) == 0) {
startingX += 5;
digit = new JLabel(String.valueOf(0));
}
}
}
}
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 GregorianCalendar
and put them into 6 different boxes, then an efficient way to put them into the frame using a while loop or whatnot.
To clarify: 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 TitlePanel
class. The digit boxes are of the DigitPanel
class and there are 6 of them. The colon boxes are of the ColonPanel
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 GregorianCalendar.MINUTE
or whatever and split it into a 4 and an 8 to put into each of those boxes. Thanks.