Question

In: Computer Science

Write an application with three radio buttons labeled “Cyan”, “Magenta”, and “Orange” that changes the background...

Write an application with three radio buttons labeled “Cyan”, “Magenta”, and “Orange” that changes the background color of a panel in the center of the frame to CYAN, MAGENTA, or ORANGE.

This is required to be programmed in Java.

Solutions

Expert Solution

import javax.swing.*;  //  package
import java.awt.*;  
import java.awt.event.*;
class ColorMain extends Frame implements ActionListener{
        
private JRadioButton Cyan;  
private JRadioButton Magenta; 

        private JRadioButton Orange; // Decalare radio button
          public ColorMain(){
        setLayout(new BorderLayout());
        setVisible(true);
        setSize(400,250);
        JPanel p = new JPanel();
        Cyan=new JRadioButton(" Cyan");
        Orange=new JRadioButton(" Orange");
        Magenta=new JRadioButton(" magenta");
        ButtonGroup bgroup=new ButtonGroup();
        bgroup.add(Cyan);
        bgroup.add(Orange);
        bgroup.add(Magenta);
        Cyan.addActionListener(this);
        Orange.addActionListener(this);
        Magenta.addActionListener(this);
        p.add(Orange);   // place the light component in a saparate container.
        p.add(Cyan);
        p.add(Magenta);
        add(p,BorderLayout.NORTH);      
}
public void actionPerformed(ActionEvent evnt){  //set bg color when button clicked
        if(evnt.getSource()== Cyan){
                setBackground(Color.cyan);
        }
        if(evnt.getSource()== Orange){
                setBackground(Color.orange); 
        }
        
        if(evnt.getSource()== Magenta){
                setBackground(Color.magenta);
        }       
        }
        
}
//driver class
public class Colorbg {
        public static void main(String[] args){
                ColorMain s=new ColorMain();
                s.addWindowListener(new WindowAdapter(){
                        public void windowClosing(WindowEvent e){
                                System.exit(0);
                        }
                        });
        }                       
}


Related Solutions

Write an application with three buttons labeled “Red”, “Green”, and “Blue” that changes the background color...
Write an application with three buttons labeled “Red”, “Green”, and “Blue” that changes the background color of a panel in the center of the frame to red, green, or blue. Add icons to the buttons of Exercise E19.1. Use a JButton constructor with an Icon argument and supply an ImageIcon. this is the code that I already wrote that I need to do the above to. import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame;...
Using C#: Create a Form that consists of 4 checkboxes, three radio buttons, a label and...
Using C#: Create a Form that consists of 4 checkboxes, three radio buttons, a label and a button. The 4 checkboxes represent pizza toppings. The three radiobuttons should represent three sizes of pizza, namely “small”, “medium” and “large”. When the user clicks the button you need to calculate the price of the pizza. The calculation should be done as follows: count up the cost of the selected ingredients (you may assign your own prices for the ingredients) and then multiply...
Write a JavaFX application that presents two buttons and a number (initially 50) to the user....
Write a JavaFX application that presents two buttons and a number (initially 50) to the user. Label the buttons Increment and Decrement. When the increment button is pushed, increment the displayed value. Likewise, decrement the value when the decrement button is pushed. This has to use Java.Fx and not Java.Awt
Write a paragraph with a short background on the topic and at least three reasons supporting...
Write a paragraph with a short background on the topic and at least three reasons supporting whether DXM (dextromethorphan) should be prescription only or if DXM should NOT be prescription only.
Write an application that reads three integers, adds all three together and computes an average of...
Write an application that reads three integers, adds all three together and computes an average of the three entries and computes any remainder of the integer division. A remainder represents the modulus result of dividing an even by an odd number or vice versa. Display the output. Enter an integer score 3 Enter an integer score 6 Enter an integer score 4 The average of 3, 6, 4 is 4 with a remainder of 1 Press any key to continue...
Write an application and perform the following:(NO USER INPUT) -Create at least three classes such as:...
Write an application and perform the following:(NO USER INPUT) -Create at least three classes such as: 1. listnode- for data and link, constructors 2. Singlelinkedlist-for method definition 3. linkedlist-for objects -Insert a node at tail/end in a linked list. -and display all the nodes in the list. -Delete a node at a position in the list Note: Add these methods in the same application which we have done in the class. this is what we've done in the class: class...
Write a three (3) page paper on the application and challenges involved with implementing an Electronic...
Write a three (3) page paper on the application and challenges involved with implementing an Electronic Health Record (EHR) system for a private family medicine practice. This is a small family practice with 3 doctors and a HIT budget of $60,000 annually and $150,000 for upfront expenditures.  The report must answer the following questions. What are the most important functionalities of the EHR that needs to be implemented at the practice? Is it possible for any existing Practice Management Systems to...
*Java* Write an application that declares an array of three Listings whose contents are input by...
*Java* Write an application that declares an array of three Listings whose contents are input by the user (User inputs name and age for each listing). After the input, the listings should output in reverse order.
(JAVA) Write an application that reads three nonzero values entered by the user and determines and...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
Write a short report noting three key changes you would like to make to your organisation's...
Write a short report noting three key changes you would like to make to your organisation's current method of measuring HR contribution. Make reference to the following: Implementing measures of efficiency, effectiveness and impact The benefits of your suggested changes The tools you would use for measurement.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT