Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2006

Tip: Looking for answers? Try searching our database.

Gui Interface

Thread view: 
IanH - 29 Mar 2006 22:16 GMT
Hi,
I have posted my code for an 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);
   }

}

//
widernet programmer - 29 Mar 2006 23:09 GMT
This looks remarkably like a Computer Science project. Anyway, you need
to place your interface in a seperate source file-- think of it as a
class. Then, your other classes will implement it. A class can
implement multiple thigns with a comma, such as: implements
ActionListener, Payable. Next, extend JPanel instead of JFrame. Then in
your main(), change it to:

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

Also, change the beginning of the constructor as follows:

       //super(str);
       //construct preComponents
       String[] typeItems = {"Hourly", "Salary", "Commission", "Base
plus Commission"};
       //Container c = getContentPane();
       //c.setLayout(null);
       setSize(850,650);
       //setLocationRelativeTo(null);

Then when the button is used, you want to extract the fields from the
textFields and update the Employee objects, which need to be created
before the button is pushed (either in main(), the constructor, or
write a method to create a new employee that takes the type of employee
as a parameter). The Employee objects will need set and get methods to
set these fields. Use them to update the objects after you create them
with 'new'. If you want display stuff in the 'renumeration' textArea,
place the code between where you get the fields and where you set them
to blanks.
Hope this helps.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.