Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Write a Java GUI application to calculate total resistance, current, and power in a circuit. The general appearance of you GUI should be as shown below:

2214_ckt.jpg

Your program must meet the following requirements:

1. Do not use any of the GUI editing capabilities of Eclipse for this assignment (no setBounds). Do all the GUI layout work based on what you have learned from the lecture material and assigned book readings in the last 2 weeks.

2. You will only need to use the ActionListener interface for this lab. The only events that your program handles are action events from the 4 buttons.

3. This program is contained in 1 class that has a constructor, a main method, and a nested inner class for the event handler.

4. You must use inheritance to get a JFrame into your application

5. The GUI and event handling setup must be done in the constructor of your GUI class or in private methods called from the constructor. Hint: it would seem logical to have a private method to build the top, right, left, and bottom panels.

6. The GUI should be organized as follows:

  • The top panel will contain 2 labels and 2 text fields. The text fields should be initialized with a parameter of 8. No special layout manager needed here.
  • The bottom panel will contain 4 buttons. Use a grid layout here with horizontal and vertical gaps of 5.
  • The right panel contains 3 labels and 3 text fields initialized with a parameter of 10. Use a grid layout here with horizontal and vertical gaps of 5.
  • The left panel contains a scrollpane which contains a text area setup for 10 rows and 18 columns. No special layout manager needed here.
  • Place the 4 panels into the frame in the appropriate regions of the frame's border layout.

How the Application Works

A user will enter one value into the voltage text field and one value into the resistance text field. Then the user will click either the Series Resistor or Parallel Resistor button. This action causes the program to store the voltage value and the resistance value and output the voltage and resistance values to the text area as shown in the screen shot above. The user can then place another value into the resistance text field and again click the Series Resistor or Parallel Resistor buttons. This action causes the resistance value to be reported in the text area and the resistance value is used to update the total resistance calculations internally. When the user is finished adding resistors, the user clicks the Calculate Totals button which causes the program to calculate and output the total resistance, current, and power into the appropriate text fields. Clicking the New Circuit button should clear the total resistance, current, and power text fields. It should clear the text area and place the initial instruction to "Enter volts, then resistance values" into the text area.

Event Handling Design

First of all you will need 3 member variables to hold values to be used over the course of the circuit entry. These three member variables are all doubles: one for voltage, one to accumulate total resistance, and one to accumulate resistance of the current parallel part of the circuit.

Second, you will need one nested inner class that implements the ActionListener interface. One object of this class is to be created and added to the 4 buttons as the event handler.

Inside the nested inner class you will have to use if statements to check to see which of the 4 buttons was clicked. The following describes what to do for each of the 4 buttons:

1. New Circuit button: Clear the three text fields for total resistance, power, and current. Set the text area to read "Enter volts, then resistance values.". Set the 3 member variables mentioned above back to 0.

2. Series Resistor button: If the voltage member variable is 0, call a function that gets the voltage value from the voltage text field, reports the voltage value in the text area, and stores the numeric value of the voltage into the voltage member variable. (This function will be called from the next button also.). Get the value of the resistor from the resistor text field and report adding a series resistor in the text area. Convert the value of the resistance to a numeric value and add it to the member variable used to keep track of total resistance. In addition, if the member variable used for accumulating parallel resistance is non-zero, add that to the total resistance member variable, then set the parallel resistance variable to 0.

3. Parallel Resistor button: If the voltage member variable is 0, call a function that gets the voltage value from the voltage text field, reports the voltage value in the text area, and stores the numeric value of the voltage into the voltage member variable. (This function was called from the previous button also.). Get the value of the resistor from the resistor text field and report adding a parallel resistor in the text area. Convert the value of the resistance to a numeric value and if the member variable used to keep track of parallel resistance is 0, set the parallel resistance member variable to this resistance value. If the member variable is not zero, calculate the new parallel resistance value by using the following formula:

R_parallel = (R_parallel * new_resistance) / (R_parallel + new_resistance)

4. Calculate Totals button: If the parallel resistance member variable is not 0, add it to the total resistance member variable and set the parallel resistance variable to 0. Output the total resistance member variable to the total resistance text field with 3 digits after the decimal point. Use String.format! Output the current to the total current text field by calculating the current as voltage / total resistance. Also use String.format to set the output to 3 digits after the decimal point. Finally, output the power to the total power text field by calculating the power as (voltage * voltage) / total resistance. Also use String.format to set the output to 3 digits after the decimal point. The output should appear as shown in the screen shot above.

Java, Programming

  • Category:- Java
  • Reference No.:- M91382493
  • Price:- $30

Guranteed 24 Hours Delivery, In Price:- $30

Have any Question?


Related Questions in Java

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As