Check out JButton documentation. Take special attention to setBackground
and setForeground
methods inherited from JComponent
.
Something like:
for(int i=1;i<=9;i++)
{
JButton btn = new JButton(String.valueOf(i));
btn.setBackground(Color.BLACK);
btn.setForeground(Color.GRAY);
p3.add(btn);
}