Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
IntegratedTravelSystem/TravProfInterface.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1038 lines (883 sloc)
37.4 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.*; | |
public class TravProfInterface { | |
private TravProfDB database; | |
private JFrame mainFrame; | |
//DB Object | |
public TravProfInterface(String newfileName){ | |
database = new TravProfDB(newfileName); | |
initDB(); | |
getUserChoice(); | |
} | |
//get choice from the user | |
private void getUserChoice(){ | |
mainFrame = new JFrame("Integrated Travel System"); | |
mainFrame.setSize(500,500); | |
mainFrame.setLayout(null); | |
mainFrame.setBackground(Color.RED); | |
//initialize | |
JLabel Header; | |
JRadioButton rbtn1, rbtn2, rbtn3, rbtn4, rbtn5; | |
JButton btn; | |
//Header | |
Header = new JLabel("ITS"); | |
Header.setBounds(100,10,150,20); | |
mainFrame.add(Header); | |
//Options | |
//Create Profile | |
rbtn1 = new JRadioButton("Create a Profile"); | |
rbtn1.setBounds(100,50,120,25); | |
mainFrame.add(rbtn1); | |
//Delete Profile | |
rbtn2 = new JRadioButton("Delete a Profile"); | |
rbtn2.setBounds(100,80,120,25); | |
mainFrame.add(rbtn2); | |
//Update | |
rbtn3 = new JRadioButton("Update a Profile"); | |
rbtn3.setBounds(100,110,120,25); | |
mainFrame.add(rbtn3); | |
//Find/Display | |
rbtn4 = new JRadioButton("Find/Display a Profile"); | |
rbtn4.setBounds(100,140,150,25); | |
mainFrame.add(rbtn4); | |
//Display | |
rbtn5 = new JRadioButton("Display All Profiles"); | |
rbtn5.setBounds(100,170,150,25); | |
mainFrame.add(rbtn5); | |
//Add the buttons we just selected | |
ButtonGroup group = new ButtonGroup(); | |
group.add(rbtn1); | |
group.add(rbtn2); | |
group.add(rbtn3); | |
group.add(rbtn4); | |
group.add(rbtn5); | |
//search | |
btn = new JButton("Choose"); | |
btn.setBounds(110,200,100,30); | |
mainFrame.add(btn); | |
mainFrame.getContentPane().setBackground( Color.lightGray ); | |
mainFrame.setVisible(true); | |
//Action listener | |
btn.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
mainFrame.getContentPane().removeAll(); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
//Depending on what is selected go to that function | |
if(rbtn1.isSelected()) | |
createNewTravProf(); | |
else if(rbtn2.isSelected()) | |
deleteTravProf(); | |
else if(rbtn3.isSelected()) | |
updateTravProf(); | |
else if(rbtn4.isSelected()) | |
findTravProf(); | |
else if(rbtn5.isSelected()) | |
displayAllTravProf(); | |
} | |
}); | |
} | |
//create a profile | |
public void createNewTravProf(){ | |
final String[] travAgentID = new String[1]; | |
final String[] FirstName = new String[1]; | |
final String[] LastName = new String[1]; | |
final String[] Address = new String[1]; | |
final String[] Phone = new String[1]; | |
final String[] TravelType = new String[1]; | |
final String[] PaymentType = new String[1]; | |
final String[] AlgType = new String[1]; | |
final String[] IllType = new String[1]; | |
final String[] MdContact = new String[1]; | |
final String[] MdPhone = new String[1]; | |
final float[] TripCost = new float[1]; | |
//Jlabel and field creation | |
JLabel Header, lb1, lb2, lb3, lb4, lb5, lb6, lb7, lb8, lb9, lb10, lb11, lb12; | |
JComboBox box6, box7; | |
JTextField txt1, txt2, txt3, txt4, txt5, txt8, txt9, txt10, txt11, txt12; | |
JButton btn; | |
//Options | |
Header = new JLabel("Create a Profile"); | |
Header.setBounds(100,10,140,20); | |
mainFrame.add(Header); | |
lb1 = new JLabel("Traveler ID:"); | |
lb1.setBounds(10,50,110,20); | |
mainFrame.add(lb1); | |
txt1 = new JTextField(); | |
txt1.setBounds(120,50,140,20); | |
mainFrame.add(txt1); | |
lb2 = new JLabel("First Name:"); | |
lb2.setBounds(10,70,110,20); | |
mainFrame.add(lb2); | |
txt2 = new JTextField(); | |
txt2.setBounds(120,70,140,20); | |
mainFrame.add(txt2); | |
lb3 = new JLabel("Last Name:"); | |
lb3.setBounds(10,90,110,20); | |
mainFrame.add(lb3); | |
txt3 = new JTextField(); | |
txt3.setBounds(120,90,140,20); | |
mainFrame.add(txt3); | |
lb4 = new JLabel("Address:"); | |
lb4.setBounds(10,110,110,20); | |
mainFrame.add(lb4); | |
txt4 = new JTextField(); | |
txt4.setBounds(120,110,140,20); | |
mainFrame.add(txt4); | |
lb5 = new JLabel("Phone:"); | |
lb5.setBounds(10,130,110,20); | |
mainFrame.add(lb5); | |
txt5 = new JTextField(); | |
txt5.setBounds(120,130,140,20); | |
mainFrame.add(txt5); | |
lb6 = new JLabel("Travel Type:"); | |
lb6.setBounds(10,150,110,20); | |
mainFrame.add(lb6); | |
String[] list1 = {"Select", "Personal", "Business"}; | |
box6 = new JComboBox<>(list1); | |
box6.setBounds(120,150,140,20); | |
mainFrame.add(box6); | |
lb7 = new JLabel("Payment Type: "); | |
lb7.setBounds(10,170,110,20); | |
mainFrame.add(lb7); | |
String[] list2 = {"Select", "Credit", "Check", "Debit", "Invoice"}; | |
box7 = new JComboBox<>(list2); | |
box7.setBounds(120,170,140,20); | |
mainFrame.add(box7); | |
lb8 = new JLabel("Trip Cost:"); | |
lb8.setBounds(10,190,110,20); | |
mainFrame.add(lb8); | |
txt8 = new JTextField(); | |
txt8.setBounds(120,190,140,20); | |
mainFrame.add(txt8); | |
lb9 = new JLabel("Allergies:"); | |
lb9.setBounds(10,210,110,20); | |
mainFrame.add(lb9); | |
txt9 = new JTextField(); | |
txt9.setBounds(120,210,140,20); | |
mainFrame.add(txt9); | |
lb10 = new JLabel("Illnesses:"); | |
lb10.setBounds(10,230,110,20); | |
mainFrame.add(lb10); | |
txt10 = new JTextField(); | |
txt10.setBounds(120,230,140,20); | |
mainFrame.add(txt10); | |
lb11 = new JLabel("Medical Contact:"); | |
lb11.setBounds(10,250,110,20); | |
mainFrame.add(lb11); | |
txt11 = new JTextField(); | |
txt11.setBounds(120,250,140,20); | |
mainFrame.add(txt11); | |
lb12 = new JLabel("Contact Phone:"); | |
lb12.setBounds(10,270,110,20); | |
mainFrame.add(lb12); | |
txt12 = new JTextField(); | |
txt12.setBounds(120,270,140,20); | |
mainFrame.add(txt12); | |
btn = new JButton("Submit"); | |
btn.setBounds(100, 300, 100, 30); | |
mainFrame.add(btn); | |
btn.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
travAgentID[0] = txt1.getText(); | |
FirstName[0] = txt2.getText(); | |
LastName[0] = txt3.getText(); | |
Address[0] = txt4.getText(); | |
Phone[0] = txt5.getText(); | |
TravelType[0] = (String) box6.getSelectedItem(); | |
PaymentType[0] = (String) box7.getSelectedItem(); | |
TripCost[0] = Float.parseFloat(txt8.getText()); | |
AlgType[0] = txt9.getText(); | |
IllType[0] = txt10.getText(); | |
MdContact[0] = txt11.getText(); | |
MdPhone[0] = txt12.getText(); | |
MedCond medcondinfo = new MedCond(AlgType[0], IllType[0], MdContact[0], MdPhone[0]); | |
TravProf profile = new TravProf(travAgentID[0], FirstName[0], LastName[0], Address[0], Phone[0], TravelType[0], PaymentType[0], TripCost[0], medcondinfo); | |
database.insertNewProfile(profile); | |
// write to the database | |
writeToDB(); | |
mainFrame.getContentPane().removeAll(); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
} | |
}); | |
} | |
/* | |
import java.io.*; | |
import java.nio.charset.StandardCharsets; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
public class TravProfDB { | |
private int numTravelers; | |
private int currentTravelerIndex; | |
private String fileName; | |
public TravProf[] travelerList; | |
//This is a constructor method which accepts the name of the file in which the traveler | |
//profiles will be stored. Thus, for the ITS system in its current version, the database of TravProf is | |
//implemented using a file.`` | |
public TravProfDB(String fileName){ | |
this.fileName = fileName; | |
numTravelers = 0; | |
currentTravelerIndex = 0; | |
travelerList = new TravProf[0]; | |
} | |
//This method accepts a TravProf as input and inserts it into the array travelerList | |
public void insertNewProfile(TravProf travProf){ | |
TravProf[] newTravelerList = new TravProf[travelerList.length+1]; | |
if(travelerList.length == 0){ | |
newTravelerList[0] = travProf; | |
} else { | |
for (int i = 0; i < newTravelerList.length-1; i++) { | |
newTravelerList[i] = travelerList[i]; | |
} | |
newTravelerList[travelerList.length] = travProf; | |
} | |
travelerList = newTravelerList; | |
numTravelers = travelerList.length; | |
} | |
//This method accepts the travAgentID and lastName as inputs and returns the | |
//corresponding traveler profile as output. | |
public TravProf findProfile(String travAgentID, String lastName){ | |
TravProf travProf = null; | |
for (int i = 0; i < travelerList.length; i++) { | |
if(travelerList[i].getLastName() == lastName && travelerList[i].getTravAgentID() == travAgentID){ | |
travProf = travelerList[i]; | |
} | |
} | |
return travProf; | |
} | |
//This method accepts the travAgentID and lastName as inputs and deletes | |
//the corresponding traveler profile. It returns a boolean value to indicate whether the delete operation | |
//was successful. | |
public boolean deleteProfile(String travAgentID, String lastName){ | |
if(travelerList.length == 0){ | |
return false; | |
} else if (travelerList.length == 1){ | |
numTravelers = 0; | |
travelerList = new TravProf[0]; | |
return true; | |
} | |
TravProf[] newTravelerList = new TravProf[travelerList.length-1]; | |
boolean found = false; | |
int i; | |
for (i = 0; i < newTravelerList.length; i++) { | |
if (travelerList[i].getLastName() == lastName && travelerList[i].getTravAgentID() == travAgentID) { | |
i++; | |
for (int j = i-1; j < newTravelerList.length; j++) { | |
newTravelerList[j] = travelerList[i]; | |
i++; | |
} | |
travelerList = newTravelerList; | |
numTravelers = travelerList.length; | |
currentTravelerIndex = 0; | |
return true; | |
} | |
newTravelerList[i] = travelerList[i]; | |
} | |
return false; | |
} | |
//Returns first profile in the DB. | |
public TravProf findFirstProfile(){ | |
return travelerList[0]; | |
} | |
//This method writes all TravProf stored in the array travelerList to a | |
//file. Argument is a filename. E.x. "ExampleDB.txt". | |
public void writeAllTravProf(String fileName){ | |
try { | |
FileOutputStream outputStream = new FileOutputStream(fileName); | |
for (int i = 0; i < travelerList.length; i++) { | |
String line = travelerList[i].toString() + "\n"; | |
byte[] strToBytes = line.getBytes(); | |
outputStream.write(strToBytes); | |
} | |
outputStream.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
//Iterates through the profiles in the DB using the travelerIndex as an index | |
//and the numTravelers as a max to loop to 0. | |
public TravProf findNextProfile(){ | |
if(numTravelers == 0){ | |
System.out.println("No travelers in the database!"); | |
return null; | |
} else if(currentTravelerIndex >= numTravelers) { | |
currentTravelerIndex = 1; | |
return travelerList[0]; | |
} else { | |
return travelerList[currentTravelerIndex++]; | |
} | |
} | |
//This function should read traveler profiles from a file. The string argument might be filename or filepath. | |
//This method is used to read in the existing traveler profiles placed in the file. Example Argument: "TestDB.txt". | |
public void initializeDataBase(String fileName){ | |
try { | |
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8)); | |
String line; | |
while ((line = br.readLine()) != null) { | |
String[] attributes = line.split("\t"); | |
insertNewProfile(new TravProf(attributes[0],attributes[1],attributes[2],attributes[3],attributes[4],Float.parseFloat(attributes[5]),attributes[6],attributes[7],new MedCond(attributes[8],attributes[9],attributes[10],attributes[11]))); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
*/ | |
//delete | |
public void deleteTravProf(){ | |
JLabel Header, lb1, lb2; | |
JTextField txt1, txt2; | |
JButton btn1, btn2; | |
Header = new JLabel("Delete a Profile"); | |
Header.setBounds(100,10,150,25); | |
mainFrame.add(Header); | |
lb1 = new JLabel("Traveler ID: "); | |
lb1.setBounds(10,50,120,25); | |
mainFrame.add(lb1); | |
txt1 = new JTextField(); | |
txt1.setBounds(120,50,150,25); | |
mainFrame.add(txt1); | |
lb2 = new JLabel("Last Name: "); | |
lb2.setBounds(10,70,120,25); | |
mainFrame.add(lb2); | |
txt2 = new JTextField(); | |
txt2.setBounds(120,70,150,25); | |
mainFrame.add(txt2); | |
btn1 = new JButton("Delete"); | |
btn1.setBounds(100, 100, 100, 35); | |
mainFrame.add(btn1); | |
btn2 = new JButton("OK"); | |
btn2.setBounds(100, 100, 100, 35); | |
btn1.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
String ID = txt1.getText(); | |
String lastName = txt2.getText(); | |
mainFrame.getContentPane().remove(txt1); | |
mainFrame.getContentPane().remove(lb2); | |
mainFrame.getContentPane().remove(txt2); | |
mainFrame.getContentPane().remove(btn1); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
lb1.setBounds(100,50,100,30); | |
if(database.deleteProfile(ID,lastName)){ | |
lb1.setText("Profile Deleted."); | |
} | |
else{ | |
lb1.setText("Profile not found."); | |
} | |
writeToDB(); | |
mainFrame.add(btn2); | |
} | |
}); | |
btn2.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
mainFrame.getContentPane().removeAll(); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
} | |
}); | |
} | |
public void updateTravProf(){ | |
JLabel Header, lb1, lb2, lb3; | |
JTextField txt1; | |
JTextField txt2; | |
final JTextField[] txt3 = new JTextField[1]; | |
JComboBox box; | |
JButton btn1, btn2; | |
final TravProf[] profile = new TravProf[1]; | |
Header = new JLabel("Update Profile"); | |
Header.setBounds(100,10,150,25); | |
mainFrame.add(Header); | |
lb1 = new JLabel("Traveler ID: "); | |
lb1.setBounds(10,50,120,25); | |
mainFrame.add(lb1); | |
txt1 = new JTextField(); | |
txt1.setBounds(120,50,150,25); | |
mainFrame.add(txt1); | |
lb2 = new JLabel("Last Name: "); | |
lb2.setBounds(10,70,120,25); | |
mainFrame.add(lb2); | |
txt2 = new JTextField(); | |
txt2.setBounds(120,70,150,25); | |
mainFrame.add(txt2); | |
lb3 = new JLabel("Update Field: "); | |
lb3.setBounds(10,100,150,25); | |
mainFrame.add(lb3); | |
String[] list = {"Select","Address", "Phone number", "Travel type", "Payment type", "Trip cost", "Allergies", "Illnesses","Medical Contact", "Medical contact phone"}; | |
box = new JComboBox<>(list); | |
box.setBounds(120,100,150,25); | |
mainFrame.add(box); | |
btn1 = new JButton("Find"); | |
btn1.setBounds(100,130,100,35); | |
mainFrame.add(btn1); | |
btn2 = new JButton("Submit"); | |
btn2.setBounds(100,130,100,35); | |
btn1.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
String ID = txt1.getText(); | |
String lastName = txt2.getText(); | |
profile[0] = database.findProfile(ID,lastName); | |
mainFrame.getContentPane().remove(txt1); | |
mainFrame.getContentPane().remove(txt2); | |
mainFrame.getContentPane().remove(box); | |
mainFrame.getContentPane().remove(btn1); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
Header.setText("Update"); | |
Header.setBounds(150,10,150,25); | |
lb1.setText("Traveler ID - " + ID); | |
lb2.setText("Last Name - " + lastName); | |
lb3.setText((String) box.getSelectedItem() + ": "); | |
txt3[0] = new JTextField(); | |
txt3[0].setBounds(120,100,150,25); | |
mainFrame.add(txt3[0]); | |
mainFrame.add(btn2); | |
} | |
}); | |
btn2.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
String value = txt3[0].getText(); | |
int picked = box.getSelectedIndex(); | |
if(picked == 1) | |
profile[0].updateAddress(value); | |
if(picked == 2) | |
profile[0].updatePhone(value); | |
if(picked == 3) | |
profile[0].updateTravelType(value); | |
if(picked == 4) | |
profile[0].updatePaymentType(value); | |
if(picked == 5) | |
profile[0].updateTripCost(value); | |
if(picked == 6) | |
profile[0].getMedCondInfo().updateAlgType(value); | |
if(picked == 7) | |
profile[0].getMedCondInfo().updateIllType(value); | |
if(picked == 8) | |
profile[0].getMedCondInfo().updateMdContact(value); | |
if(picked == 9) | |
profile[0].getMedCondInfo().updateMdPhone(value); | |
writeToDB(); | |
mainFrame.getContentPane().removeAll(); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
} | |
}); | |
} | |
public void findTravProf(){ | |
JLabel Header, lb1, lb2; | |
JTextField txt1, txt2; | |
JButton btn; | |
Header = new JLabel("Find Profile"); | |
Header.setBounds(100,10,150,20); | |
mainFrame.add(Header); | |
lb1 = new JLabel("Traveler ID: "); | |
lb1.setBounds(10,50,120,20); | |
mainFrame.add(lb1); | |
txt1 = new JTextField(); | |
txt1.setBounds(120,50,150,20); | |
mainFrame.add(txt1); | |
lb2 = new JLabel("Last Name: "); | |
lb2.setBounds(10,70,120,20); | |
mainFrame.add(lb2); | |
txt2 = new JTextField(); | |
txt2.setBounds(120,70,150,20); | |
mainFrame.add(txt2); | |
btn = new JButton("Find"); | |
btn.setBounds(100,100,100,30); | |
mainFrame.add(btn); | |
btn.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
String ID = txt1.getText(); | |
String lastName = txt2.getText(); | |
mainFrame.getContentPane().removeAll(); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
displayTravProf(database.findProfile(ID, lastName)); | |
} | |
}); | |
} | |
/* | |
for reference | |
public class TravProfDB { | |
private int numTravelers; | |
private int currentTravelerIndex; | |
private String fileName; | |
public TravProf[] travelerList; | |
//This is a constructor method which accepts the name of the file in which the traveler | |
//profiles will be stored. Thus, for the ITS system in its current version, the database of TravProf is | |
//implemented using a file.`` | |
public TravProfDB(String fileName){ | |
this.fileName = fileName; | |
numTravelers = 0; | |
currentTravelerIndex = 0; | |
travelerList = new TravProf[0]; | |
} | |
//This method accepts a TravProf as input and inserts it into the array travelerList | |
public void insertNewProfile(TravProf travProf){ | |
TravProf[] newTravelerList = new TravProf[travelerList.length+1]; | |
if(travelerList.length == 0){ | |
newTravelerList[0] = travProf; | |
} else { | |
for (int i = 0; i < newTravelerList.length-1; i++) { | |
newTravelerList[i] = travelerList[i]; | |
} | |
newTravelerList[travelerList.length] = travProf; | |
} | |
travelerList = newTravelerList; | |
numTravelers = travelerList.length; | |
} | |
//This method accepts the travAgentID and lastName as inputs and returns the | |
//corresponding traveler profile as output. | |
public TravProf findProfile(String travAgentID, String lastName){ | |
TravProf travProf = null; | |
for (int i = 0; i < travelerList.length; i++) { | |
if(travelerList[i].getLastName() == lastName && travelerList[i].getTravAgentID() == travAgentID){ | |
travProf = travelerList[i]; | |
} | |
} | |
return travProf; | |
} | |
//This method accepts the travAgentID and lastName as inputs and deletes | |
//the corresponding traveler profile. It returns a boolean value to indicate whether the delete operation | |
//was successful. | |
public boolean deleteProfile(String travAgentID, String lastName){ | |
if(travelerList.length == 0){ | |
return false; | |
} else if (travelerList.length == 1){ | |
numTravelers = 0; | |
travelerList = new TravProf[0]; | |
return true; | |
} | |
TravProf[] newTravelerList = new TravProf[travelerList.length-1]; | |
boolean found = false; | |
int i; | |
for (i = 0; i < newTravelerList.length; i++) { | |
if (travelerList[i].getLastName() == lastName && travelerList[i].getTravAgentID() == travAgentID) { | |
i++; | |
for (int j = i-1; j < newTravelerList.length; j++) { | |
newTravelerList[j] = travelerList[i]; | |
i++; | |
} | |
travelerList = newTravelerList; | |
numTravelers = travelerList.length; | |
currentTravelerIndex = 0; | |
return true; | |
} | |
newTravelerList[i] = travelerList[i]; | |
} | |
return false; | |
} | |
//Returns first profile in the DB. | |
public TravProf findFirstProfile(){ | |
return travelerList[0]; | |
} | |
//This method writes all TravProf stored in the array travelerList to a | |
//file. Argument is a filename. E.x. "ExampleDB.txt". | |
public void writeAllTravProf(String fileName){ | |
try { | |
FileOutputStream outputStream = new FileOutputStream(fileName); | |
for (int i = 0; i < travelerList.length; i++) { | |
String line = travelerList[i].toString() + "\n"; | |
byte[] strToBytes = line.getBytes(); | |
outputStream.write(strToBytes); | |
} | |
outputStream.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
//Iterates through the profiles in the DB using the travelerIndex as an index | |
//and the numTravelers as a max to loop to 0. | |
public TravProf findNextProfile(){ | |
if(numTravelers == 0){ | |
System.out.println("No travelers in the database!"); | |
return null; | |
} else if(currentTravelerIndex >= numTravelers) { | |
currentTravelerIndex = 1; | |
return travelerList[0]; | |
} else { | |
return travelerList[currentTravelerIndex++]; | |
} | |
} | |
//This function should read traveler profiles from a file. The string argument might be filename or filepath. | |
//This method is used to read in the existing traveler profiles placed in the file. Example Argument: "TestDB.txt". | |
public void initializeDataBase(String fileName){ | |
try { | |
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8)); | |
String line; | |
while ((line = br.readLine()) != null) { | |
String[] attributes = line.split("\t"); | |
insertNewProfile(new TravProf(attributes[0],attributes[1],attributes[2],attributes[3],attributes[4],Float.parseFloat(attributes[5]),attributes[6],attributes[7],new MedCond(attributes[8],attributes[9],attributes[10],attributes[11]))); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
*/ | |
public void displayTravProf(TravProf traveler){ | |
JLabel Header, lb1, lb2, lb3, lb4, lb5, lb6, lb7, lb8, lb9, lb10, lb11, lb12; | |
JButton btn; | |
Header = new JLabel("Traveler Profile"); | |
Header.setBounds(100,10,150,20); | |
mainFrame.add(Header); | |
btn = new JButton("Close"); | |
if(traveler == null){ | |
lb1 = new JLabel("Profile not found."); | |
lb1.setBounds(100,50,150,20); | |
mainFrame.add(lb1); | |
btn.setBounds(100,90,100,30); | |
mainFrame.add(btn); | |
mainFrame.getContentPane().removeAll(); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
} | |
else{ | |
lb1 = new JLabel("Traveler ID: " + traveler.gettravAgentID()); | |
lb1.setBounds(10,50,300,20); | |
mainFrame.add(lb1); | |
lb2 = new JLabel("First Name: " + traveler.getFirstName()); | |
lb2.setBounds(10,70,300,20); | |
mainFrame.add(lb2); | |
lb3 = new JLabel("Last Name: " + traveler.getLastName()); | |
lb3.setBounds(10,90,300,20); | |
mainFrame.add(lb3); | |
lb4 = new JLabel("Address: " + traveler.getAddress()); | |
lb4.setBounds(10,110,300,20); | |
mainFrame.add(lb4); | |
lb5 = new JLabel("Phone: " + traveler.getPhone()); | |
lb5.setBounds(10,130,300,20); | |
mainFrame.add(lb5); | |
lb6 = new JLabel("Travel type: " + traveler.getTravelType()); | |
lb6.setBounds(10,150,300,20); | |
mainFrame.add(lb6); | |
lb7 = new JLabel("Payment type: " + traveler.getPaymentType()); | |
lb7.setBounds(10,170,300,20); | |
mainFrame.add(lb7); | |
lb8 = new JLabel("Trip cost: " + Float.toString(traveler.getTripCost())); | |
lb8.setBounds(10,190,300,20); | |
mainFrame.add(lb8); | |
lb9 = new JLabel("Allergies: " + traveler.getMedCondInfo().getAlgType()); | |
lb9.setBounds(10,210,300,20); | |
mainFrame.add(lb9); | |
lb10 = new JLabel("Illnesses: " + traveler.getMedCondInfo().getIllType()); | |
lb10.setBounds(10,230,300,20); | |
mainFrame.add(lb10); | |
lb11 = new JLabel("Medical contact: " + traveler.getMedCondInfo().getMdContact()); | |
lb11.setBounds(10,250,300,20); | |
mainFrame.add(lb11); | |
lb12 = new JLabel("Medical Contact Phone: " + traveler.getMedCondInfo().getMdPhone()); | |
lb12.setBounds(10,270,300,20); | |
mainFrame.add(lb12); | |
btn.setBounds(100,300,100,30); | |
mainFrame.add(btn); | |
mainFrame.getContentPane().removeAll(); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
} | |
} | |
public void displayAllTravProf(){ | |
JLabel Header; | |
final JLabel[] lb1 = new JLabel[1]; | |
final JLabel[] lb2 = new JLabel[1]; | |
final JLabel[] lb3 = new JLabel[1]; | |
final JLabel[] lb4 = new JLabel[1]; | |
final JLabel[] lb5 = new JLabel[1]; | |
final JLabel[] lb6 = new JLabel[1]; | |
final JLabel[] lb7 = new JLabel[1]; | |
final JLabel[] lb8 = new JLabel[1]; | |
final JLabel[] lb9 = new JLabel[1]; | |
final JLabel[] lb10 = new JLabel[1]; | |
final JLabel[] lb11 = new JLabel[1]; | |
final JLabel[] lb12 = new JLabel[1]; | |
JTextField txt1; | |
JButton btn1; | |
final JButton[] btn2 = new JButton[1]; | |
TravProf[] profiles = new TravProf[database.numTravelers]; | |
final int[] j = {0}, i = {0}; | |
Header = new JLabel("Display All Profiles"); | |
Header.setBounds(100,10,150,20); | |
mainFrame.add(Header); | |
lb1[0] = new JLabel("Traveler ID: "); | |
lb1[0].setBounds(10,50,120,20); | |
mainFrame.add(lb1[0]); | |
txt1 = new JTextField(); | |
txt1.setBounds(120,50,150,20); | |
mainFrame.add(txt1); | |
btn1 = new JButton("Find"); | |
btn1.setBounds(100,80,100,30); | |
mainFrame.add(btn1); | |
btn2[0] = new JButton("Next"); | |
btn2[0].setBounds(270,300,100,30); | |
//Create Profile | |
btn1.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
TravProf profile = database.findFirstProfile(); //create a temporary profile to iterate TravelerList | |
String ID = txt1.getText(); | |
mainFrame.getContentPane().removeAll(); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
for(int i = 0; i < database.numTravelers; i++){ | |
if(profile.gettravAgentID().equals(ID)) { | |
profiles[j[0]] = profile; | |
j[0]++; | |
} | |
profile = database.findNextProfile(); | |
} | |
mainFrame.add(Header); | |
lb1[0] = new JLabel("Traveler ID: " + profiles[i[0]].gettravAgentID()); | |
lb1[0].setBounds(10,50,300,20); | |
mainFrame.add(lb1[0]); | |
lb2[0] = new JLabel("First Name: " + profiles[i[0]].getFirstName()); | |
lb2[0].setBounds(10,70,300,20); | |
mainFrame.add(lb2[0]); | |
lb3[0] = new JLabel("Last Name: " + profiles[i[0]].getLastName()); | |
lb3[0].setBounds(10,90,300,20); | |
mainFrame.add(lb3[0]); | |
lb4[0] = new JLabel("Address: " + profiles[i[0]].getAddress()); | |
lb4[0].setBounds(10,110,300,20); | |
mainFrame.add(lb4[0]); | |
lb5[0] = new JLabel("Phone: " + profiles[i[0]].getPhone()); | |
lb5[0].setBounds(10,130,300,20); | |
mainFrame.add(lb5[0]); | |
lb6[0] = new JLabel("Travel type: " + profiles[i[0]].getTravelType()); | |
lb6[0].setBounds(10,150,300,20); | |
mainFrame.add(lb6[0]); | |
lb7[0] = new JLabel("Payment type: " + profiles[i[0]].getPaymentType()); | |
lb7[0].setBounds(10,170,300,20); | |
mainFrame.add(lb7[0]); | |
lb8[0] = new JLabel("Trip cost: " + Float.toString(profiles[i[0]].getTripCost())); | |
lb8[0].setBounds(10,190,300,20); | |
mainFrame.add(lb8[0]); | |
lb9[0] = new JLabel("Allergies: " + profiles[i[0]].getMedCondInfo().getAlgType()); | |
lb9[0].setBounds(10,210,300,20); | |
mainFrame.add(lb9[0]); | |
lb10[0] = new JLabel("Illnesses: " + profiles[i[0]].getMedCondInfo().getIllType()); | |
lb10[0].setBounds(10,230,300,20); | |
mainFrame.add(lb10[0]); | |
lb12[0] = new JLabel("Medical Contact Phone: " + profiles[i[0]].getMedCondInfo().getMdPhone()); | |
lb12[0].setBounds(10,270,300,20); | |
mainFrame.add(lb12[0]); | |
lb11[0] = new JLabel("Medical contact: " + profiles[i[0]].getMedCondInfo().getMdContact()); | |
lb11[0].setBounds(10,250,300,20); | |
mainFrame.add(lb11[0]); | |
mainFrame.add(btn2[0]); | |
i[0]++; | |
} | |
}); | |
//Create Profile | |
btn2[0].addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
mainFrame.getContentPane().removeAll(); | |
mainFrame.revalidate(); | |
mainFrame.repaint(); | |
if(i[0] != j[0]){ | |
mainFrame.add(Header); | |
//ID | |
lb1[0] = new JLabel("Traveler ID:" + profiles[i[0]].gettravAgentID()); | |
lb1[0].setBounds(10,50,350,20); | |
mainFrame.add(lb1[0]); | |
//First Name | |
lb2[0] = new JLabel("First Name:" + profiles[i[0]].getFirstName()); | |
lb2[0].setBounds(10,70,350,20); | |
mainFrame.add(lb2[0]); | |
//Last Name | |
lb3[0] = new JLabel("Last Name:" + profiles[i[0]].getLastName()); | |
lb3[0].setBounds(10,90,350,20); | |
mainFrame.add(lb3[0]); | |
//Phone # | |
lb5[0] = new JLabel("Phone:" + profiles[i[0]].getPhone()); | |
lb5[0].setBounds(10,130,350,20); | |
mainFrame.add(lb5[0]); | |
//Address | |
lb4[0] = new JLabel("Address:" + profiles[i[0]].getAddress()); | |
lb4[0].setBounds(10,110,350,20); | |
mainFrame.add(lb4[0]); | |
//Travel Type | |
lb6[0] = new JLabel("Travel Type:" + profiles[i[0]].getTravelType()); | |
lb6[0].setBounds(10,150,350,20); | |
mainFrame.add(lb6[0]); | |
//Payment Type | |
lb7[0] = new JLabel("Payment Type:" + profiles[i[0]].getPaymentType()); | |
lb7[0].setBounds(10,170,350,20); | |
mainFrame.add(lb7[0]); | |
//Trip Cost | |
lb8[0] = new JLabel("Trip Cost:" + Float.toString(profiles[i[0]].getTripCost())); | |
lb8[0].setBounds(10,190,350,20); | |
mainFrame.add(lb8[0]); | |
//Illnesses | |
lb10[0] = new JLabel("Illnesses:" + profiles[i[0]].getMedCondInfo().getIllType()); | |
lb10[0].setBounds(10,230,350,20); | |
mainFrame.add(lb10[0]); | |
//Allergies | |
lb9[0] = new JLabel("Allergies:" + profiles[i[0]].getMedCondInfo().getAlgType()); | |
lb9[0].setBounds(10,210,350,20); | |
mainFrame.add(lb9[0]); | |
//Medicak Contact | |
lb11[0] = new JLabel("Medical contact:" + profiles[i[0]].getMedCondInfo().getMdContact()); | |
lb11[0].setBounds(10,250,350,20); | |
mainFrame.add(lb11[0]); | |
//Medical Phone Num | |
lb12[0] = new JLabel("Medical Contact Phone:" + profiles[i[0]].getMedCondInfo().getMdPhone()); | |
lb12[0].setBounds(10,270,350,20); | |
mainFrame.add(lb12[0]); | |
mainFrame.add(btn2[0]); | |
i[0]++; | |
} | |
} | |
}); | |
} | |
//Database functions | |
public void initDB(){ | |
database.initializeDatabase(database.fileName); | |
} | |
public void writeToDB(){ | |
database.WriteAllTravProf(database.fileName); | |
} | |
//Main loading screen and what stays open | |
public static void main(String[] args){ | |
JFrame fileframe = new JFrame("Integrated Travel System"); | |
fileframe.setSize(400,200); | |
fileframe.setLayout(null); | |
//Header Setup | |
JLabel Header = new JLabel("Integrated Travel System"); | |
Header.setBounds(125,10,150,20); | |
fileframe.add(Header); | |
//Text Field | |
JTextField filetxt = new JTextField(); | |
filetxt.setBounds(145,55,150,20); | |
fileframe.add(filetxt); | |
//Prompt setup | |
JLabel lb = new JLabel("Database filename: "); | |
lb.setBounds(20,55,200,20); | |
fileframe.add(lb); | |
//Search Button | |
JButton btn = new JButton("Search"); | |
btn.setBounds(120,100,150,20); | |
fileframe.add(btn); | |
//make the frame visible | |
fileframe.getContentPane().setBackground( Color.lightGray ); | |
fileframe.setVisible(true); | |
//Action Listener | |
btn.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
String fileName = filetxt.getText(); | |
TravProfInterface face = new TravProfInterface(fileName); | |
} | |
}); | |
} | |
} |