LAB ASSIGNMENT TEMPLATE SUBMITTAL Name

LAB ASSIGNMENT TEMPLATE SUBMITTAL
Name:PrashanthCourse:ITM 311
Assignment: Lab No. 11
Date:11.24.18Project 1: Describe the purpose of the project
Source Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SimpleGUI extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
JLabel l1, l2, l3;
JButton b1;
JTextField t1, t2, t3;

SimpleGUI()
{
l1 = new JLabel(” INPUT 1″);
l2 = new JLabel(” INPUT 2″);
l3 = new JLabel(” OUTPUT”);
b1 = new JButton(“BUTTON 1”);
t1 = new JTextField(10);
t2 = new JTextField(10);
t3 = new JTextField(10);

add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
b1.addActionListener(this);

setSize(500,300);
setLayout(new GridLayout(4,2));
setTitle(“Simple Java GUI”);
}
public void actionPerformed(ActionEvent ae)
{
float a, b, c;
if(ae.getSource() == b1)
{
a = Float.parseFloat(t1.getText());
b = Float.parseFloat(t2.getText());
c = a + b;
t3.setText(String.valueOf(c));
}
}
public static void main(String args)
{
SimpleGUI a = new SimpleGUI();
a.setVisible(true);
a.setLocation(200, 200);
}
}
Snippet of Output(s)

Modified Source Code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SimpleGUI extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
JLabel l1, l2, l3, l4, l5;
JButton b1, b2;
JTextField t1, t2, t3, t4;
JCheckBox check1;

SimpleGUI()
{
l1 = new JLabel(” Current Salary”);
l2 = new JLabel(” Percent Rate”);
l3 = new JLabel(” New Salary”);
l4 = new JLabel(” “);
l5 = new JLabel(” Difference”);
check1 = new JCheckBox(“bonus pay”);
check1.setSelected(true);
b1 = new JButton(“COMPUTE”);
b2 = new JButton(“EXIT”);
t1 = new JTextField(10);
t2 = new JTextField(10);
t3 = new JTextField(10);
t4 = new JTextField(10);

add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(check1);
add(l4);
add(l5);
add(t4);
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(e -> System.exit(0));

setSize(500,300);
setLayout(new GridLayout(6,2));
setTitle(“Salary Calculator”);
}
public void actionPerformed(ActionEvent ae)
{
float x, y, z;
if(ae.getSource() == b1)
if (check1.isSelected())
{
x = Float.parseFloat(t1.getText());
y = Float.parseFloat(t2.getText());
z = x * (y/100) + x + 500;
t3.setText(String.valueOf(z));
t4.setText(String.valueOf(z – x));
}
else {
x = Float.parseFloat(t1.getText());
y = Float.parseFloat(t2.getText());
z = x * (y/100) + x;
t3.setText(String.valueOf(z));
t4.setText(String.valueOf(z – x));
}
}

public static void main(String args)
{
SimpleGUI a = new SimpleGUI();
a.setVisible(true);
a.setLocation(200, 200);
}
}
Snippet of Output(s)

Excel Snapshot(s) if required (whenever there are calculations to be made by the program code)

Answers to the Five Questions located at the end of the lab.How would you modify the GUI to incorporate federal and state taxes (that would be subtracted from the gross salary)?
Ans) The GUI can show be tweaked in such a way that federal and state tax can be included in the row
Explain the use of each term in
private static final long serialVersionUID = 1L;
Private : is an access modifier that restricts other classes to access the values of variables.

Static: makes all the value of the static shared across all the instances of static.

Final: the value is constant until the program is executed
Long: is a data type
serialVersionUID = 1L is used for deserialization3)Why is it important to label a button object?
Ans) it is important to label a button object as it represents the function . 4) Explain the use of each term in
public class SimpleGUI extends JFrame implements ActionListenerpublic : is an access modifier that allows other classes to access the class
SimpleGUI : is the class name
Extends J frame: it means SingleGUI is the child class and extending a parent class called JframeImplements Action listener is just calling that would be the listener it is an event object for a button click.

5) What code would you use to have a radiobutton added to the interface?
Ans) JRadioButton g4 = new JRadioButton