Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ColorFrame.java /NewColorFram e .java 1. Create a file for the program shown here: 2. Run program. [NOTE: There might be errors in the code you

ColorFrame.java/NewColorFrame.java

1. Create a file for the program shown here:
2. Run program. [NOTE: There might be errors in the code you need to fix.]
3. Describe what is happening in the area highlighted in yellow.
4. For the NewColorFrame.java program, re-write the inner class as a lambda expression.

package com.IST240Apps;

import java.awt.*;

import java.awt.events.*;

import javax.swing.*;

public class ColorFrame extends Jframe {

Jbutton red, green, blue;

public Colorframe() {

super("ColorFrame");

setSize(322, 122);

setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);

FlowLayout flo = new FlowLayout();

setLayout(flo);

red = new Jbutton("Red");

add(red);

green = new Jbutton("Green");

add(green);

blue = new Jbutton("Blue");

add(blue);

// comment: something starts here

ActionListener act = new ActionListener() {

public void actionPerformed(ActionEvent event) {

if (event.getSource() == red) {

getContentPane().setBackground(Color.RED);

}

if (event.getSource() == green) {

getContentPane().setBackground(Color.GREEN);

}

if (event.getSource() == blue) {

getContentPane().setBackground(Color.BLUE);

}

}

};

// comment: something ends here

red.addActionListener(act);

green.addActionListener(act);

blue.addActionListener(act);

setVisible(false);

}

public static void main(Stringarguments) {

new Colorframe();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions