public class Salary {
public static void main (String [] args) {
int Button_width = 230;
int Button_height = 25;
JLabel IntroLabel = new JLabel (" Welcome to salary sheet");
final JTextField Introtextfield = new JTextField(15);
JLabel Intro2Label = new JLabel ("Please select the employee' name that you would like to edit");
final JTextField Intro2textfield = new JTextField(15);
JButton Name1button = new JButton("Bob Carey");
Name1button.setPreferredSize (new Dimension (Button_width, Button_height));
JButton Name2button = new JButton("Luis Garcia");
Name2button.setPreferredSize (new Dimension (Button_width, Button_height));
JButton Name3button = new JButton("Xavi Alonso");
Name3button.setPreferredSize (new Dimension (Button_width, Button_height));
JButton Name4button = new JButton("Steven Gerrard");
Name4button.setPreferredSize (new Dimension (Button_width, Button_height));
class SaveButtonListener implements ActionListener {
public void actionPerformed (ActionEvent event) {
}
};
JFrame frame = new JFrame ("Salary Sheet");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
u need to create another frame and set its status to viewable. that will show the second window (and this will be done in the event capture method (actionEvent)
So how do i do that. wud u be able to give me an example so wen i press a button another window opens. wats the code?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class employee {
public static void main (String[] args) {
int Button_width = 230;
int Button_height = 25;
JLabel IntroLabel = new JLabel ("Hello");
final JTextField Introtextfield = new JTextField(15);
JFrame frame = new JFrame ("Salary Sheet");
class SaveButtonListener implements ActionListener {
public void actionPerformed (ActionEvent event) {
}
};
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setLayout (new GridLayout (1,2));
frame.add (IntroLabel);
frame.pack ();
frame.show ();
}
}
......................................................................
for the above how do i make it possible to call it to open another button wen i press one of the buttons (Bob Carey), How?
public class Salary extends JFrame implements ActionListener{
public Salary(){
int Button_width = 230;
int Button_height = 25;
JLabel IntroLabel = new JLabel(" Welcome to salary sheet");
final JTextField Introtextfield = new JTextField(15);
JLabel Intro2Label = new JLabel("Please select the employee' name that you would like to edit");
final JTextField Intro2textfield = new JTextField(15);
JButton Name1button = new JButton("Bob Carey");
Name1button.setPreferredSize(new Dimension(Button_width, Button_height));
Name1button.addActionListener(this);
JButton Name2button = new JButton("Luis Garcia");
Name2button.setPreferredSize(new Dimension(Button_width, Button_height));
JButton Name3button = new JButton("Xavi Alonso");
Name3button.setPreferredSize(new Dimension(Button_width, Button_height));
JButton Name4button = new JButton("Steven Gerrard");
Name4button.setPreferredSize(new Dimension(Button_width, Button_height));
wat part of the code to i have to copy again so that wen i press another name it opens??????
AND
is ir possible for my program that wen u press another button the user can create another person? HOW? And that the person inherits everythin the same as the other people there already??
The code below is wat all employees should get?\/
*********************************************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class Employee {
public static void main (String [] args) {
int Button_width = 65;
int Button_height = 25;
JLabel NameLabel = new JLabel ("Name");
final JTextField Nametextfield = new JTextField(15);
JLabel BasicSalaryLabel = new JLabel ("Basic salary:");
final JTextField BasicSalarytextfield = new JTextField (15);
JLabel LunchAllowLabel = new JLabel ("Lunch Allowance:");
final JTextField LunchAllowtextfield = new JTextField (15);
JLabel HousingAllowLabel = new JLabel ("Housing Allowance:");
final JTextField HousingAllowtextfield = new JTextField (15);
JLabel TravelAllowLabel = new JLabel ("Travel Allowance:");
final JTextField TravelAllowtextfield = new JTextField(15);
JLabel BonusLabel = new JLabel ("Bonus:");
final JTextField Bonustextfield = new JTextField(15);
JLabel OvertimeLabel = new JLabel ("Overtime:");
final JTextField Overtimetextfield = new JTextField(15);
JLabel GrossSalaryLabel = new JLabel ("Gross Salary:");
final JTextField GrossSalarytextfield = new JTextField(15);
JButton Savebutton = new JButton("Save");
Savebutton.setPreferredSize (new Dimension (Button_width, Button_height));
JButton Openbutton = new JButton("Open");
Openbutton.setPreferredSize (new Dimension (Button_width, Button_height));
class SaveButtonListener implements ActionListener {
public void actionPerformed (ActionEvent event) {
try {
FileWriter writer = new FileWriter ("data.txt");
PrintWriter out = new PrintWriter (writer);
i did the first bit.
Then do i copy this(below) but just change the name to the other name i have????
AND 2) How wud i call another class to open up in a new window wen i press a button (see Employee). i wanna call that to open wen i press Bob Carey?
if(e.getSource() instanceof JButton ){
JButton jb = (JButton) e.getSource();
if(jb.getText().equals("Bob Carey")){
openNewFrame("This is a second frame.");
}
}
****************************************************
Do u know how o answer my other quetion in which another employee may be added by simply clickin a button??
Last edited by The One; 02-14-2006 at 08:36 AM.
Reason: change
public class Salary extends JFrame implements ActionListener{
public Salary(){
int Button_width = 230;
int Button_height = 25;
JLabel IntroLabel = new JLabel(" Welcome to salary sheet");
final JTextField Introtextfield = new JTextField(15);
JLabel Intro2Label = new JLabel("Please select the employee' name that you would like to edit");
final JTextField Intro2textfield = new JTextField(15);
JButton Name1button = new JButton("Bob Carey");
Name1button.setPreferredSize(new Dimension(Button_width, Button_height));
Name1button.addActionListener(this);
JButton Name2button = new JButton("Luis Garcia");
Name2button.setPreferredSize(new Dimension(Button_width, Button_height));
Name2button.addActionListener(this);
JButton Name3button = new JButton("Xavi Alonso");
Name3button.setPreferredSize(new Dimension(Button_width, Button_height));
JButton Name4button = new JButton("Steven Gerrard");
Name4button.setPreferredSize(new Dimension(Button_width, Button_height));
if(e.getSource() instanceof JButton ){
JButton jb = (JButton) e.getSource();
if(jb.getText().equals("Bob Carey")){
openNewFrame("This is a second frame.");
}
if(jb.getText().equals("Luis Garcia")){
openNewFrame("This is a second frame.");
}
}
}
Bookmarks