Real-State/LeaseProperty.java
Real-State/LeaseProperty.java
import java.io.Serializable;
public class LeaseProperty implements Serializable{
private String propertyAddress;
private int totalProperties;
private int propertyTaken;
public void cancelLease(){
if (propertyTaken>0)
propertyTaken--;
}
public boolean takeProperty(){
if (propertyTaken propertyTaken++;
return true;
}
else
return false;
}
public int placesLeft(){
return totalProperties - propertyTaken;
}
public int available(){
return totalProperties - propertyTaken;
}
public LeaseProperty(String title, int totCapacity){
this.propertyAddress = title;
this.totalProperties = propertyTaken;
propertyTaken = 0;
}
public LeaseProperty() {
this("Address unknown", 0);
}
public void setPropertyAddress(String propAddress){
this.propertyAddress = propAddress;
}
public void setTotalProperties(int totProperties){
this.totalProperties = totProperties;
}
public String getPropertyAddress() { return propertyAddress;}
public int getTotalProperties() { return totalProperties;}
public int getPropertyTaken() { return propertyTaken;};
public String toString() {
return "\n Property Address: " + getPropertyAddress() + "\n Total Properties: " + getTotalProperties() +
"\n Property Taken: " + getPropertyTaken();
}
}
Real-State/Property.java
Real-State/Property.java
import java.io.Serializable;
public class Property extends PropertyRent implements Serializable{
private final int propertyID_;
private String address_;
private String beds_;
private String propertyType_;
private String rentAmount_;
private String propertyStatus_;
private static int nextPropertyID_ = 1;
public Property(){
propertyID_ = getNextPropertyID_();
setAddress_("Unassigned");
setBeds_("Unassigned");
setPropertyType_("Unassigned");
setRentAmount_("Unassigned");
setPropertyStatus_("Unassigned");
}
public Property(String address, String beds, String pType, String rent, String pStatus){
propertyID_ = getNextPropertyID_();
nextPropertyID_++;
setAddress_(address);
setBeds_(beds);
setPropertyType_(pType);
setRentAmount_(rent);
setPropertyStatus_(pStatus);
}
public int getPropertyID_(){
return propertyID_;
}
public static int getNextPropertyID_(){
if(HomeScreenGUI.propertyAvailable.isEmpty()){
int Id = nextPropertyID_;
nextPropertyID_++;
return Id;
}
else{
int Id = HomeScreenGUI.propertyAvailable.get(HomeScreenGUI.propertyAvailable.size() - 1).getPropertyID_();
return (Id +1);
}
}
public void setAddress_(String address){
address_ = address;
}
public String getAddress_(){
return address_;
}
public void setBeds_(String beds){
beds_ = beds;
}
public String getBeds_(){
return beds_;
}
public void setPropertyType_(String pType){
propertyType_ = pType;
}
public String getPropertyType_(){
return propertyType_;
}
public void setRentAmount_(String rent){
rentAmount_ = rent;
}
public String getRentAmount_(){
return rentAmount_;
}
public void setPropertyStatus_(String pStatus){
propertyStatus_ = pStatus;
}
public String getPropertyStatus_(){
return propertyStatus_;
}
public String toString(){
return "\n" + super.toString()+ "\nProperty ID: " + this.getPropertyID_() + "\nAddress: " + this.getAddress_() +
"\nBeds: " + this.getBeds_() + "\nProperty Type: " + this.getPropertyType_() + "\nRent Amount: " + this.getRentAmount_() +
"\nProperty Status: " + this.getPropertyStatus_();
}
}
Real-State/Tenant.java
Real-State/Tenant.java
import java.io.Serializable;
public class Tenant extends Person implements Serializable {
private final int tenantID;
private String tenantStatus;
private static int nextTenantID = 1;
public Tenant(){
super();
setTenantStatus("Unknown");
tenantID = getNextTenantID();
}
public Tenant(String name, String address, String phone, String pps, String tenStatus){
super(name, address, phone, pps);
tenantID = getNextTenantID();
setTenantStatus(tenStatus);
}
public int getTenantID(){
return tenantID;
}
public static int getNextTenantID(){
if(HomeScreenGUI.tenantsAvailable.isEmpty()){
int Id = nextTenantID;
nextTenantID++;
return Id;
}
else{
int Id = HomeScreenGUI.tenantsAvailable.get(HomeScreenGUI.tenantsAvailable.size() - 1).getTenantID();
return (Id +1);
}
}
public void setTenantStatus(String tenStatus){
tenantStatus = tenStatus;
}
public String getTenantStatus(){
return tenantStatus;
}
public String toString(){
return "\n" + super.toString()+ "\nTenant ID: " + this.getTenantID() + "\nTenant Status: " + this.getTenantStatus();
}
}
Real-State/AmendTenantGUI.java
Real-State/AmendTenantGUI.java
import javax.swing.*;
import java.awt.*;
public class AmendTenantGUI extends JFrame {
private static final int WIDTH = 800;
private static final int HEIGHT = 500;
private JLabel nameL, addressLine1L, addressLine2L, addressLine3L, countyL, tenantPhoneL, tenantPPSL, tenantStatusL, tenantIDL, blankL, blank2L;
private JTextField nameTF, addressLine1TF, addressLine2TF, addressLine3TF, countyTF, tenantPhoneTF, tenantPPSTF, tenantStatusTF, tenantIDTF;
private String[] counties = {"Australia","India","Antrim","Armagh","Carlow","Cavan","Clare","Cork","Derry","Donegal","Down",
"Dublin","Fermanagh","Galway","Kerry","Kildare","Kilkenny","Laois","Leitrim","Limerick","Longford","Louth","Mayo",
"Meath","Monaghan","Offaly","Roscommon","Sligo","Tipperary","Tyrone","Waterford","Westmeath","Wexford","Wicklow"};
private JComboBox countyComboBox;
private JButton addB, cancelB;
public static Tenant tenant_;
public AmendTenantGUI(Tenant tenant){
tenant_ = tenant;
Font myFont = new Font("Times New Roman", Font.BOLD, 20);
nameL = new JLabel("Tenant Name: " , SwingConstants.RIGHT);
addressLine1L = new JLabel("Address Line 1: ", SwingConstants.RIGHT);
addressLine2L = new JLabel("Address Line 2: ", SwingConstants.RIGHT);
addressLine3L = new JLabel("Address Line 3: ", SwingConstants.RIGHT);
countyL = new JLabel("County: ", SwingConstants.RIGHT);
tenantPhoneL = new JLabel("Contact No: ", SwingConstants.RIGHT);
tenantPPSL = new JLabel("Tenant's PPS Number: ", SwingConstants.RIGHT);
tenantStatusL = new JLabel("Tenant Status: ", SwingConstants.RIGHT);
tenantIDL = new JLabel("Tenant's ID Number: ", SwingConstants.RIGHT);
blankL = new JLabel("", SwingConstants.RIGHT);
blank2L = new JLabel("", SwingConstants.RIGHT);
//Text Fields:
nameTF = new JTextField(10);
addressLine1TF = new JTextField(10);
addressLine2TF = new JTextField(10);
addressLine3TF = new JTextField(10);
countyTF = new JTextField(10);
tenantPhoneTF = new JTextField(10);
tenantPPSTF = new JTextField(10);
tenantStatusTF = new JTextField(10);
tenantIDTF = new JTextField(10);
tenantIDTF.setEditable(false);
countyComboBox = new JComboBox(counties);
nameTF.setText(tenant.getName());
addressLine1TF.setText(tenant.getAddress());
tenantPhoneTF.setText(tenant.getPhoneNumber());
tenantPPSTF.setText(tenant.getPpsNumber());
tenantStatusTF.setText(tenant.getTenantStatus());
tenantIDTF.setText(""+tenant.getTenantID());
addB = new JButton("Commit Changes");
addB.setFont(myFont);
addB.setToolTipText("Click to submit details to the system.\n NOTE: Make sure details are correct with landlord");
addB.addActionListener(ae->{
tenant.setName(nameTF.getText());
tenant.setAddress(addressLine1TF.getText());
tenant.setPhoneNumber(tenantPhoneTF.getText());
tenant.setPpsNumber(tenantPPSTF.getText());
tenant.setTenantStatus(tenantStatusTF.getText());
tenantIDTF.setText(""+tenant.getTenantID());
JOptionPane.showMessageDialog(null, "Tenant info updated!");
});
cancelB = new JButton("Cancel");
cancelB.setFont(myFont);
cancelB.addActionListener(ae->{
setVisible(false);
dispose();
});
setLayout(new GridLayout(11, 2));
add(nameL);
add(nameTF);
add(addressLine1L);
add(addressLine1TF);
add(countyL);
add(countyComboBox);
add(tenantPhoneL);
add(tenantPhoneTF);
add(tenantPPSL);
add(tenantPPSTF);
add(tenantStatusL);
add(tenantStatusTF);
add(tenantIDL);
add(tenantIDTF);
add(blankL);
add(blank2L);
add(addB);
add(cancelB);
setTitle("Amend Tenant Details");
setSize(WIDTH, HEIGHT);
setLocationRelativeTo(null);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
toFront();
}
}
Real-State/HomeScreenGUI.java
Real-State/HomeScreenGUI.java
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JComboBox;
import javax.swing.JPanel;
public class HomeScreenGUI extends JFrame {
public static ArrayList
landlordList = new ArrayList<>();
public static ArrayList propertyList = new ArrayList<>();
public static ArrayList propertyLet = new ArrayList<>();
public static ArrayList propertyAvailable = new ArrayList<>();
public static ArrayList tenantsAvailable = new ArrayList<>();
public static ArrayList tenantList = new ArrayList<>();
public static ArrayList rentalList = new ArrayList<>();
JTextArea area;
String[] delPropertyLists = {"Properties Available", "Properties Least Out"};
JComboBox delPropertyLts = new JComboBox(delPropertyLists);
JButton b = new JButton("Enter");
JButton c = new JButton("Cancel");
JLabel delProText = new JLabel("Select Property List to delete from");
String[] tenantLists = {"Tenants Available", "Tenants Not Available"};
JComboBox tenantLts = new JComboBox(tenantLists);
JButton d = new JButton("Enter");
JButton f = new JButton("Cancel");
JLabel tenText = new JLabel("Select Tenant List");
String[] delTenantLists = {"Tenants Available", "Tenants Not Available"};
JComboBox delTenantLts = new JComboBox(delTenantLists);
JButton g = new JButton("Enter");
JButton h = new JButton("Cancel");
JLabel delTenText = new JLabel("Select Tenant List to delete from");
String[] amdTenantLists = {"Tenants Available", "Tenants Not Available"};
JComboBox amdTenantLts = new JComboBox(amdTenantLists);
JButton i = new JButton("Enter");
JButton j = new JButton("Cancel");
JLabel amdTenText = new JLabel("Select Tenant List to delete from");
String searchName;
boolean found = false;
public static void main(String args[]) throws IOException {
HomeScreenGUI ex = new HomeScreenGUI();
ex.setVisible(true);
}
public HomeScreenGUI() {
Image storeImage = Toolkit.getDefaultToolkit().createImage("images/PropertyManagement.png");
createMenuBar();
loadDatabases();
setLayout(new BorderLayout());
setTitle("Real-Estate Agency");
JLabel background = new JLabel(new ImageIcon(storeImage));
add(background);
background.setLayout(new FlowLayout());
setSize(1218, 684);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
area = new JTextArea();
}
private void createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu listMenu;
ImageIcon exitIcon = new ImageIcon("images/exit.png");
ImageIcon addIcon = new ImageIcon("images/add.png");
ImageIcon deleteIcon = new ImageIcon("images/delete.png");
ImageIcon editIcon = new ImageIcon("images/edit.png");
ImageIcon searchIcon = new ImageIcon("images/search.png");
ImageIcon displayIcon = new ImageIcon("images/display.png");
ImageIcon listIcon = new ImageIcon("images/list.png");
ImageIcon saveIcon = new ImageIcon("images/save.png");
ImageIcon aboutIcon = new ImageIcon("images/about.png");
ImageIcon helpIcon = new ImageIcon("images/help.png");
JMenu file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
JMenu landlords = new JMenu("Landlords");
landlords.setMnemonic(KeyEvent.VK_L);
JMenu properties = new JMenu("Properties");
properties.setMnemonic(KeyEvent.VK_P);
JMenu tenants = new JMenu("Tenants");
tenants.setMnemonic(KeyEvent.VK_T);
JMenu rentals = new JMenu("Rentals");
rentals.setMnemonic(KeyEvent.VK_R);
JMenu help = new JMenu("Help");
help.setMnemonic(KeyEvent.VK_H);
JMenuItem save = new JMenuItem(" Save", saveIcon);
save.setMnemonic(KeyEvent.VK_S);
save.setToolTipText("Save any new changes made to the system");
save.addActionListener(ae -> {
saveDatabases();
System.out.println("Save clicked");
});
JMenuItem exit = new JMenuItem(" Exit", exitIcon);
exit.setMnemonic(KeyEvent.VK_E);
exit.setToolTipText("Exit application");
exit.addActionListener(ae -> {
System.out.println("Exit option clicked");
String message = " Would you like to save any changes made to the database? ";
String title = "Quit";
int confirm = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_CANCEL_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
saveDatabases();
JOptionPane.showMessageDialog(null, "Database updated. Goodbye");
System.exit(0);
} else if (confirm == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "Database not updated. Goodbye");
System.exit(0);
}
}
);
file.add(save);
file.addSeparator();
file.add(exit);
JMenuItem registerLandlord = new JMenuItem(" Register Landlord", addIcon);
registerLandlord.setMnemonic(KeyEvent.VK_A);
registerLandlord.setToolTipText("Open Register Landlord window");
registerLandlord.addActionListener(ae -> {
RegisterLandlordGUI addNewLandlordScreen = new RegisterLandlordGUI();
});
JMenuItem deRegisterLandlord = new JMenuItem(" De-Register Landlord", deleteIcon);
deRegisterLandlord.setMnemonic(KeyEvent.VK_D);
deRegisterLandlord.setToolTipText("De-Register Landlord from the system");
deRegisterLandlord.addActionListener(ae -> {
System.out.println("De-Register Landlord Clicked");
Landlord removeLandLord = removeLandlord();
});
JMenuItem amendDetails = new JMenuItem(" Amend Details", editIcon);
amendDetails.setMnemonic(KeyEvent.VK_C);
amendDetails.setToolTipText("Find a Landlord and update their details");
amendDetails.addActionListener(ae -> {
System.out.println("Change Landlord Details Clicked");
Landlord searchedLandL = amendLandlord();
if (searchedLandL != null) {
AmendLandlordGUI amendLandlordGUI = new AmendLandlordGUI(searchedLandL);
}
});
JMenuItem searchLandlord = new JMenuItem(" Search Landlord", searchIcon);
searchLandlord.setMnemonic(KeyEvent.VK_S);
searchLandlord.setToolTipText("Search Landlord on the system");
searchLandlord.addActionListener(ae -> {
System.out.println("Search Landlord Clicked");
Landlord seaLandlord = searchLandlord();
});
JMenuItem displayLandlord = new JMenuItem(" Display Landlords", displayIcon);
displayLandlord.setMnemonic(KeyEvent.VK_L);
displayLandlord.setToolTipText("Search Landlord on the system");
displayLandlord.addActionListener(ae -> {
System.out.println("Display Landlord Clicked");
StringBuilder builder = new StringBuilder(landlordList.size());
for (Landlord land : landlordList) {
builder.append(land.toString() + "\n");
}
JTextArea textArea = new JTextArea(builder.toString());
JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
scrollPane.setPreferredSize(new Dimension(500, 500));
JOptionPane.showMessageDialog(null, scrollPane, "List of Landlords", JOptionPane.OK_OPTION);
for (Landlord c : landlordList) {
System.out.println(c.toString());
}
});
landlords.add(registerLandlord);
landlords.add(deRegisterLandlord);
landlords.add(amendDetails);
landlords.add(searchLandlord);
landlords.add(displayLandlord);
JMenuItem recordNewProperty = new JMenuItem(" Record New Property", addIcon);
recordNewProperty.setMnemonic(KeyEvent.VK_R);
recordNewProperty.setToolTipText("Open Record New Property window");
recordNewProperty.addActionListener(ae -> {
RecordNewPropertyGUI addNewPropertyScreen = new RecordNewPropertyGUI();
});
JMenuItem deleteProperty = new JMenuItem(" Delete Property", deleteIcon);
deleteProperty.setMnemonic(KeyEvent.VK_D);
deleteProperty.setToolTipText("Delete Property from the system");
deleteProperty.addActionListener(ae -> {
System.out.println("Delete Property Clicked");
Property removeProperty = removeProperty();
});
JMenuItem searchProperties = new JMenuItem(" Search For Property", searchIcon);
searchProperties.setMnemonic(KeyEvent.VK_A);
searchProperties.setToolTipText("Search For a Property on the system");
searchProperties.addActionListener(ae -> {
System.out.println("Search For Property Clicked");
});
JMenuItem propertiesAvailable = new JMenuItem(" Display Properties Available", displayIcon);
propertiesAvailable.setMnemonic(KeyEvent.VK_A);
propertiesAvailable.setToolTipText("Search Properties on the system");
propertiesAvailable.addActionListener(ae -> {
System.out.println("Display Properties Clicked");
StringBuilder builder = new StringBuilder(propertyAvailable.size());
for (Property pr : propertyAvailable) {
builder.append(pr.toString() + "\n");
}
JTextArea textArea = new JTextArea(builder.toString());
JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
scrollPane.setPreferredSize(new Dimension(500, 500));
JOptionPane.showMessageDialog(null, scrollPane, "List of Properties Available", JOptionPane.OK_OPTION);
for (Property pro : propertyAvailable) {
System.out.println(pro.toString());
}
});
JMenuItem displayProperties = new JMenuItem(" Display Properties", displayIcon);
displayProperties.setMnemonic(KeyEvent.VK_A);
displayProperties.setToolTipText("Search Properties on the system");
displayProperties.addActionListener(ae -> {
System.out.println("Display Properties Clicked");
StringBuilder builder = new StringBuilder(propertyList.size());
for (Property pr : propertyList) {
builder.append(pr.toString() + "\n");
}
JTextArea textArea = new JTextArea(builder.toString());
JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
scrollPane.setPreferredSize(new Dimension(500, 500));
JOptionPane.showMessageDialog(null, scrollPane, "List of Properties", JOptionPane.OK_OPTION);
for (Property pro : propertyAvailable) {
System.out.println(pro.toString());
}
});
JMenuItem listPropertiesAvailable = new JMenuItem(" List Properties Available/Let", listIcon);
listPropertiesAvailable.setMnemonic(KeyEvent.VK_L);
listPropertiesAvailable.setToolTipText("List Properties Available/Let on the system");
listPropertiesAvailable.addActionListener(ae -> {
System.out.println("List Properties Available/Let Clicked");
StringBuilder builder = new StringBuilder(propertyList.size());
for (Property prop : propertyList) {
builder.append(prop.toString() + "\n");
}
JTextArea textArea = new JTextArea(builder.toString());
JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
scrollPane.setPreferredSize(new Dimension(500, 500));
JOptionPane.showMessageDialog(null, scrollPane, "List of Properties not available", JOptionPane.OK_OPTION);
for (Property p : propertyList) {
System.out.println(p.toString());
}
});
properties.add(recordNewProperty);
properties.add(deleteProperty);
properties.add(searchProperties);
properties.add(displayProperties);
properties.add(propertiesAvailable);
properties.add(listPropertiesAvailable);
JMenuItem registerNewTenant = new JMenuItem(" Register New Tenant", addIcon);
registerNewTenant.setMnemonic(KeyEvent.VK_R);
registerNewTenant.setToolTipText("Open Register New Tenant window");
registerNewTenant.addActionListener(ae -> {
RegisterNewTenantGUI addNewTenantScreen = new RegisterNewTenantGUI();
});
JMenuItem deleteTenant = new JMenuItem(" Delete Tenant", deleteIcon);
deleteTenant.setMnemonic(KeyEvent.VK_D);
deleteTenant.setToolTipText("Delete Tenant from the system");
deleteTenant.addActionListener(ae -> {
System.out.println("Delete Tenant Clicked");
Tenant removeTenant = removeTenant();
});
JMenuItem amendTenant = new JMenuItem(" Amend Tenant's Details", editIcon);
amendTenant.setMnemonic(KeyEvent.VK_C);
amendTenant.setToolTipText("Find a Tenant and update their details");
amendTenant.addActionListener(ae -> {
System.out.println("Change Tenant Details Clicked");
Tenant amendTenantDetails = amendTenant();
if (amendTenantDetails != null) {
AmendTenantGUI amendTenantGUI = new AmendTenantGUI(amendTenantDetails);
}
});
JMenuItem searchTenant = new JMenuItem(" Search For Tenant", searchIcon);
searchTenant.setMnemonic(KeyEvent.VK_S);
searchTenant.setToolTipText("Search For a Tenant on the system");
searchTenant.addActionListener(ae -> {
System.out.println("Search For Tenant Clicked");
Tenant searchTen = searchTenant();
});
JMenuItem tenantsAvailable = new JMenuItem(" Display Available Tenants", displayIcon);
tenantsAvailable.setMnemonic(KeyEvent.VK_P);
tenantsAvailable.setToolTipText("Display Tenants on the system");
tenantsAvailable.addActionListener(ae -> {
System.out.println("Display Tenants Clicked");
String s = tenantLts.getSelectedItem().toString();
if (s == "Tenants Available") {
StringBuilder builder = new StringBuilder(HomeScreenGUI.tenantsAvailable.size());
for (Tenant land : HomeScreenGUI.tenantsAvailable) {
builder.append(land.toString() + "\n");
}
JTextArea textArea = new JTextArea(builder.toString());
JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
scrollPane.setPreferredSize(new Dimension(500, 500));
JOptionPane.showMessageDialog(null, scrollPane, "List of Tenants Available", JOptionPane.OK_OPTION);
System.out.println("Tenant's Available List :");
for (Tenant t : HomeScreenGUI.tenantsAvailable) {
System.out.println("Name: " + t.getName() + "\nID number: "
+ t.getAddress() + "\nPhone No: " + t.getPhoneNumber() + "\nPPS Number: " + t.getPpsNumber()
+ "\nTenant ID: " + t.getTenantID() + "\nTenant Status: " + t.getTenantStatus());
}
}
});
JMenuItem displayTenants = new JMenuItem(" Display Tenants List", displayIcon);
displayTenants.setMnemonic(KeyEvent.VK_P);
displayTenants.setToolTipText("Display Tenants on the system");
displayTenants.addActionListener(ae -> {
System.out.println("Display Tenants Clicked");
String s = tenantLts.getSelectedItem().toString();
if (s == "Tenants Available") {
StringBuilder builder = new StringBuilder(tenantList.size());
for (Tenant ten : tenantList) {
builder.append(ten.toString() + "\n");
}
JTextArea textArea = new JTextArea(builder.toString());
JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
scrollPane.setPreferredSize(new Dimension(500, 500));
JOptionPane.showMessageDialog(null, scrollPane, "List of Tenants Available", JOptionPane.OK_OPTION);
System.out.println("Tenant's Available List :");
for (Tenant t : HomeScreenGUI.tenantsAvailable) {
System.out.println("Name: " + t.getName() + "\nID number: "
+ t.getAddress() + "\nPhone No: " + t.getPhoneNumber() + "\nPPS Number: " + t.getPpsNumber()
+ "\nTenant ID: " + t.getTenantID() + "\nTenant Status: " + t.getTenantStatus());
}
}
});
tenants.add(registerNewTenant);
tenants.add(deleteTenant);
tenants.add(amendTenant);
tenants.add(searchTenant);
tenants.add(displayTenants);
tenants.add(tenantsAvailable);
JMenuItem processNewRental = new JMenuItem(" Process New Rental", addIcon);
processNewRental.setMnemonic(KeyEvent.VK_P);
processNewRental.setToolTipText("Process New Rental on the system");
processNewRental.addActionListener(ae -> {
System.out.println("Process New Rental Clicked");
StringBuilder builder = new StringBuilder(rentalList.size());
for (Rental land : rentalList) {
builder.append(land.toString() + "\n");
}
int tenIdx = Integer.parseInt(JOptionPane.showInputDialog("Enter a tenant ID number "
+ " between 1 and " + HomeScreenGUI.tenantsAvailable.size()));
int propIdx = Integer.parseInt(JOptionPane.showInputDialog("Enter a property ID number "
+ " between 1 and " + propertyAvailable.size()));
Rental propertyRental = new Rental(propertyAvailable.get(tenIdx - 1),
HomeScreenGUI.tenantsAvailable.get(propIdx - 1));
propertyAvailable.get(propIdx - 1).takeProperty();
propertyRental.setTerm("1 year");
propertyRental.setRate(750.00);
rentalList.add(propertyRental);
tenantList.add(HomeScreenGUI.tenantsAvailable.get(propIdx - 1));
HomeScreenGUI.tenantsAvailable.remove(HomeScreenGUI.tenantsAvailable.get(propIdx - 1));
propertyLet.add(propertyAvailable.get(tenIdx - 1));
propertyAvailable.remove(propertyAvailable.get(tenIdx - 1));
});
JMenuItem searchRental = new JMenuItem(" Search For Rental", searchIcon);
searchRental.setMnemonic(KeyEvent.VK_S);
searchRental.setToolTipText("Search For a Rental on the system");
searchRental.addActionListener(ae -> {
System.out.println("Search For Rental Clicked");
});
JMenuItem displayRentals = new JMenuItem(" Display Rentals", displayIcon);
displayRentals.setMnemonic(KeyEvent.VK_D);
displayRentals.setToolTipText("Display Rentals on the system");
displayRentals.addActionListener(ae -> {
System.out.println("Display Rentals Clicked");
area.setText("Class List\n");
JScrollPane scroll = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
for (Rental r : rentalList) {
area.append(r.toString());
if (r.getProperty() instanceof Property) {
area.append(" for Class Name: " + ((Property) (r.getProperty())).getAddress_() + "\n\n");
}
}
scroll.setPreferredSize(new Dimension(500, 500));
JOptionPane.showMessageDialog(null, scroll);
});
rentals.add(processNewRental);
rentals.add(searchRental);
rentals.add(displayRentals);
JMenuItem about = new JMenuItem(" About", aboutIcon);
about.setMnemonic(KeyEvent.VK_A);
about.setToolTipText("Information about this system");
about.addActionListener(ae -> {
System.out.println("Information about this system Clicked");
JOptionPane.showMessageDialog(null, "This application is developed by Roman.\n"
+ "This Project Is About Real-Estate Agency.");
});
JMenuItem documentation = new JMenuItem(" Help", helpIcon);
documentation.setMnemonic(KeyEvent.VK_H);
documentation.setToolTipText("Opens the help page. This shows information with regard to the operation of this system");
documentation.addActionListener(ae -> {
System.out.println("Display help page clicked");
JOptionPane.showMessageDialog(null, "Click on the menu bar to use this software.\n"
+ "You can use keyboard to handle this software also like press Alt then\n"
+ "click on the fist alphabet of any menubar option.\n"
+ "Ex- alt+L or alt+P or alt+ or alt+H");
});
help.add(about);
help.add(documentation);
menuBar.add(file);
menuBar.add(landlords);
menuBar.add(properties);
menuBar.add(tenants);
menuBar.add(rentals);
menuBar.add(help);
setJMenuBar(menuBar);
}
private void saveDatabases() {
//Save the Landlord's File
saveLandlordsFile();
//Save the Properties Files
savePropertiesListFile();
savePropertiesFile();
savePropertiesLetFile();
//Save the Tenants Files
saveTenantsFile();
saveTenantsListFile();
//Save the Rentals File
saveRentalsFile();
}
private void saveLandlordsFile() {
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("files/landlords.data"));
os.writeObject(HomeScreenGUI.landlordList);
os.close();
} catch (Exception e) {
System.out.println("Error occurred when trying to save landlords.dat file");
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "landlord(s) successfully written to file\n");
}
private void savePropertiesFile() {
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("files/property.data"));
os.writeObject(HomeScreenGUI.propertyAvailable);
os.close();
} catch (Exception e) {
System.out.println("Error occurred when trying to save properties.dat file");
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "Property/Properties successfully written to file\n");
}
private void savePropertiesListFile() {
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("files/propertyList.data"));
os.writeObject(HomeScreenGUI.propertyList);
os.close();
} catch (Exception e) {
System.out.println("Error occurred when trying to save propertiesList.dat file");
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "Property/Properties successfully written to file\n");
}
private void savePropertiesLetFile() {
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("files/propertyLet.data"));
os.writeObject(HomeScreenGUI.propertyLet);
os.close();
} catch (Exception e) {
System.out.println("Error occurred when trying to save propertiesLet.dat file");
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "Property/Properties successfully written to file\n");
}
private void saveTenantsFile() {
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("files/tenants.data"));
os.writeObject(HomeScreenGUI.tenantsAvailable);
os.close();
} catch (Exception e) {
System.out.println("Error occurred when trying to save tenants.dat file");
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "Tenant(s) successfully written to file\n");
}
private void saveTenantsListFile() {
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("files/tenantsList.data"));
os.writeObject(HomeScreenGUI.tenantList);
os.close();
} catch (Exception e) {
System.out.println("Error occurred when tr...