-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAirportPageFrame.java
More file actions
176 lines (137 loc) · 5.29 KB
/
AirportPageFrame.java
File metadata and controls
176 lines (137 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class AirportPageFrame extends JFrame {
private JPanel mainpanel;
private Airport myairport;
public AirportPageFrame(Airport anairport) {
mainpanel=new JPanel();
myairport=anairport;
JPanel panel1= new JPanel();
int fieldsize=10;
JTextField name= new JTextField(myairport.getName(),fieldsize);
JTextField id= new JTextField(myairport.getID(),fieldsize);
JTextField city= new JTextField(myairport.getCity(),fieldsize);
JTextField country= new JTextField(myairport.getCountry(),fieldsize);
name.setEditable(false);
id.setEditable(false);
city.setEditable(false);
country.setEditable(false);
name.setBackground(Color.WHITE);
id.setBackground(Color.WHITE);
city.setBackground(Color.WHITE);
country.setBackground(Color.WHITE);
HashSet<String> comptemp= CentralRegistry.AssociatedCompanies(myairport);
ArrayList<String> companies= new ArrayList<>(comptemp);
Collections.sort(companies);
String compstring="";
for(String acompany: companies)
compstring+=acompany+"\n";
JTextArea comparea = new JTextArea(compstring);
comparea.setPreferredSize(new Dimension(100,100));
comparea.setEditable(false);
comparea.setBackground(Color.WHITE);
panel1.add(name);
panel1.add(id);
panel1.add(city);
panel1.add(country);
panel1.add(comparea);
JPanel panel2=new JPanel();
JTextField anothercityfield= new JTextField("City name: ",fieldsize);
JButton FindFlights = new JButton("Find Flights");
anothercityfield.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
anothercityfield.setText("");
}
}); //when anothercityfield is initially clicked on, text area will be cleared
panel2.add(anothercityfield);
panel2.add(FindFlights);
mainpanel.add(panel1, BorderLayout.PAGE_START);
mainpanel.add(panel2, BorderLayout.CENTER);
JPanel panel3 = new JPanel();
FindFlights.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String city = anothercityfield.getText();
Airport airportx=CentralRegistry.getAirport(city);
if (airportx!=null) {
String directinfo=CentralRegistry.getDirectFlightsDetails(myairport,airportx);
JTextArea directinfofield = new JTextArea(directinfo);
directinfofield.setPreferredSize(new Dimension( 340, 340 ) );
directinfofield.setEditable(false);
directinfofield.setBackground(Color.WHITE);
String indirectinfo=CentralRegistry.getInDirectFlightsDetails(myairport,airportx);
JTextArea indirectinfofield = new JTextArea(indirectinfo);
indirectinfofield.setPreferredSize(new Dimension( 340, 340 ) );
indirectinfofield.setEditable(false);
indirectinfofield.setBackground(Color.WHITE);
panel3.add(directinfofield);
panel3.add(indirectinfofield);
mainpanel.add(panel3, BorderLayout.SOUTH);
mainpanel.revalidate();
try {
File f = new File(myairport.getCity()+"To"+airportx.getCity()+".txt");
FileWriter writer = new FileWriter(f);
writer.write("CITY: "+myairport.getCity()+","+myairport.getCountry());
writer.write(System.lineSeparator());
writer.write("Airport: "+myairport.getName()+","+myairport.getID());
writer.write(System.lineSeparator());
writer.write(System.lineSeparator());
writer.write("DESTINATION: "+airportx.getCity());
writer.write(System.lineSeparator());
writer.write(System.lineSeparator());
writer.write(directinfo);
if (directinfo.equals("DIRECT FLIGHTS DETAILS"+System.lineSeparator())) {
writer.write(System.lineSeparator());
writer.write("No direct flights");
}
writer.write(System.lineSeparator());
writer.write(System.lineSeparator());
writer.write(indirectinfo);
if (indirectinfo.equals("INDIRECT FLIGHTS through"+System.lineSeparator())) {
writer.write(System.lineSeparator());
writer.write("No indirect flights");
}
writer.close();
}
catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
else
JOptionPane.showMessageDialog(null,city+" does not have an airport");
}
}
);
JButton BackTS = new JButton("Back to Search Screen");
BackTS.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
AirportPageFrame.this.dispose();
}
});
panel3.add(BackTS);
mainpanel.add(panel3);
this.setContentPane(mainpanel);
this.setVisible(true);
this.setSize(500,500);
this.setTitle("Find Airport");
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
}