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...
Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
In JAVA write the following program: Objective: Practice object-oriented principles by making two Peanut Butter and...
In JAVA write the following program: Objective: Practice object-oriented principles by making two Peanut Butter and Jelly Sandwiches. The program must create two sandwiches based on user input. The sandwich information for both must then print out their details and determine if the two sandwiches are equal. Requirements: Write a class called Bread with the following Instance Variables Name: The name brand of the bread. o   Calories: The number of calories per slice assumed to be between 50 and 250 inclusively....
IN JAVA Speed Control Problem: The files SpeedControl.java and SpeedControlPanel.java contain a program (and its associated...
IN JAVA Speed Control Problem: The files SpeedControl.java and SpeedControlPanel.java contain a program (and its associated panel) with a circle that moves on the panel and rebounds from the edges. (NOTE: the program is derived from Listing 8.15 and 8.16 in the text. That program uses an image rather than a circle. You may have used it in an earlier lab on animation.) The Circle class is in the file Circle.java. Save the program to your directory and run it...
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:...
Write a program in python that reads in the file quiztext (txt) and creates a list...
Write a program in python that reads in the file quiztext (txt) and creates a list of each unique word used in the file, then prints the list. Generate a report that lists each individual word followed by the number of times it appears in the text, for example: Frequency_list = [('was', 3), ('bird',5), ('it', 27)….] and so on. Note: Notice the structure: a list of tuples. If you're really feeling daring, Google how to sort this new list based...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database,...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database, exercise use of arrays of objects, external classes, processing files and user interaction. For this project, you will design and implement a program that analyzes baby name popularities in data provided by the Social Security Administration. Every 10 years, the data gives the 1,000 most popular boy and girl names for kids born in the United States. The data can be boiled down to...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Your company is thinking of introducing a Bring Your Own Device (BYOD) policy. You have been...
    asked 11 seconds ago
  • Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a...
    asked 2 minutes ago
  • Suppose the number of cars in a household has a binomial distribution with parameters n =...
    asked 5 minutes ago
  • HR needs some information on the new interns put into a database. Given an id, email,...
    asked 26 minutes ago
  • Problem solving strategies Questions years = input("Enter a number of years and I'll tell you how...
    asked 30 minutes ago
  • Calculate ?Hrxn for the following reaction: CH4(g)+4Cl2(g)?CCl4(g)+4HCl(g) Use the following reactions and given ?H?s. C(s)+2H2(g)?CH4(g)?H=?74.6kJC(s)+2Cl2(g)?CCl4(g)?H=?95.7kJH2(g)+Cl2(g)?2HCl(g)?H=?184.6kJ Express...
    asked 37 minutes ago
  • ASCII (American Standard Code for Information Interchange) has an encoding for every character of the alphabet,...
    asked 51 minutes ago
  • Is home confinement with electronic monitoring a deterrent? Are there negatives to being confined to one’s...
    asked 1 hour ago
  • Social hostility can have severe lasting effects of interperpersonal relationship during our adolescence years, which if...
    asked 1 hour ago
  • - A series RLC circuit has R=15 ?, L=1.5 H, and C=15 ?F. (a) For what...
    asked 1 hour ago
  • TV Circuit has 30 large-screen televisions in a warehouse in Erie and 60 large-screen televisions in...
    asked 1 hour ago
  • Charges q1, q2, q3, and q4 are placed in sequential order at the corners of a...
    asked 1 hour ago