First java
package a;
abstract class Employee{
private String staffID;
private String name;
public Employee(String staffID, String name) {
this.staffID = staffID;
this.name = name;
}
public String getStaffID() {
return staffID;
}
public void setStaffID(String staffID) {
this.staffID = staffID;
}
public String getName() {
return name + "EM";
}
public void setName(String name) {
this.name = name;
}
}
Second java
package a;
class Manager extends Employee{
private int salary;
public Manager(String staffID, String name, int salary) {
super(staffID, name);
this.salary = salary;
}
}
The GUI java
package a;
import java.io.*;
java.awt.*;
java.awt.event.*;
import javax.swing.*;
public class Gui extends JFrame implements ActionListener{
private JLabel l1, l2;
private JTextField i1,i2;
private JButton b1;
String string = "";
public Gui(){
super("Title");
Container container = getContentPane();
container.setLayout(null);
l1 = new JLabel("Staff ID:");
l1.setBounds(65, 31, 46, 14);
container.add(l1);
l2 = new JLabel("Name:");
l2.setBounds(65, 115, 46, 14);
container.add(l2);
i1 = new JTextField(20);
i1.setBounds(120,31,250,20);
container.add(i1);
i2 = new JTextField(20);
i2.setBounds(120,115,250,20);
container.add(i2);
b1 = new JButton("add m");
b1.setBounds(30,390,120,30);
container.add(b1);
addMButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Employee emp[] = new Manager(i1.getText(),i2.getText());
string = "Staff Id:" + Emp[].getstaffID +"Name: "+ Emp[].getName();
try{
String data = "Staff.txt";
BufferedWriter reader = new BufferedWriter(new FileWriter(data));
reader.write(string);
reader.newLine();
reader.close();
}catch (IOException E){
System.out.println("Error is " + E);
}
}
});
setSize(600,600enter code here);
setVisible(true);
}
public static void main (String args[]){
Gui application = new Gui();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
}
}
E.g the Id is A1234567 and the name is Tom Lee. How can I insert those data by the constructor?
I am a beginner and I know that there are some common mistake hopeful, someone can correct my mistake.. thanks a lot