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
java: write an applet to display the message Welcome to Java Programming The program will have...
java: write an applet to display the message Welcome to Java Programming The program will have a checkbox to display the message in italic and or bold. The program will have a combo box that uses a string array called fontNames to store the following font names, ["Dialog", "Century", "Gothic", "Courier", "Serif"]. Depending on the selection in the font name in combo box, the applet will display the message using the font name. The program will have a radio button...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT