You will be creating an event-driven GUI program. Once you have completed the ex
ID: 3531577 • Letter: Y
Question
You will be creating an event-driven GUI program. Once you have completed the exercises, save your file as "ColorFactory.java".
1. Import the required Java libraries.
2. Create a class called ColorFactory that inherits from JFrame.
3. Create named constants for a width of 500 and height of 300 for the frame.
4. Write a default constructor that does the following:
a) Calls the super constructor, passing in the title Color Factory.
b) Set the size of the window using the constants.
c) Specify what happens when the close button is clicked.
d) Get the content pane of the JFrame and set the layout manager to border
layout.
e) Call the method to build the top panel (to be written as directed below).
f) Add the panel to the north part of the content pane.
g) Call the method to build the bottom panel (to be written as directed below).
h) Add this panel to the south part of the content pane.
i) Create a label that contains the message
Explanation / Answer
This is the exact code for your question so check it out..and Rate it..It takes a lot of work..
Run it to view the output
The code starts from below line
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ColorFactory extends JFrame
{ //Fields of the class
private JFrame frame=null;
private JLabel messageLabel=null;
//A message to the user
private JPanel panelNorth=null;
//A holding panel for the north border panel
private JPanel panelSouth=null;
//A holding panel for the south border panel
private JPanel panelCenter=null;
//A holding panel for the center border panel
private JButton redButton=null;
//Changes panel color to red
private JButton orangeButton=null;
//Changes panel color to orange
private JButton yellowButton=null;
//Changes panel color to yellow
private JRadioButton greenRadioButton=null;
//Changes text color to green
private JRadioButton blueRadioButton=null;
//Changes text color to blue
private JRadioButton cyanRadioButton=null;
//Changes text color to cyan
private final int WINDOW_WIDTH = 500;
//Sets width of window
private final int WINDOW_HEIGHT = 300;
//Sets height of window
/** Constructor +ColorFactory() */
public ColorFactory() {
//Set the title of the window to Color Factory.
frame=new JFrame("Color Factory");
//Set the size of the window using the constants 500 for window width and 300 for window height.
frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); //Specify what happens when the close button is clicked.
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Get the content pane of the JFrame and set the layout manager to border layout.
frame.getContentPane().setLayout(new BorderLayout()); //Call the method buildNorthPanel to build the top panel.
buildNorthPanel(); //Add panelNorth to the north part of the content pane.
frame.add(panelNorth, BorderLayout.NORTH); //Call the method buildSouthPanel to build the bottom panel.
buildSouthPanel(); //Add panelSouth to the south part of the content pane.
frame.add(panelSouth, BorderLayout.SOUTH); //Create a label that contains the message
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.