Question

22. Fill in the codes that creates a Java GUI application that contains a label and a button. The label reads Click the butt
22.2 13 package javaapplication 179; public class JavaApplication 179 { public static void main(String args) { ColorChangcakr
0 0
Add a comment Improve this question Transcribed image text
Answer #1

package javaapplication179; import javax.swing. *; import java.awt. *; import java.awt.event.*; class ColorChange extends JFradd(label); add(button); } /*Since a listener to button is added, on the click of the button, this actionPerformed() method ipackage javaapplication179; public class JavaApplication179 { public static void main(String a[]) { ColorChange aFrame = new

package javaapplication179;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;



class ColorChange extends JFrame implements ActionListener 

{

      JLabel label = new JLabel("Click the button to change the background color");

      JButton button = new JButton("Change Color");



      public ColorChange()

      {

            super("Change color");

            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            setLayout(new FlowLayout());

            button.addActionListener(this);

            /*The above line of code adds an action listener to the JButton button */ 

            add(label);

            add(button);

            }



            /*Since a listener to button is added, on the click of the button, this actionPerformed( ) method is called. */

            public void actionPerformed(ActionEvent e) 

            {

                        this.getContentPane().setBackground(Color.RED); 

                        /*The above line of code change the background color of the JFrame, ColorChange to red. 

                            The keyword this specifies the current frame, ColorChange. */

            }

}



package javaapplication179;

public class JavaApplication179
{

            public static void main(String a[])

            {

                        ColorChange aFrame = new ColorChange();

                        final int WIDTH=250;

                        final int HEIGHT=100;

                        aFrame.setSize(WIDTH,HEIGHT);

                        aFrame.setVisible(true);

            }

}
Add a comment
Know the answer?
Add Answer to:
22. Fill in the codes that creates a Java GUI application that contains a label and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with...

    Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with the files available here. public class app6 { public static void main(String args[]) {     myJFrame6 mjf = new myJFrame6(); } } import java.awt.*; import javax.swing.*; import java.awt.event.*; public class myJFrame6 extends JFrame {    myJPanel6 p6;    public myJFrame6 ()    {        super ("My First Frame"); //------------------------------------------------------ // Create components: Jpanel, JLabel and JTextField        p6 = new myJPanel6(); //------------------------------------------------------...

  • Please design a Java GUI application with two JTextField for user to enter the first name...

    Please design a Java GUI application with two JTextField for user to enter the first name and last name. Add two JButtons with action events so when user click on one button to generate a full name message from the user input and put it in a third JTextField which is not editable; and click on the other button to clear all three JTextField boxes. Please run the attached nameFrame.class file (Note: because there is an actionhandler inner class in...

  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • Modify Java Code below: - Remove Button Try the Number -Instead of Try the Number button...

    Modify Java Code below: - Remove Button Try the Number -Instead of Try the Number button just hit enter on keyboard to try number -Remove Button Quit import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; // Main Class public class GuessGame extends JFrame { // Declare class variables private static final long serialVersionUID = 1L; public static Object prompt1; private JTextField userInput; private JLabel comment = new JLabel(" "); private JLabel comment2 = new JLabel(" "); private int...

  • GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public...

    GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public class DrawingFrame extends JFrame {    JButton loadButton, saveButton, drawButton;    JComboBox colorList, shapesList;    JTextField parametersTextField;       DrawingFrame() {        super("Drawing Application");        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        JToolBar toolbar = new JToolBar();        toolbar.setRollover(true);        toolbar.add(loadButton=new JButton("Load"));        toolbar.add(saveButton=new JButton("Save"));        toolbar.addSeparator();        toolbar.add(drawButton=new JButton("Draw"));               toolbar.addSeparator();        toolbar.addSeparator();        toolbar.add(new...

  • This is the java GUI program. I want to add an icon to a button, but...

    This is the java GUI program. I want to add an icon to a button, but it shows nothing. Can you fix it for me please? import java.awt.BorderLayout; import java.awt.Container; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; class Icon extends JFrame{ public static void main(String args[]){ Icon frame = new Icon("title"); frame.setVisible(true); } Icon(String title){ setTitle(title); setBounds(100, 100, 300, 250); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); ImageIcon icon1 = new ImageIcon("https://static.thenounproject.com/png/610387-200.png"); JButton button1 = new JButton(icon1); p.add(button1); Container contentPane...

  • Swing File Adder: Build a GUI that contains an input file, text box and Infile button....

    Swing File Adder: Build a GUI that contains an input file, text box and Infile button. It also must contain and output file, text box and Outfile button. Must also have a process button must read the infile and write to the outfile if not already written that is already selected and clear button. It must pull up a JFile chooser that allows us to brows to the file and places the full path name same with the output file.  Program...

  • Instructions The application JFacts contains a JFrame, a label, and six random facts. Every time the...

    Instructions The application JFacts contains a JFrame, a label, and six random facts. Every time the user clicks the JButton, remove replace the label's text and add a different one. The facts should cycle in order, fact 1 to fact 6. When the JButton is pressed on face 6, the program should display fact 1 again. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JFacts extends JFrame implements ActionListener { FlowLayout flow = new FlowLayout(); JButton b = new JButton("Press...

  • Modify the code to turn the text area background to the color YELLOW if you click...

    Modify the code to turn the text area background to the color YELLOW if you click an "x" (lower or uppercase)? package com.java24hours; import javax.swing.*; import java.awt.event.*; import java.awt.*; public class KeyViewer extends JFrame implements KeyListener { JTextField keyText = new JTextField(80); JLabel keyLabel = new JLabel("Press any key in the text field."); public KeyViewer() { super("KeyViewer"); set LookAndFeel(); setSize(350, 100); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ; keyText.addKeyListener(this); BorderLayout bord = new BorderLayout(); set Layout (bord); add (keyLabel, BorderLayout. NORTH); add (keyText, BorderLayout....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT