Question: 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
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
Get step-by-step solutions from verified subject matter experts
