Concept explainers
Design and code a Swing GUI calculator. You can use Display 17.19 as a starting point, but your calculator will be more sophisticated. Your calculator will have two text fields that the user cannot change: One labeled "Result" will contain the result of performing the operation, and the other labeled "Operand" will be for the user to enter a number to be added, subtracted, and so forth from the result. The user enters the number for the "Operand" text field by clicking buttons labeled with the digits o through 9 and a decimal point, just as in a real calculator. Allow the operations of addition, subtraction, multiplication, and division. Use a GridLayout manager to produce a button pad that looks similar to the keyboard on a real calculator.
When the user clicks a button for an operation, the following occurs: the operation is performed, the "Result" text field is updated, and the "Operand" text field is cleared. Include a button labeled "Reset" that resets the "Result" to 0.0. Also include a button labeled "Clear" that resets the "Operand" text field so it is blank.
number in the "Operand" text field. Because values of type double are, in effect, approximate values, it makes no sense to test for equality with 0.0. Consider an operand to be "equal to zero" if it is in the range
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Modern Database Management
Computer Systems: A Programmer's Perspective (3rd Edition)
Concepts Of Programming Languages
C How to Program (8th Edition)
C Programming Language
Starting Out with Java: From Control Structures through Objects (6th Edition)
- Write a GUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values. These components should be arranged in a grid where the labels occupy the first row and the corresponding fields occupy the second row. At start-up, the Fahrenheit field should contain 32.0, and the Celsius field should contain 0.0. The third row in the window contains two command buttons, labeled >>>> and <<<<. When the user presses the first button, the program should use the data in the Celsius field to compute the Fahrenheit value, which should then be output to the Fahrenheit field. The second button should perform the inverse function. Be sure to use the field names provided in the comments in your starter code. An example of the program is shown below:arrow_forwardFor this task, you need to develop a JavaFX application in NetBeans that implements a LinkedHashMap class. The Java application should consist of a graphical user interface that can be used to add elements to the LinkedHashMap. There should be two TextFields to take in the element name and number. Then there should be four buttons to do four tasks, namely: add, change, remove and show all elements in the LinkedHashMap. Your buttons should have Action methods and should make use of methods in the LinkedHashMap class.When the Add button is clicked, the element name and value should be added to the LinkedHashMap. Make use of the LinkedHashMap methods to add the elements. When the user fills in the element name and number and the Add button is clicked, a message should be displayed in an alert dialog box to the user to inform them of this If no element is specified at the time the Add button is clicked, an error message should be displayed to inform the user to enter the elementarrow_forwardCreate an enumeration named Month that holds values for the months of the year, starting with JANUARY equal to 1. (Recall that an enumeration must be placed within a class but outside of any method.) Write a GUI program named MonthNamesGUl that prompts the user for a month integer. Convert the users entry to a Month value, and display it.arrow_forward
- Recreate the following GUI in JavaFX: 2. In JavaFX, implement the functionality of making a popup appear on the screen when the 'Addworkshop' button is pressed. The popup should contain the message: 'Maximum number of workshopsreached.'arrow_forwardWrite a GUI in Java that will let the user sample borders. Include a menu named Borders that offers three options—beveled border, etched border, and line border—as submenus with the following options: • Beveled-border submenu options: raised or lowered. • Etched-border submenu options: raised or lowered. • Line-border submenu options: small, medium, or large. Each of these options should be a submenu with three color options: black, red, and blue. Put the borders around a label containing text that describes the border, such as Raised Border, Lowered Etched Border, and so forth. Fix the highlight and shadow colors for the etched-border options to whatever colors you like, and make the small line border 5 pixels wide, the medium one 10 pixels wide, and the large one 20 pixels widearrow_forwardWrite a GUI in Java that will let the user sample borders. Include a menu named Borders that offers three options—beveled border, etched border, and line border—as submenus with the following options: • Beveled-border submenu options: raised or lowered. • Etched-border submenu options: raised or lowered. • Line-border submenu options: small, medium, or large. Each of these options should be a submenu with three color options: black, red, and blue.Put the borders around a label containing text that describes the border, such as Raised Border, Lowered Etched Border, and so forth. Fix the highlight and shadow colors for the etched-border options to whatever colors you like, and make the small line border 5 pixels wide, the medium one 10 pixels wide, and the large one 20 pixels wide.arrow_forward
- Using JavaFX with Eclipse or Netbeans, please explain using a main class, controller class, and a FXML... Devise a JavaFX GUI with an internal controller class to maintain an array of arbitrary size. Use a starting default of size 20 and populate it with random data (numbers) initialized into the array. The GUI should be such that users can select and perform the actions listed below. Write methods and select appropriate GUI mechanisms to do the following: 1. Display the contents of the array2. Add a, or a group of numbers to the array at any position.3. Delete a number from the array at any position.4. Sort the array and display the original and sorted forms.5. Display the size of the array.6. Search for a number and its occurrences in the array and flag that number’s position(s) by highlighting it in the display.arrow_forwardUsing comments within the code itself, can you provide an line by line explanation of the below JavaScript file? The file itself deals with WebGl and if that helps you. Please and thank you JavaScript file: function mat2() { var out = new Array(2); out[0] = new Array(2); out[1] = new Array(2); switch ( arguments.length ) { case 0: out[0][0]=out[3]=1.0; out[1]=out[2]=0.0; break; case 1: if(arguments[0].type == 'mat2') { out[0][0] = arguments[0][0][0]; out[0][1] = arguments[0][0][1]; out[1][0] = arguments[0][1][0]; out[1][1] = arguments[0][1][1]; break; } case 4: out[0][0] = arguments[0]; out[0][1] = arguments[1]; out[1][0] = arguments[2]; out[1][1] = arguments[3]; break; default: throw "mat2: wrong arguments"; } out.type = 'mat2'; return out; } //---------------------------------------------------------------------------- function mat3() { // v = _argumentsToArray( arguments ); var out = new Array(3); out[0] = new Array(3); out[1] = new Array(3); out[2] = new Array(3);…arrow_forwardIn this lab, you will use a timer to animate the movement of a heart image to the location where the mouse clicks, as shown below. In jacascript, please! The given web page shows a heart image. When the user clicks anywhere in the page, the startAnimation() function is called. startAnimation() determines where the user clicked and calls moveImage() with the clicked (x, y) coordinate. moveImage() moves the heart 1 pixel in the direction of the given (x, y) coordinates. Make the following JavaScript modifications using clearInterval() and setInterval() where appropriate: In startAnimation(), add an if statement that stops the timer with the ID timerId if timerId is not null. In startAnimation(), start a timer that calls moveImage(clickX, clickY) every 10 milliseconds. Save the timer ID in the timerId variable. Add an if statement in moveImage() that stops the timer with the ID timerId if (imgX, imgY) is equal to (centerX, centerY). Also set timerId to null. After the…arrow_forward
- Write an application creating a GUI which diplays a panel with elements of graphics and text. Sliders allow to modify their color (red, green, blue components) and the bacground color. The interface may look like the one below, but can be different as long as its functionality is preserved.arrow_forwardIn Blue j Create a new class named Scene.Add a main method to the Scene class that simply creates a new Scene object Add a public method named animate that has no parameter variables and returns nothing. Add two House fields to Scene. Call them house1 and house2.Add a sun field that can reference a Circle object. Add a moon field that can reference a Circle object. Create a no-arg constructor for the Scene class that creates the two House objects shown in the imagebelow. Use the methods you created in the preceding activity to position and color the houses exactlyas in the image. We will adopt the convention that house1 refers to the left house and house2 refersto the right house. Add a sun to the upper-left corner of the scene. (Create the sun object and set the color, position, andsize in the no-arg constructor.) When you run main, what appears in the resulting image should match the above…arrow_forwardWrite a JavaFX application that creates polyline shapes dynamically using mouse clicks. Each mouse click adds a new line segment to the current polyline from the previous point to the current mouse position. Allow the user to end the current polyline with the double click. And provide a button that clears the window and allows the user to begin again.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,