Re: Gui Question



Hi,
I have posted my code for the interface if anyone can help. I have to
create an interface for employees pay. I think i need to create an
instance of the object (object names are Employee, SalariedEmployee,
CommissionEmployee and BasePlusCommission)for each type of employee but
not sure.
Ian

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


public interface Payable
{
double getPaymentAmout();
}

public class MyPanel extends JFrame implements ActionListener
{
private JLabel labelfirstname;//
private JTextField first;
private JLabel labellastname;
private JTextField last;
private JLabel labelssn;
private JTextField ssn;
private JLabel labelhoursworked;
private JLabel labelrateofpay;
private JTextField hoursWorked;
private JTextField rateOfPay;
private JLabel labelsalary;
private JTextField salary;
private JLabel labeltotalsales;
private JLabel labelcommission;
private JTextField totalSales;
private JTextField commission;
private JButton buttonSubmit;
private JLabel labeltype;
private JComboBox type;
private JLabel labeltext;
private JTextArea textareaResults;
private JLabel labelrenumeration;

public MyPanel(String str)
{
super(str);

//construct preComponents
String[] typeItems = {"Hourly", "Salary", "Commission", "Base
plus Commission"};

Container c = getContentPane();
c.setLayout(null);
setSize(850,650);
setLocationRelativeTo(null);

//construct components
labelfirstname = new JLabel (" First Name");
add (labelfirstname);
first = new JTextField (5);
add (first);
labellastname = new JLabel (" Last Name");
add (labellastname);
last = new JTextField (5);
add (last);
labelssn = new JLabel (" Social Security Number");
add (labelssn);
ssn = new JTextField (5);
add (ssn);
labelhoursworked = new JLabel (" Hours Worked");
add (labelhoursworked);
labelrateofpay = new JLabel (" Rate of Pay");
add (labelrateofpay);
hoursWorked = new JTextField (5);
add (hoursWorked);
rateOfPay = new JTextField (5);
add (rateOfPay);
labelsalary = new JLabel (" Salary");
add (labelsalary);
salary = new JTextField (5);
add (salary);
labeltotalsales = new JLabel (" Total Sales");
add (labeltotalsales);
labelcommission = new JLabel (" Commission Rate");
add (labelcommission);
totalSales = new JTextField (5);
add (totalSales);
commission = new JTextField (5);
add (commission);
buttonSubmit = new JButton ("SUBMIT");
add (buttonSubmit);
labeltype = new JLabel (" Type of Employee");
add (labeltype);
type = new JComboBox (typeItems);
add (type);
labeltext = new JLabel (" Please fill in only text boxes
appropriate to the type of Employee");
add (labeltext);
textareaResults = new JTextArea (5, 5);
add (textareaResults);
labelrenumeration = new JLabel (" Renumeration");
add (labelrenumeration);
//adjust size and set layout
setPreferredSize (new Dimension (646, 571));
setLayout (null);


//set component bounds (only needed by Absolute Positioning)
labelfirstname.setBounds (15, 31, 72, 25);
first.setBounds (90, 31, 110, 25);
labellastname.setBounds (214, 31, 71, 25);
last.setBounds (285, 31, 100, 25);
labelssn.setBounds (400, 31, 144, 25);
ssn.setBounds (545, 31, 100, 25);
labelhoursworked.setBounds (15, 250, 100, 25);
labelrateofpay.setBounds (225, 250, 76, 25);
hoursWorked.setBounds (110, 250, 100, 25);
rateOfPay.setBounds (305, 250, 100, 25);
labelsalary.setBounds (10, 315, 51, 25);
salary.setBounds (60, 315, 100, 25);
labeltotalsales.setBounds (170, 315, 100, 25);
labelcommission.setBounds (379, 315, 112, 25);
totalSales.setBounds (246, 315, 100, 25);
commission.setBounds (494, 315, 100, 25);
buttonSubmit.setBounds (505, 350, 100, 25);
labeltype.setBounds (15, 110, 110, 20);
type.setBounds (125, 105, 135, 25);
labeltext.setBounds (15, 185, 370, 25);
textareaResults.setBounds (50, 410, 565, 140);
labelrenumeration.setBounds (50, 385, 100, 25);


//register event handlers

buttonSubmit.addActionListener( this );


}//end MyPanel constuctor


//process events

public void actionPerformed( ActionEvent event)
{


if (event.getSource() == buttonSubmit)

{
//Enabling the Text Area's
first.setEnabled (true);
last.setEnabled (true);
ssn.setEnabled (true);
type.setEnabled (true);
hoursWorked.setEnabled (true);
rateOfPay.setEnabled (true);
salary.setEnabled (true);
totalSales.setEnabled (true);
commission.setEnabled (true);


//Setting the Text Area's to Null
first.setText("");
last.setText("");
ssn.setText("");
//type.setText("");
hoursWorked.setText("");
rateOfPay.setText("");
salary.setText("");
totalSales.setText("");
commission.setText("");

}

// create subclass objects


// SalariedEmployee salariedEmployee = new SalariedEmployee;

//HourlyEmployee hourlyEmployee = new HourlyEmployee();

// CommissionEmployee commissionEmployee = new
CommissionEmployee();

//BasePlusCommissionEmployee basePlusCommissionEmployee = new
BasePlusCommissionEmployee();


}



public static void main (String[] args)
{

MyPanel pr = new MyPanel("ww");
pr.show();
//JFrame frame = new JFrame ("MyPanel");
//frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//frame.getContentPane().add (new MyPanel());
//frame.pack();
//frame.setVisible (true);
}
}
//

.


Quantcast