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

  1 rock-paper-scissors simplejavaproblems 1-3 are based on

1 rock-paper-scissors simple.javaproblems 1-3 are based on the rock-paper-scissors game. if you are unfamiliar with

  Given the following data definition classpublic class exam

given the following data definition classpublic class exam private static int totalpublic static void settotalint t

  Design an object hierarchy

Design an object hierarchy and design your own UML class diagram to reflect the classes and relationship required by your program.

  Program produces 1000 integer ranging

Then your program produces 1000 integer ranging from 1to 10000 in the array and then sort them in ascending order and then print the result into data.txt file. (You may list integers separated by space or new line)

  Which announces whether or not the player has won the game

2D graphics, instead of text, to display the Xs and Os in the grids of the square- shaped buttons decision logic or recursion in order to determine whether or not a player wins the games. Display a message which announces whether or not the player ha..

  Accounts receivable system appication

A common business application is an 'Accounts Receivable' (AR) system. Companies use an AR system to bill their customers on sales of their products

  These are more specialized versions of the pizzaorders you

your pizza shop expands and now handles delivery orders and sit down orders in a restaurant setting. there are

  Complete the code found in player.java

You are to complete the code found in Player.java. Once completed you can then simulate a good old game of Rock, Paper, Scissors. To play you need to compile Player.java, InputMaker.java, and RockPaperScissorsTest.java. Then you will run InputMake..

  Write a java class that reads through a text file

You will write a Java class that reads through a text file of drawing commands and draws the appropriate shapes onto JFrames

  Find the nth largest of 2 sorted arrays of length n

In java, use divide and conquer to find the nth largest of 2 sorted arrays of length n.

  Implement 4 sorting algorithms in a java "sort" class.

Implement 4 sorting algorithms in a Java " Sort " class. ( insertion sort, selection sort and quicksort, and mergesort). count the number of comparisons made.

  Write a program to test your class definition

Do not define an input method. The only method that can set the counter is the one that sets it to zero. Write a program to test your class definition.

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