import java.awt.*; // for setColor, setFont, setForeground import javax.swing.*; // for JFrame, JPanel, JLabel import javax.swing.border.*; // for setBorder public class Ch12_8a // similar to Ch12_5a.java, this displays text in Times New Roman bold, 20 point font { // of different colors (Strings) where each String is written in its color (e.g., blue is written in blue) public static void main(String[] args) { JFrame frame=new JFrame("Exercise12_1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300,200); JPanel p1=new JPanel(new GridLayout(2,3)); // we will have 6 JLabels in a 2x3 grid Font f1=new Font("Times New Roman", Font.BOLD, 20); // establish the font type Border b1=new LineBorder(Color.yellow,2); // Create the border to use for all JLabels JLabel l1=new JLabel("black"); // create the first JLabel, with the String "black", written in black color l1.setForeground(Color.black); l1.setFont(f1); l1.setBorder(b1); JLabel l2=new JLabel("blue"); // etc for each other JLabel l2.setForeground(Color.blue); l2.setFont(f1); l2.setBorder(b1); JLabel l3=new JLabel("cyan"); l3.setForeground(Color.cyan); l3.setFont(f1); l3.setBorder(b1); JLabel l4=new JLabel("green"); l4.setForeground(Color.green); l4.setFont(f1); l4.setBorder(b1); JLabel l5=new JLabel("magenta"); l5.setForeground(Color.magenta); l5.setFont(f1); l5.setBorder(b1); JLabel l6=new JLabel("orange"); l6.setForeground(Color.orange); l6.setFont(f1); l6.setBorder(b1); p1.add(l1); // add the JLabels to the JPanel, add the JPanel and show the JFrame p1.add(l2); p1.add(l3); p1.add(l4); p1.add(l5); p1.add(l6); frame.add(p1); frame.setVisible(true); } }