JColorFrame.java - Authors Name Ran Sun Date 12 Aug 2018...

This preview shows page 1 - 2 out of 2 pages.

/* Authors Name: Ran Sun Date: 12 Aug 2018 Subject: Chapter14, Exercise #4 Purpose: demonstrate color change */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JColorFrame extends JFrame implements ActionListener{ //create the card layout to cycle thru all the buttons later CardLayout cards = new CardLayout(); //create 5 panels that will be positioned in border layout later JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JPanel panel3 = new JPanel(); JPanel panel4 = new JPanel(); JPanel panel5 = new JPanel(); //create all the buttons for user to use JButton button1 = new JButton("YELLOW"); JButton button2 = new JButton("BLUE"); JButton button3 = new JButton("GREEN"); JButton button4 = new JButton("RED"); public JColorFrame(){ super("Change Color"); setSize(600,600); setLayout(new BorderLayout()); //set panel 5 with card layout //add all buttons to it panel5.setLayout(cards); panel5.add(button1, "1"); panel5.add(button2, "2"); panel5.add(button3, "3"); panel5.add(button4, "4"); //change the size of each result pane panel1.setPreferredSize(new Dimension(100, 100)); panel2.setPreferredSize(new Dimension(100, 100));

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture