Write a java gui application to calculate total resistance

Assignment Help JAVA Programming
Reference no: EM13812553

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.

Reference no: EM13812553

Questions Cloud

How you affecting your weight given information described : Compare and contrast the effect of these results on personal weight in general and the ideas you have about having good health. How might you be affecting your weight given the information described.
Discuss the pros and cons of doing business with the governm : You are a contracting specialist with the government. You are assigned to assist the chief information officer's team with procuring information technology software and services.  You schedule a call with the program specialist who informs you she fi..
Write the balanced equation of the reaction of o2 : Write the balanced equation of the reaction of O2 with vitamin C and determine the potential of the reaction. is the reaction spontaneous? explain.
How many grams of methane gas (ch4) : How many grams of methane gas (CH4) need to be combusted to produce 18.2 L water vapor at 1.2 atm and 275 K? Show all of the work used to solve this problem. CH4 (g) + 2 O2 (g) CO2 (g) + 2 H2O (g)
Write a java gui application to calculate total resistance : Write a Java GUI application to calculate total resistance, current, and power in a circuit.
What is the molar mass of gas : A sample of gas at 310 Kelvin and 1.2 atmospheres has a density of 2.78 g/L, what is the molar mass of this gas? Show all of the work used to solve this problem.
Write a summary and response paper about the given article : Write a summary and response paper about the article "The Worst Mistake In The History of The Human Race" by Jared Diamond.
Cholesterol in blood is measured in milligrams of cholestero : Cholesterol in blood is measured in milligrams of cholesterol per deciliter of blood. If the average adult has 6.0 liters of blood, how many grams of cholesterol would be in the blood of an average adult with a cholesterol reading of 185 mg/dL? Densi..
How has technology affected marketing : How has technology affected marketing

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd