Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives: Creating GUI Components Learning the Basic components for GUI Submis

ID: 3530975 • Letter: O

Question

Objectives: Creating GUI Components Learning the Basic components for GUI Submission Instructions: Create a new Net Beans project called Homework4_youraame" to hold the solutions for this homework. the solution to the problem should be contained within a separate file called Employee. Submit the project to BB. Any project submitted later than 11: 58PM. on Tuesday, February 28th not be accepted by BB. Pay Calculator In this Assignment, you will design and write a GUI program to calculate pay for different types of employees. Your program should have the following components: Combo box to select the type of employee. Two text fields to input the number of hours worked and pay rate. A button to calculate the total pay. Labels where appropriate. the types of employees are as follows: Salaried - the se employees do not get paid by the hour and earn $2000 plus a weekly bonus. Use a JOptionPane to ask for the weekly bonus. Hourly - the se employees are paid a certain amount per hour. Any work over 40 hours is paid at time and a half Volunteer - the se employees do not get paid anything. If Salaried or Volunteer is selected in the combo box, the hours and rate text fields should be disabled, as the y are not needed. Whenever the employee type is changed, the hours text field should reset to 0 and the rate text field should reset to 0. 0. If the calculate button is pressed when no employee type is selected, use a JOptionPane to tell the user to select an employee type.

Explanation / Answer

Hey check it out....


package paycalculator;

import javax.swing.JFrame;

import javax.swing.JComboBox;

import javax.swing.JButton;

import javax.swing.JTextField;

import javax.swing.JOptionPane;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.SwingUtilities;


import java.awt.event.*;

public class PayCalculatorClass extends JFrame {


/**

* @param args

*/

JFrame frame=null;

JButton button=null;

JTextField jt=null;

JTextField jt1=null;

JOptionPane jp=null;

JLabel jl=null;

JLabel jl1=null;

JLabel jl2=null;

JComboBox jc=null;

JPanel mainPanel=null;

public PayCalculatorClass()

{

init();

}

public void init()

{

String[] employeeType={"Select Employee Type","Salaried","Hourly","Volunteer"};

frame=new JFrame();

frame.setSize(400,200);

frame.setDefaultCloseOperation(EXIT_ON_CLOSE);

jc=new JComboBox(employeeType);

jt=new JTextField(5);

jt1=new JTextField(5);

jl1=new JLabel();

jl2=new JLabel();

jl=new JLabel();

mainPanel=new JPanel();

mainPanel.setSize(400,200);

jl1.setText("HOUR :");

jl2.setText("RATE :");

button=new JButton("Calculate Pay");

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

String s=(String)jc.getSelectedItem();

System.out.println(s);

if(s.equals("Salaried"))

{

JOptionPane.showInternalConfirmDialog(frame,

"These Employee will get $2000 Pay per week", "information",

JOptionPane.CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

}

else if(s.equals("Hourly"))

{

int hour=Integer.parseInt(jt.getText());

double rate=Double.parseDouble(jt.getText());

int extrawork=0;

if(hour > 40)

{

extrawork=hour-40;

}

jl.setText("Pay :"+(extrawork * rate ));

}

else if(s.equals("Volunteer"))

{

JOptionPane.showInternalConfirmDialog(null,

"These Emplpoyees have no bonus", "information",

JOptionPane.CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);

}

else

{

}

}

});

mainPanel.add(jc);

mainPanel.add(jl1);

mainPanel.add(jt);

mainPanel.add(jl2);

mainPanel.add(jt1);

mainPanel.add(button);

mainPanel.add(jl);

frame.add(mainPanel);

frame.setVisible(true);

}

public static void main(String[] args) {

// TODO Auto-generated method stub

SwingUtilities.invokeLater(new Runnable() {

public void run() {

PayCalculatorClass ex = new PayCalculatorClass();

ex.setVisible(true);

}

});


}


}