Create a Java GUI application that contains a label and a button. The label reads “Click the button to change the background color.” When the button is clicked, the background is changed to a different color.

What will be an ideal response?


```
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.Container;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class ColorChange extends JFrame implements ActionListener
{
public static final int WIDTH = 300;
public static final int HEIGHT = 300;

private static Container c;

public static void main(String args[])
{
ColorChange gui = new ColorChange();
gui.setVisible(true);
}

public ColorChange()
{
super("Change Background Color Demo");
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c = getContentPane();

JLabel label1 = new JLabel("Click the button to change the background
color");
c.add(label1);

JButton button = new JButton("Change Color");
c.add(button);
}

public void actionPerformed(ActionEvent e)
{
String buttonString = e.getActionCommand();
if(buttonString.equals("Change Color"));
c.setBackground(Color.WHITE);
}
}
```

Computer Science & Information Technology

You might also like to view...

Which connectivity model uses a single access point that provides connectivity for a number of clients within a BSS?

A. Point-to-point B. Point-to-multipoint C. Mesh multipoint D. Roaming

Computer Science & Information Technology

Which of the following is NOT true about the Find Unmatched query wizard?

A) If a one-to-many relationship exists between the two tables, then the wizard will join the two correct fields automatically. B) The wizard uses the primary key from the first table and matches it with the foreign key in the second table in order to determine if there are unmatched records. C) The Find Unmatched Query Wizard is designed to find records in a table or query that have no related records in the same table or query. D) The wizard will try to match the primary key field and the foreign key field if there is a one-to-many relationship between the two tables.

Computer Science & Information Technology

The Virtual Machine configurable COM setting emulates a maximum of one serial port

Indicate whether the statement is true or false

Computer Science & Information Technology

COGNITIVE ASSESSMENT You are interested in a career as a database administrator. What skills do you need?

A. create and maintain a data dictionary; monitor database performance B. uses data modeling techniques and tools to analyze and specify data usage C. collects and analyzes evidence found on computers, networks, mobile devices, and databases D. plans and designs software and apps that consider a user's reaction to a program and its interface

Computer Science & Information Technology