I
IanH
Hi,
I am currently working on a Payroll Interface. I have been
experimenting with a cardayout view. First, I want to allow employees
to enter their first and last name and to pick how their remuneration
is calculated ie, salary, hourly, commission etc.
At the moment I just have a combo-box that allows each employee to pick
their remuneration type and based on this selection a card is called.
My question is - is it possible to display a Jtextfield for the first
and last name on the interface with the combo-box, and if so how would
i go about it.
any help would be appreciated.
Ian
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PayrollSystem implements ItemListener {
JPanel cards; //a panel that uses CardLayout
final static String HOURLYPANEL = "Hourly";
final static String COMMISSIONPANEL = "Commission";
final static String BASEPLUSPANEL = "BasePlusCommission";
final static String SALARYPANEL = "Salary";
public void addComponentToPane(Container pane) {
//Put the JComboBox in a JPanel to get a nicer look.
JPanel comboBoxPane = new JPanel(); //use FlowLayout
String comboBoxItems[] = { HOURLYPANEL, COMMISSIONPANEL,
BASEPLUSPANEL, SALARYPANEL };
JComboBox cb = new JComboBox(comboBoxItems);
cb.setEditable(false);
cb.addItemListener(this);
comboBoxPane.add(cb);
//Create the "cards".
JPanel card1 = new JPanel();
card1.add(new JLabel("Hours worked"));
card1.add(new JTextField(6));
card1.add(new JLabel("Rate of Pay"));
card1.add(new JTextField(8));
card1.add(new JButton("Submit"));
JPanel card2 = new JPanel();
card2.add(new JLabel("Total Sales"));
card2.add(new JTextField(8));
card2.add(new JLabel("Commission Rate"));
card2.add(new JTextField(8));
card2.add(new JButton("Submit"));
JPanel card3 = new JPanel();
card3.add(new JLabel("Basic Pay"));
card3.add(new JTextField(8));
card3.add(new JLabel("Total Sales"));
card3.add(new JTextField(8));
card3.add(new JLabel("Commision Rate"));
card3.add(new JTextField(8));
card3.add(new JButton("Submit"));
JPanel card4 = new JPanel();
card4.add(new JLabel("Salary"));
card4.add(new JTextField(10));
card4.add(new JButton("Submit"));
//Create the panel that contains the "cards".
cards= new JPanel(new CardLayout());
cards.add(card1, HOURLYPANEL);
cards.add(card2, COMMISSIONPANEL);
cards.add(card3, BASEPLUSPANEL);
cards.add(card4, SALARYPANEL);
pane.add(comboBoxPane, BorderLayout.PAGE_START);
pane.add(cards, BorderLayout.CENTER);
pane.add(comboBoxPane, BorderLayout.PAGE_START);
pane.add(cards, BorderLayout.CENTER);
}
public void itemStateChanged(ItemEvent evt) {
CardLayout cl = (CardLayout)(cards.getLayout());
cl.show(cards, (String)evt.getItem());
}
/**
* GUI created
*
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("Payroll Interface System");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
PayrollSystem demo = new PayrollSystem();
demo.addComponentToPane(frame.getContentPane());
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
I am currently working on a Payroll Interface. I have been
experimenting with a cardayout view. First, I want to allow employees
to enter their first and last name and to pick how their remuneration
is calculated ie, salary, hourly, commission etc.
At the moment I just have a combo-box that allows each employee to pick
their remuneration type and based on this selection a card is called.
My question is - is it possible to display a Jtextfield for the first
and last name on the interface with the combo-box, and if so how would
i go about it.
any help would be appreciated.
Ian
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PayrollSystem implements ItemListener {
JPanel cards; //a panel that uses CardLayout
final static String HOURLYPANEL = "Hourly";
final static String COMMISSIONPANEL = "Commission";
final static String BASEPLUSPANEL = "BasePlusCommission";
final static String SALARYPANEL = "Salary";
public void addComponentToPane(Container pane) {
//Put the JComboBox in a JPanel to get a nicer look.
JPanel comboBoxPane = new JPanel(); //use FlowLayout
String comboBoxItems[] = { HOURLYPANEL, COMMISSIONPANEL,
BASEPLUSPANEL, SALARYPANEL };
JComboBox cb = new JComboBox(comboBoxItems);
cb.setEditable(false);
cb.addItemListener(this);
comboBoxPane.add(cb);
//Create the "cards".
JPanel card1 = new JPanel();
card1.add(new JLabel("Hours worked"));
card1.add(new JTextField(6));
card1.add(new JLabel("Rate of Pay"));
card1.add(new JTextField(8));
card1.add(new JButton("Submit"));
JPanel card2 = new JPanel();
card2.add(new JLabel("Total Sales"));
card2.add(new JTextField(8));
card2.add(new JLabel("Commission Rate"));
card2.add(new JTextField(8));
card2.add(new JButton("Submit"));
JPanel card3 = new JPanel();
card3.add(new JLabel("Basic Pay"));
card3.add(new JTextField(8));
card3.add(new JLabel("Total Sales"));
card3.add(new JTextField(8));
card3.add(new JLabel("Commision Rate"));
card3.add(new JTextField(8));
card3.add(new JButton("Submit"));
JPanel card4 = new JPanel();
card4.add(new JLabel("Salary"));
card4.add(new JTextField(10));
card4.add(new JButton("Submit"));
//Create the panel that contains the "cards".
cards= new JPanel(new CardLayout());
cards.add(card1, HOURLYPANEL);
cards.add(card2, COMMISSIONPANEL);
cards.add(card3, BASEPLUSPANEL);
cards.add(card4, SALARYPANEL);
pane.add(comboBoxPane, BorderLayout.PAGE_START);
pane.add(cards, BorderLayout.CENTER);
pane.add(comboBoxPane, BorderLayout.PAGE_START);
pane.add(cards, BorderLayout.CENTER);
}
public void itemStateChanged(ItemEvent evt) {
CardLayout cl = (CardLayout)(cards.getLayout());
cl.show(cards, (String)evt.getItem());
}
/**
* GUI created
*
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("Payroll Interface System");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
PayrollSystem demo = new PayrollSystem();
demo.addComponentToPane(frame.getContentPane());
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}