Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert this AWT code format into Swing and make an executable JAR file for it ========================================================= import java.awt.*; import java.awt.event.*; public class ColorCalculator implements ActionListener{

Convert this AWT code format into Swing and make an executable JAR file for it ========================================================= import java.awt.*; import java.awt.event.*;

public class ColorCalculator implements ActionListener{ private Frame f; private Panel p1, p2, p3, p4, p5, p6; private Label l1, l2, l3, l4; private TextField tf1, tf2, tf3, tf4; private Button b1, b2; public ColorCalculator(){ f = new Frame("Color Calculator");

p1 = new Panel(); p2 = new Panel(); p3 = new Panel(); p4 = new Panel(); p5 = new Panel(); p6 = new Panel(); l1 = new Label("Red: "); l2 = new Label("Green: "); l3 = new Label("Blue: "); l4 = new Label("Alpha: "); tf1 = new TextField("0", 15); tf2 = new TextField("0", 15); tf3 = new TextField("0", 15); tf4 = new TextField("0", 15); b1 = new Button("Compute"); b2 = new Button("Clear"); } public void startApp(){ p1.add(l1); p1.add(tf1); p2.add(l2); p2.add(tf2);

p3.add(l3); p3.add(tf3); p4.add(l4); p4.add(tf4); p5.add(b1); p5.add(b2); p6.setSize(300, 100); f.setLayout(new GridLayout(6, 1));

f.add(p1); f.add(p2); f.add(p3); f.add(p4); f.add(p5); f.add(p6); f.pack(); f.setVisible(true); b1.addActionListener(this); b2.addActionListener(this);

f.addWindowListener(new MyCloseButtonHandler()); } public void actionPerformed(ActionEvent e){ Object source = e.getSource(); int num1 = 0, num2 = 0, num3 = 0, num4 = 0; if (tf1.getText() != null && tf2.getText() != null && tf3.getText() != null && tf4.getText() != null){ if (num1 >= 0 && num2 >= 0 && num3 >= 0 && num4 >= 0){ num1 = Integer.parseInt(tf1.getText()); num2 = Integer.parseInt(tf2.getText()); num3 = Integer.parseInt(tf3.getText()); num4 = Integer.parseInt(tf4.getText()); if (num1 <= 255 && num2 <= 255 && num3 <= 255 && num4 <= 255){ if (num1 >= 0 && num2 >= 0 && num3 >= 0 && num4 >= 0){ if (source == b1){ p6.setBackground(new Color(num1, num2, num3,num4)); } } } } } if(source == b2){ tf1.setText("0"); tf2.setText("0"); tf3.setText("0"); tf4.setText("0"); p6.setBackground(new Color(255, 255, 255)); } } private class MyCloseButtonHandler extends WindowAdapter { @Override public void windowClosing(WindowEvent we) { System.exit(0); } } public static void main(String args[]) { ColorCalculator sc = new ColorCalculator(); sc.startApp(); } } =================================================

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Power Bi And Azure Integrating Cloud Analytics For Scalable Solutions

Authors: Kiet Huynh

1st Edition

B0CMHKB85L, 979-8868959943

More Books

Students also viewed these Databases questions

Question

How is athlete burnout defined? What are its three dimensions?

Answered: 1 week ago