Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello first of all, I Have this question here, when i type the codes as shown be

ID: 3529953 • Letter: H

Question

Hello first of all, I Have this question here, when i type the codes as shown below, and creat another java file called GOOD_BRANDON_LAB_08, when i try to run the GOOD_BRANDON file, i get an error of Exception in thread "main" java.lang.NullPointerException at ColorFactory.buildNorthPanel(ColorFactory.java:76) at ColorFactory.(ColorFactory.java:39) at Good_Brandon_Lab_08.main(Good_Brandon_Lab_08.java:10) thanks already ------------------------- import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ColorFactory extends JFrame { //Fields of the class private JLabel messageLabel; //A message to the user private JPanel panelNorth; //A holding panel for the north border panel private JPanel panelSouth; //A holding panel for the south border panel private JPanel panelCenter; //A holding panel for the center border panel private JButton redButton; //Changes panel color to red private JButton orangeButton; //Changes panel color to orange private JButton yellowButton; //Changes panel color to yellow private JRadioButton greenRadioButton; //Changes text color to green private JRadioButton blueRadioButton; //Changes text color to blue private JRadioButton cyanRadioButton; //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. setTitle("Color Factory"); //Set the size of the window using the constants 500 for window width and 300 for window height. setSize(WINDOW_WIDTH, WINDOW_HEIGHT); //Specify what happens when the close button is clicked. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Get the content pane of the JFrame and set the layout manager to border layout. getContentPane().setLayout(new BorderLayout()); //Call the method buildNorthPanel to build the top panel. buildNorthPanel(); //Add panelNorth to the north part of the content pane. add(panelNorth, BorderLayout.NORTH); //Call the method buildSouthPanel to build the bottom panel. buildSouthPanel(); //Add panelSouth to the south part of the content pane. add(panelSouth, BorderLayout.SOUTH); //Create a label that contains the message

Explanation / Answer

This is the corrected Code ..The error u have done is that u have not instantiated any of these JPanel..panelNorth,panelSouth,panelCenter..I have corrected all the error..Now you can run it and check it out...and Rate..



colorFactory Class

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ColorFactory extends JFrame
{ //Fields of the class
private JLabel messageLabel;
//A message to the user
private JPanel panelNorth;
//A holding panel for the north border panel
private JPanel panelSouth;
//A holding panel for the south border panel
private JPanel panelCenter;
//A holding panel for the center border panel
private JButton redButton;
//Changes panel color to red
private JButton orangeButton;
//Changes panel color to orange
private JButton yellowButton;
//Changes panel color to yellow
private JRadioButton greenRadioButton;
//Changes text color to green
private JRadioButton blueRadioButton;
//Changes text color to blue
private JLabel foreColor;
private JRadioButton cyanRadioButton; //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()
{
panelNorth=new JPanel();
//Set the title of the window to Color Factory.
this.setTitle("Color Factory");
//Set the size of the window using the constants 500 for window width and 300 for window height.
this.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
//Specify what happens when the close button is clicked.
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Get the content pane of the JFrame and set the layout manager to border layout.
this. getContentPane().setLayout(new BorderLayout());
//Call the method buildNorthPanel to build the top panel.
this.panelNorth.setSize(200,200);
this. buildNorthPanel();
//Add panelNorth to the north part of the content pane.
this.add(panelNorth, BorderLayout.NORTH);
//Call the method buildSouthPanel to build the bottom panel.
this. panelSouth=new JPanel();
this.panelSouth.setSize(200,200);
this. buildSouthPanel();

//Add panelSouth to the south part of the content pane.
this.add(panelSouth, BorderLayout.SOUTH);
//Create a label that contains the message

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote