Question

In: Computer Science

In this question, use your new GUI classes to create a small application. You have 2...

In this question, use your new GUI classes to create a small application. You have 2 options:

Write any small application of your choice, as long as it follows the rules that follow.

Write the small UnitConversion application, which will be described for you.

Option 1: Write your own application

You can write any small application that you like, as long as:

It uses your GUI classes, including:

at least one checkbox,

at least one group of 3 radio buttons,

at least two buttons, one of which is labelled “Quit” and terminates the program. (You can use System.exit(0); to do this anywhere in a program.)

At least one input text box, and at least one output text box.

It must do some sort of calculation or processing that uses the input, and the options specified by the checkboxes and radio buttons, to produce some output that is displayed.

It must be self-explanatory, so that the marker can run it and test it without knowing anything about it other than what is displayed in the window.

Option 2: Write a UnitConverter application

If you have no idea of your own, you can use this one:

Write a simple application that will do conversions between units of temperature, weight, and length, with a GUI interface that looks approximately like the one below. (You don’t have to put things in the same places.)

                                              

The type of conversion is specified by the radio buttons on the right. If the Reverse checkbox is highlighted, then it should do the conversion in the opposite order (F to C instead of C to F for example). It does not have to re-label the radio buttons. The user should be able to type a number into the top box. (Error handling would be nice, but is not required.) When the Calculate button is pressed the answer should appear in the lower text box, with a suitable message as shown. The Quit button should terminate the program.

You can use code from TestA3Q1 or TestA3Q2 as a starting point.

Solutions

Expert Solution

/*

* Converter

*/

import java.awt.*;

import java.util.Scanner;

import java.awt.event.*;

class Converter

{

Converter()

{

Frame f=new Frame("Converter");

f.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e) {

f.dispose();

}

});

Label cl=new Label();

cl.setBounds(700,700,50,100);

cl.setVisible(false);

f.add(cl);

Label l1=new Label("enter input:");

l1.setBounds(50,50,200,50);

f.add(l1);

TextField t1=new TextField();

t1.setBounds(50,100, 200,30);

f.add(t1);

Label l2=new Label("enter convertion type:");

l2.setBounds(50,150,200,50);

f.add(l2);

CheckboxGroup cbg = new CheckboxGroup();

Checkbox checkBox1 = new Checkbox("Temperature(0c->F)", cbg, false);

checkBox1.setBounds(50,200, 150,50);

checkBox1.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {

cl.setText("temperature");

}

});

Checkbox checkBox2 = new Checkbox("Weight(kg->gm)", cbg, false);

checkBox2.setBounds(200,200, 150,50);

checkBox2.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {

cl.setText("weight");

}

});

Checkbox checkBox3 = new Checkbox("length(km->m)", cbg, false);

checkBox3.setBounds(350,200, 150,50);

checkBox3.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {

cl.setText("length");

}

});

f.add(checkBox1);

f.add(checkBox2);

f.add(checkBox3);

Label l3=new Label("output:");

l3.setBounds(50,250,200,50);

f.add(l3);

TextField t2=new TextField();

t2.setBounds(50,300, 200,30);

f.add(t2);

Button b1=new Button("submit");

b1.setBounds(50, 350, 50, 25);

b1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

double input =Integer.valueOf(t1.getText());

String choice=cl.getText();

if(choice.equals("temperature"))

t2.setText(Double.toString(input * 1.8 + 32) );

else if(choice.equals("weight"))

t2.setText(Double.toString(input * 1000) );

else if(choice.equals("length"))

t2.setText(Double.toString(input *1000) );

}

});

f.add(b1);

Button b2=new Button("exit");

b2.setBounds(110, 350, 50, 25);

b2.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

f.dispose();

}

});

f.add(b2);

f.setSize(800,800);

f.setLayout(null);

f.setVisible(true);

}

public static void main(String[] args) {

new Converter();

}

}


Related Solutions

You will design and create your own GUI application for the Bank project. This project should...
You will design and create your own GUI application for the Bank project. This project should be designed and written by Java programming. The requirements of the program: 1. The program will be best implemented as a multi-file program for each class. 2. The parameters and return types of each function and class member should be decided in advance. You may need to add more member variables and functions to the classes than those listed below. Also, you can throws...
Create in java an interactive GUI application program that will prompt the user to use one...
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students” On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
I need a Java application with a GUI that includes the following requirements: Three classes minimum...
I need a Java application with a GUI that includes the following requirements: Three classes minimum At least one class must use inheritance At least one class must be abstract Utilization of “get set” method. (get; set; =  is related to how variables are passed between different classes. The get method is used to obtain or retrieve a particular variable value from a class. A set value is used to store the variables. The whole point of the get and set...
In C# Create a GUI application that calculates and displays the total travel expenses of a...
In C# Create a GUI application that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: Number of days on the trip Amount of airfare, if any Amount of car rental fees, if any Number of miles driven, if a private vehicle was used Amount of parking fees, if any Amount of taxi charges, if any Conference or seminar registration fees, if any Lodging charges, per...
Create a GUI application in C# that calculates and displays the total travel expenses of a...
Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of taxi charges, if any • Conference or seminar...
Create a code where you click on the appropriate buttons on your Python GUI and it...
Create a code where you click on the appropriate buttons on your Python GUI and it turns on and off the corresponding LEDs for Arduino, please.
Python Create a tkinter GUI application that has two buttons on it. The first button should...
Python Create a tkinter GUI application that has two buttons on it. The first button should have in red text the word "Red" on it and the second button should have in blue text the word "Blue" on it. When the red button is clicked you should change the background color of the application window to red and when the blue button is pressed you should change the background color of the application window to blue. You should place your...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT