/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package payroll;
/**
*
* @author SUSER2
*/
public class pay extends javax.swing.JFrame {
/**
* Creates new form pay
*/
public pay() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
name = new javax.swing.JLabel();
hours = new javax.swing.JLabel();
wage = new javax.swing.JLabel();
calculate = new javax.swing.JButton();
clear = new javax.swing.JButton();
nameInput = new javax.swing.JTextField();
hourInput = new javax.swing.JTextField();
wageInput = new javax.swing.JTextField();
resultTextField = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
name.setText("Name: ");
hours.setText("How many hours did you work: ");
wage.setText("What is your hourly wage: ");
calculate.setText("Calculate");
calculate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
calculateActionPerformed(evt);
}
});
clear.setText("Clear");
clear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearActionPerformed(evt);
}
});
resultTextField.setEditable(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(name)
.addGap(138, 138, 138)
.addComponent(nameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(hours)
.addComponent(wage))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(resultTextField)
.addComponent(hourInput)
.addComponent(wageInput))))
.addContainerGap(88, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(calculate)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clear)
.addGap(28, 28, 28))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(name)
.addComponent(nameInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hours)
.addComponent(hourInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(wage)
.addComponent(wageInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(40, 40, 40)
.addComponent(resultTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(calculate)
.addComponent(clear))
.addGap(31, 31, 31))
);
pack();
}// </editor-fold>
private void clearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void calculateActionPerformed(java.awt.event.ActionEvent evt) {
double othours, totalpay, pay, otwage, otpay;
String num1Str = hourInput.getText();
String num2Str = wageInput.getText();
String totalpayStr;
double num1 = Double.parseDouble(num1Str);
double num2 = Double.parseDouble(num2Str);
if (num1 <= 40) {
totalpay = num1 * num2;
} if (40 < num1) {
pay = num1 * num2;
othours = 40 - num1;
otwage = num2 * 1.5;
otpay = otwage * othours;
totalpay = otpay + pay;
}
double result = totalpay;
String resultStr = Double.toString(result);
resultTextField.setText(resultStr);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(pay.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(pay.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(pay.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(pay.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new pay().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton calculate;
private javax.swing.JButton clear;
private javax.swing.JTextField hourInput;
private javax.swing.JLabel hours;
private javax.swing.JLabel name;
private javax.swing.JTextField nameInput;
private javax.swing.JTextField resultTextField;
private javax.swing.JLabel wage;
private javax.swing.JTextField wageInput;
// End of variables declaration
}