Question: public class Main { public static void main(String[] args) { new GUIFrame().setVisible(true); } } import java.awt.Color; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import

public class Main {

public static void main(String[] args) {

new GUIFrame().setVisible(true);

}

}

import java.awt.Color;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

public class GUIFrame extends JFrame {

private JPanel mContentPane;

private JTextField txtGreen;

private JTextField txtBlue;

private JTextField txtRed;

public GUIFrame() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100,100,200,200);

setResizable(false);

//initialize the JPanel

mContentPane = new JPanel();

mContentPane.setLayout(null);

//set the JFrame's JPanel

setContentPane(mContentPane);

//Q1. a - Add btnDisplay JButton. Set the label to "Display"

JButton btnDisplay= new JButton("Display");

//btnDisplay.setEnabled(false);

// btnDisplay.setVisible(true);

//btnDisplay.setLabel("Display");

//Q1. b - Set its bounds to 33, 138, 117, 25

btnDisplay.setBounds(33,138,117,25);

//Q1. c - Add it to the JPanel of the program

add(btnDisplay);

//Q2

//Register an anonymous object that implements ActionListener

//and add it to the action listeners of btnDisplay

//Make sure that when users click on the button,

//the JPanel's background is changed to the new color

txtRed = new JTextField();

txtRed.setBounds(104, 10, 66, 30);

mContentPane.add(txtRed);

txtGreen = new JTextField();

txtGreen.setBounds(104, 52, 66, 30);

mContentPane.add(txtGreen);

txtBlue = new JTextField();

txtBlue.setBounds(104, 94, 66, 30);

mContentPane.add(txtBlue);

JLabel lblRed = new JLabel("RED");

lblRed.setBounds(23, 17, 70, 15);

mContentPane.add(lblRed);

JLabel lblGreen = new JLabel("GREEN");

lblGreen.setBounds(23, 59, 70, 15);

mContentPane.add(lblGreen);

JLabel lblBlue = new JLabel("BLUE");

lblBlue.setBounds(23, 101, 70, 15);

mContentPane.add(lblBlue);

//Q4. Register your KeyListener to the JTextFields in the program

}

//Q3. Add an inner class that implements KeyListener here

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!