Believe it or not, I've come a long way w/ this clock; however, I cannot figure out how to color the buttons. When it is that certain hour, minute, & second, the buttons are supposed to be colored. I don't know how to color them. Any assistance w/ the following program is greatly appreciated.
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.border.*;
public class NewClock extends JFrame implements ActionListener
{
public static void main(
String[] args)
{
NewClock clock = new NewClock();
clock.myLayout();
}
public NewClock()
{
}
public void myLayout()
{
int rowSize = 6;
int colSize = 2;
int horGap = 3;
int verGap = 3;
int hGap = 8;
int vGap = 4;
int numHrs = 12;
int numMin = 59;
int numSec = 59;
int hour;
int min;
int sec;
Panel pl1 = new Panel(); //create the frame
Panel pl2 = new Panel();
Panel pl3 = new Panel();
JFrame con = new myClock(100, 100, 600, 200); //container to hold all
BorderLayout conBL = new BorderLayout(hGap, vGap);
con.getContentPane().setLayout(conBL);
//Code that generates the Time
GregorianCalendar time = new GregorianCalendar();
hour = time.get(time.HOUR);
min = time.get(time.MINUTE);
sec = time.get(time.SECOND);
//Time Tester
System.out.print(hour + ":" + min + ":" + sec);
//generate the layout
GridLayout gl1 = new GridLayout(rowSize, colSize, horGap, verGap);
pl1.setLayout(gl1);
for (int i = 1; i <= numHrs; i++)
{
pl1.add(new Button(Integer.toString(i)) );
}
pl1.validate();
GridLayout gl2 = new GridLayout(rowSize, colSize, horGap, verGap);
pl2.setLayout(gl2);
for (int i = 1; i <= numMin; i++)
{
pl2.add(new Button(Integer.toString(i)) );
}
pl2.validate();
pl3.setLayout(gl2);
for (int i = 1; i <= numSec; i++)
{
pl3.add(new Button(Integer.toString(i)) );
}
pl3.validate();
Button b = new Button("Seconds");
con.getContentPane().add(pl1, BorderLayout.WEST);
con.getContentPane().add(pl2, BorderLayout.CENTER);
con.getContentPane().add(pl3, BorderLayout.EAST);
con.getContentPane().add(b, BorderLayout.SOUTH);
con.validate();
con.pack();
}
NewClock(int x, int y, int w, int h)
{
super();
this.setBounds(x, y, w, h);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
}
}
[ April 14, 2005: Message edited by: Tonia Billiot ]