Question

//Create a New Java Project called CheckBoxes. //Write a program with two checkboxes, one labeled BLUE...

//Create a New Java Project called CheckBoxes.

//Write a program with two checkboxes, one labeled BLUE and the other labeled ORANGE. When no checkbox is selected, the panel’s background color should be gray and its foreground color should be black.

//When only the BLUE checkbox is selected, the panel’s background color should be blue and its foreground color should be yellow. When only the ORANGE checkbox is selected, the panel’s background color should be orange and its foreground color should be white.

//When both checkboxes are selected, the panel’s background color should be blue and its foreground color should be orange. Please note that checkboxes require the use of the ItemListener, as opposed to the ActionListener

Homework Answers

Answer #1

This is your main and driver class:

package com.colourchanger;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class ColorDemo extends JFrame implements ItemListener{

   int r=0,g=0,b=0;
JCheckBox orange,green,blue;
JPanel P = new JPanel();
JPanel cpanel = new JPanel();
Container pane = getContentPane();


ColorDemo(String cd){
super(cd);
orange = new JCheckBox("orange");
orange.addItemListener(this);

/* green = new JCheckBox("green");
green.addItemListener(this);*/

blue = new JCheckBox("blue");
blue.setSelected(true);
blue.addItemListener(this);

cpanel.add(orange);
//cpanel.add(green);
cpanel.add(blue);

getContentPane().add(cpanel,"North");
setSize(400,400);
setVisible(true);

getContentPane().add(P);
P.setAlignmentX(JComponent.CENTER_ALIGNMENT);
setVisible(true);

}

public static void main(String[] args)
{
ColorDemo cd = new ColorDemo("Color Check Box");
cd.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void itemStateChanged(ItemEvent ie){

if(ie.getItem() == orange)
if(orange.isSelected()) r=255; else r=0;
//if(ie.getItem() == green)
//if(green.isSelected()) g=255; else g=0;
if(ie.getItem() == blue)
if(blue.isSelected()) b=255; else b=0;

P.setBackground(new Color(r,g,b));

}

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
using HTML JAVA AND CSS all embeded on one page. create a page with some black...
using HTML JAVA AND CSS all embeded on one page. create a page with some black paragraph text against a white background, on the page pu a button labeled night mode. when the button is clicked the backgrournd should turn black all text should be white. when the button is initially clicked, the text should change to say "day mode"
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. // A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. // At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the...
Compile and execute the application. You will discover that is has a bug in it -...
Compile and execute the application. You will discover that is has a bug in it - the filled checkbox has no effect - filled shapes are not drawn. Your first task is to debug the starter application so that it correctly draws filled shapes. The bug can be corrected with three characters at one location in the code. Java 2D introduces many new capabilities for creating unique and impressive graphics. We’ll add a small subset of these features to the...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can test if...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Part 1: Two Round Conductors Gather all items required for the exercise. Note: If using the...
Part 1: Two Round Conductors Gather all items required for the exercise. Note: If using the lab kit box, remove contents and place in a secure area. Put on your safety goggles. Center the black conductive paper on the top of the box, grid-side up. Place the two metal nuts (conductors) at the (5 cm, 10 cm) and (20 cm, 10 cm) positions on the paper. Secure using two dissection pins for each conductor. See Figure 13. Note: Place the...
What strategy would you recommend for Dove (1) in responding (or in not responding) to consumers...
What strategy would you recommend for Dove (1) in responding (or in not responding) to consumers and (2) going forward (or not going forward) with the campaign? If they were to go forward with this campaign, should Dove revise its Real Beauty message and if, so, how? The Dove Real Beauty Campaign In 2004, with sales at approximately $2.5 billion, Dove saw an opportunity to tap into women’s self-perceptions of beauty to address female insecurities while building a connection between...
There are two reflective essays from MED students during their third year internal medicine clerkship. One...
There are two reflective essays from MED students during their third year internal medicine clerkship. One student sees each connection to a patient as like the individual brush strokes of an artist and the other sees gratitude in a patient with an incurable illness and is moved to gratitude in her own life. (WORD COUNT 500) Reflect on both essays and then choose one and describe how the student grew from the experience. Then explain what you learned as a...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons...
1. The failure of the new supply chain system affected Nike adversely. What were the reasons for the failure and how did the breakdown harm Nike? 2. What are the important elements to be kept in mind while implementing a new system in an organization? What is the importance of a good working relationship between partners and the sharing of responsibility in implementing critical projects? What mistakes did Nike and i2 make? 3. comment on the lessons learned and the...