Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IMP Timed 15 minutes Can you check if my answer is right or not? if it's not right, please modify the answer Solution: import java.awt.*;

IMP Timed 15 minutes Can you check if my answer is right or not? if it's not right, please modify the answer image text in transcribed

Solution:

import java.awt.*; import javax.swing.*; import java.awt.event.*;

public class GUIProgram extends JFrame implements ActionListener { final double SIZE = 44.3; Container con = getContentPane(); JButton button = new JButton("Show Results"); JLabel label = new JLabel("----"); public GUIProgram() { con.setLayout(new FlowLayout()); setSize(500, 500); //Adding action listener button.addActionListener(this); //Adding to pane con.add(button); con.add(label); //Set title setTitle("GUI Program"); pack(); setVisible(true); //allows the frame to be visible } @Override public void actionPerformed(ActionEvent e) { //Declaring variables int x=12, y=34, z=87; //Computing an average double average= (x+y+z)/3; //Writing to label label.setText("Average of these numbers is " + average); } public static void main(String[] args) { GUIProgram frame = new GUIProgram(); } }

Write a Java program to create a GUI window with a label and a button as shown in the following image. Consider three variables x, y and z with values as follows: X=12, y=34, z=87. When the user click the button, the program should display the output as follows: Average of these numbers is 44.3 The output should be displayed on the GUI window using a label. To display this output, you are required to use appropriate Java logic and other elements such as operators, loops, If-else etc. GUI Program Show Results show your results here

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

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions