PROJECT WORK
Mr. Pawan works as a programmer in “ABC Marketing Company” where
he has designed a Salary generator software to generate the salary of
salesman in which Name and Salary are entered by the user. A screenshot
of the same is shown below:
Help him in writing the code to do the following:
i. After selecting appropriate Radio Button, when ‘Commission’
button is clicked, commission should be displayed in the respective
text field as each Salesman will get a commission based on the
units sold according to the following criteria:
UNIT COMMISION
SOLD (In Rs)
1 to 20 500
21 to 40 1000
>40 2000
ii. When ‘Gross Salary’ button is clicked, Gross Salary should be
calculated and displayed in the respective text field as per the
given formula: Gross Salary= Salary + Commission
iii. After required selection of Checkbox(es), when ‘Facility Charges’
button is clicked, Facility charges will be displayed in the
respective text field according to the following criteria:
Facility Charges
Transport 500
Mess 2000
iv. Money will be deducted from the Gross Salary according to the
facilities opted by the employee. When ‘Net Salary’ button is
clicked, Net Salary should be calculated and displayed in the
respective text field as per the given formulae: Net Salary= Gross
Salary-Deductions
Solution :
public class NewJFrame extends javax.swing.JFrame
{
/** Creates new form NewJFrame */
public NewJFrame() {
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() {
buttonGroup1 = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
tt = new javax.swing.JTextField();
ai = new javax.swing.JRadioButton();
cc = new javax.swing.JRadioButton();
de = new javax.swing.JRadioButton();
c1 = new javax.swing.JCheckBox();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
t1 = new javax.swing.JTextField();
t2 = new javax.swing.JTextField();
t3 = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLO
SE);
setName("Form"); // NOI18N
org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(desktopapplication14.Des
ktopApplication14.class).getContext().getResourceMap(NewJFrame.class);
jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
jLabel2.setName("jLabel2"); // NOI18N
tt.setText(resourceMap.getString("tt.text")); // NOI18N
tt.setName("tt"); // NOI18N
buttonGroup1.add(ai);
ai.setFont(resourceMap.getFont("ai.font")); // NOI18N
ai.setText(resourceMap.getString("ai.text")); // NOI18N
ai.setName("ai"); // NOI18N
ai.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aiActionPerformed(evt);
}
});
buttonGroup1.add(cc);
cc.setFont(resourceMap.getFont("cc.font")); // NOI18N
cc.setText(resourceMap.getString("cc.text")); // NOI18N
cc.setName("cc"); // NOI18N
buttonGroup1.add(de);
de.setFont(resourceMap.getFont("de.font")); // NOI18N
de.setText(resourceMap.getString("de.text")); // NOI18N
de.setName("de"); // NOI18N
c1.setFont(resourceMap.getFont("c1.font")); // NOI18N
c1.setText(resourceMap.getString("c1.text")); // NOI18N
c1.setName("c1"); // NOI18N
jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
jButton1.setName("jButton1"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setFont(resourceMap.getFont("jButton2.font")); // NOI18N
jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
jButton2.setName("jButton2"); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
jButton3.setName("jButton3"); // NOI18N
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
jLabel3.setName("jLabel3"); // NOI18N
jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
jLabel4.setName("jLabel4"); // NOI18N
jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
jLabel5.setName("jLabel5"); // NOI18N
t1.setText(resourceMap.getString("t1.text")); // NOI18N
t1.setName("t1"); // NOI18N
t2.setText(resourceMap.getString("t2.text")); // NOI18N
t2.setName("t2"); // NOI18N
t3.setText(resourceMap.getString("t3.text")); // NOI18N
t3.setName("t3"); // NOI18N
jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
jLabel6.setName("jLabel6"); // NOI18N
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout
.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupL
ayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(87, 87, 87)
.addGroup(layout.createParallelGroup(javax.swing
.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.Co
mponentPlacement.RELATED)
.addComponent(t1,
javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
.addComponent(t2)
.addComponent(t3)))
.addComponent(jLabel4)
.addComponent(jLabel3)
.addComponent(jButton1)
.addGroup(javax.swing.GroupLayout.Alignment.TR
AILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.Compo
nentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing
.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2,
javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.Co
mponentPlacement.RELATED)
.addComponent(tt,
javax.swing.GroupLayout.PREFERRED_SIZE, 87,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(48, 48, 48))))))
.addGroup(layout.createSequentialGroup()
.addGap(83, 83, 83)
.addGroup(layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.LEADING)
.addComponent(cc)
.addComponent(ai)
.addComponent(de))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlace
ment.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupL
ayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton2)
.addGap(76, 76, 76)
.addComponent(jButton3)
.addGap(19, 19, 19))
.addGroup(layout.createSequentialGroup()
.addComponent(c1,
javax.swing.GroupLayout.PREFERRED_SIZE, 164,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED))))
.addGroup(layout.createSequentialGroup()
.addGap(179, 179, 179)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 227,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(45, 45, 45))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacemen
t.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout
.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupL
ayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlace
ment.UNRELATED)
.addComponent(ai,
javax.swing.GroupLayout.PREFERRED_SIZE, 23,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlace
ment.UNRELATED)
.addComponent(cc)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlace
ment.RELATED)
.addComponent(de)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupL
ayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupL
ayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(t1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlace
ment.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupL
ayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(t2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupL
ayout.Alignment.BASELINE)
.addComponent(t3,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(75, 75, 75)
.addComponent(c1))))
);
pack();
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int s= Integer.parseInt(t2.getText());
int c = Integer.parseInt(t3.ge private void
jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int s= Integer.parseInt(t2.getText());
int c = Integer.parseInt(t3.getText());
int gs=s+c;
t4.setText(""+gs);
}
private void aiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed (java.awt.event.ActionEvent evt) {
if (r1.isSelected()==true)
t3.setText(""+500);
else if (r2.isSelected()==true)
t3.setText(""+1000);
else if (r3.isSelected() ==true)
t3.setText(""+2000);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
if (c1.isSelected()== true)
t5.setText(""+500);
else if (c2.isSelected()== true)
t5.setText(""+1000);
else if ((c1.isSelected()== true) && (c2.isSelected()==true) )
{ int a= 500+1000;
t5.setText(""+a);
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
if (c1.isSelected()== true)
t5.setText(""+500);
else if (c2.isSelected()== true)
t5.setText(""+1000);
else if ((c1.isSelected()== true) && (c2.isSelected()==true) )
{ int a= 500+1000;
t5.setText(""+a);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JRadioButton ai;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JCheckBox c1;
private javax.swing.JRadioButton cc;
private javax.swing.JRadioButton de;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
private javax.swing.JTextField t3;
private javax.swing.JTextField tt;
// End of variables declaration