package finalproject;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Interface extends JFrame implements ActionListener{
private final int FRAME_WIDTH = 1024;
private final int FRAME_HIGHT = 768;
private final int FRAME_X_ORIGIN = 150;
private final int FRAME_Y_ORIGIN = 200;
private String numberStr;
private JTextField FirstNameFiled = new JTextField();
private JTextField LastNameFiled = new JTextField();
private JTextField AddressFiled = new JTextField();
private JTextField AgeFiled = new JTextField();
private Container ContentPane = getContentPane();
public Interface() {
SetWindow();
Buttons();
TextField();
Lable();
}
private void SetWindow() {
this.setTitle("Final Project");
this.setSize(FRAME_WIDTH, FRAME_HIGHT);
this.setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.setResizable(false);
}
private void Buttons() {
JButton ExitButton, SaveButton, LoadButton;
ExitButton = new JButton("Exit");
ExitButton.setActionCommand("Exit");
ExitButton.setLocation(10, 140);
ExitButton.setSize(95, 25);
ExitButton.addActionListener(this);
ContentPane.add(ExitButton);
SaveButton = new JButton("Save File");
SaveButton.setActionCommand("Save_File");
SaveButton.setLocation(110, 140);
SaveButton.setSize(95, 25);
SaveButton.addActionListener(this);
ContentPane.add(SaveButton);
LoadButton = new JButton("Load File");
LoadButton.setActionCommand("Load_File");
LoadButton.setLocation(210, 140);
LoadButton.setSize(95, 25);
LoadButton.addActionListener(this);
ContentPane.add(LoadButton);
}
private void Lable() {
JLabel FirstNameLabel = new JLabel();
FirstNameLabel.setText("First Name: ");
FirstNameLabel.setSize(100,20);
FirstNameLabel.setLocation(10, 10);
ContentPane.add(FirstNameLabel);
JLabel LastNameLabel = new JLabel();
LastNameLabel.setText("Last Name: ");
LastNameLabel.setSize(100,20);
LastNameLabel.setLocation(240, 10);
ContentPane.add(LastNameLabel);
JLabel AddressLabel = new JLabel();
AddressLabel.setText("Address: ");
AddressLabel.setSize(100,20);
AddressLabel.setLocation(10, 50);
ContentPane.add(AddressLabel);
JLabel AgeLabel = new JLabel();
AgeLabel.setText("Age: ");
AgeLabel.setSize(100, 20);
AgeLabel.setLocation(240, 50);
ContentPane.add(AgeLabel);
}
private void TextField() {
FirstNameFiled.setActionCommand("FirstNameFiled");
FirstNameFiled.setText("First Name");
FirstNameFiled.setSize(100, 25);
FirstNameFiled.setLocation(85, 9);
FirstNameFiled.addActionListener(this);
ContentPane.add(FirstNameFiled);
LastNameFiled.setActionCommand("LastNameFiled");
LastNameFiled.setText("Last Name");
LastNameFiled.setSize(100, 25);
LastNameFiled.setLocation(315, 9);
LastNameFiled.addActionListener(this);
ContentPane.add(LastNameFiled);
AddressFiled.setActionCommand("AddressFiled");
AddressFiled.setText("Address");
AddressFiled.setSize(100, 25);
AddressFiled.setLocation(85, 48);
AddressFiled.addActionListener(this);
ContentPane.add(AddressFiled);
AgeFiled.setActionCommand("AgeFiled");
AgeFiled.setText("Age");
AgeFiled.setSize(100, 25);
AgeFiled.setLocation(315, 48);
AgeFiled.addActionListener(this);
ContentPane.add(AgeFiled);
}
public void actionPerformed(ActionEvent Action) {
if(Action.getActionCommand().contains("Exit"))
System.exit(0);
if(Action.getActionCommand().equals("Save_File")) {
System.out.print("Saving File");
}
if(Action.getActionCommand().equals("Load_File")) {
System.out.print("Loading File");
}
if (Action.getActionCommand().contains("FirstNameFiled")) {
numberStr = FirstNameFiled.getText();
}
if (Action.getActionCommand().contains("LastNameFiled")) {
numberStr = LastNameFiled.getText();
}
if (Action.getActionCommand().contains("AddressFiled")) {
numberStr = AddressFiled.getText();
}
if (Action.getActionCommand().contains("AgeFiled")) {
numberStr = AgeFiled.getText();
}
}
}