I'm writing a program that asks the user to input information regarding airline flights. The data is being collected by arraylists. I have created a class called Flight which I want to pass the completed arraylists to. Another class called Search is than going to based on the users request use the flight class to find and retrieve the matching flight data. I'm having trouble passing the arraylists to the Flight class which is holding up the program. I receive and error that states cannot find symbol; symbol: constructor Flight; location: class Flight. The constructor is in the class so not sure why it cannot find it. Here is my code:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.util.ArrayList;
public class FlightInterface implements ActionListener {
JButton exitButton;
JButton getDataButton;
JButton clearButton;
JButton searchButton;
JTextField destinationField;
JTextField nameInputField;
JTextField flightNumField;
JTextField originField;
ArrayList<String> airlineArray = new ArrayList<String>();
ArrayList<String> flightNumArray = new ArrayList<String>();
ArrayList<String> originArray = new ArrayList<String>();
ArrayList<String> destinationArray = new ArrayList<String>();
int totalFlights = 0;
private JPanel getContent() {
JLabel title = new JLabel("Flight Info");
title.setFont(new Font("Serif", Font.BOLD, 30));
JPanel bannerPanel = new JPanel();
bannerPanel.setPreferredSize(new Dimension(300, 50));
bannerPanel.add(title);
nameInputField = new JTextField(10);
JLabel inputAirlineName = new JLabel("Airline Name: ");
inputAirlineName.setFont(new Font("Serif", Font.PLAIN, 14));
JPanel namePanel = new JPanel();
namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.X_AXIS));
namePanel.setPreferredSize(new Dimension(200, 20));
namePanel.add(inputAirlineName);
namePanel.add(nameInputField);
JLabel inputFlightNum = new JLabel("Flight Number: ");
inputFlightNum.setFont(new Font("Serif", Font.PLAIN, 14));
flightNumField = new JTextField(10);
JPanel flightNumPanel = new JPanel();
flightNumPanel.setLayout(new BoxLayout(flightNumPanel, BoxLayout.X_AXIS));
flightNumPanel.setPreferredSize(new Dimension(200, 20));
flightNumPanel.add(inputFlightNum);
flightNumPanel.add(flightNumField);
JLabel inputOrigin = new JLabel("City of Origin: ");
inputOrigin.setFont(new Font("Serif", Font.PLAIN, 14));
originField = new JTextField(20);
JPanel originPanel = new JPanel();
originPanel.setLayout(new BoxLayout(originPanel, BoxLayout.X_AXIS));
originPanel.setPreferredSize(new Dimension(200, 20));
originPanel.add(inputOrigin);
originPanel.add(originField);
JLabel inputDestination = new JLabel("Destination City: ");
inputDestination.setFont(new Font("Serif", Font.PLAIN, 14));
destinationField = new JTextField(20);
JPanel destinationPanel = new JPanel();
destinationPanel.setLayout(new BoxLayout(destinationPanel, BoxLayout.X_AXIS));
destinationPanel.setPreferredSize(new Dimension(200, 20));
destinationPanel.add(inputDestination);
destinationPanel.add(destinationField);
JPanel blankPanel = new JPanel();
blankPanel.setLayout(new BoxLayout(blankPanel, BoxLayout.X_AXIS));
blankPanel.setPreferredSize(new Dimension(200, 20));
getDataButton = new JButton("Get Data");
getDataButton.setFont(new Font("Serif", Font.PLAIN, 14));
exitButton = new JButton("Exit");
exitButton.setFont(new Font("Serif", Font.PLAIN, 14));
searchButton = new JButton("Search");
searchButton.setFont(new Font("Serif", Font.PLAIN, 14));
clearButton = new JButton("Clear");
clearButton.setFont(new Font("Serif", Font.PLAIN, 14));
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
buttonPanel.add(getDataButton);
buttonPanel.add(clearButton);
buttonPanel.add(searchButton);
buttonPanel.add(exitButton);
getDataButton.addActionListener(this);
clearButton.addActionListener(this);
searchButton.addActionListener(this);
exitButton.addActionListener(this);
JPanel mainPanel = new JPanel();
System.out.println("JPanel default layout manager = " +
mainPanel.getLayout().getClass().getName());
mainPanel.add(bannerPanel, BorderLayout.NORTH);
mainPanel.add(namePanel, BorderLayout.CENTER);
mainPanel.add(flightNumPanel, BorderLayout.CENTER);
mainPanel.add(originPanel, BorderLayout.CENTER);
mainPanel.add(destinationPanel, BorderLayout.CENTER);
mainPanel.add(blankPanel, BorderLayout.CENTER);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
return mainPanel;
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == getDataButton){
String airline = nameInputField.getText();
String flightNumber = flightNumField.getText();
String origin = originField.getText();
String destination = destinationField.getText();
totalFlights++;
nameInputField.setText("");
flightNumField.setText("");
originField.setText("");
destinationField.setText("");
airlineArray.add(airline);
flightNumArray.add(flightNumber);
originArray.add(origin);
destinationArray.add(destination);
JOptionPane.showMessageDialog(null, "Flight data added.\n" +
"Number of Flights Added: " + totalFlights);
}
if(ae.getSource() == clearButton){
nameInputField.setText("");
flightNumField.setText("");
originField.setText("");
destinationField.setText("");
}
if(ae.getSource() == searchButton){
Flight Flight = new Flight(airlineArray, flightNumArray, originArray, destinationArray);
Search sf = new Search();
sf.searchApp();
}
if(ae.getSource() == exitButton){
System.exit(0);
}
}
public static void main(String[] args) {
// Using the variable "app" will help avoid problems
// with the static modifier in your class.
FlightInterface app = new FlightInterface();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(app.getContent());
f.setSize(300, 265); // sets size of JFrame
f.setLocation(200, 200); // sets location of JFrame
f.setVisible(true); // makes JFrame visible
} // end main
}
import java.util.ArrayList;
class Flight {
int totalFlights = 0;
String airlineName;
String flightNumber;
String originCity;
String destinationCity;
public Flight(String airlineArray, String flightNumArray, String originArray, String destinationArray){
airlineName = getAirlineName();
flightNumber = getFlightNumber();
originCity = getOriginCity();
destinationCity = getDestinationCity();
totalFlights++;
}// end Flight constructor
public String getAirlineName(){
return airlineName;
}
public void setAirlineName(String arrayAN){
airlineName = arrayAN;
}
public String getFlightNumber(){
return flightNumber;
}
public void setFlightNumber(String arrayFN){
flightNumber = arrayFN;
}
public String getOriginCity(){
return originCity;
}
public void setOriginCity(String arrayOC){
originCity = arrayOC;
}
public String getDestinationCity(){
return destinationCity;
}
public void setDestinationCity(String arrayDC){
destinationCity = arrayDC;
}
public String toStringFlightInfo(){
return String.format("%d", airlineName);
}
} // end Flight class
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Search implements ActionListener{
JFrame s;
JButton flightNumSearchButton;
JButton citySearchButton;
JButton exitSearchButton;
JTextField searchFlightNum;
JTextField searchDestination;
public void searchApp(){
JLabel searchTitle = new JLabel("Flight Search");
searchTitle.setFont(new Font("Serif", Font.BOLD, 30));
JPanel searchTitlePanel = new JPanel();
searchTitlePanel.setPreferredSize(new Dimension(425, 50));
searchTitlePanel.add(searchTitle);
searchFlightNum = new JTextField(10);
JLabel searchNumber = new JLabel("Enter Flight Number to Search For: ");
searchNumber.setFont(new Font("Serif", Font.PLAIN, 14));
flightNumSearchButton = new JButton("Search");
flightNumSearchButton.setFont(new Font("Serif", Font.PLAIN, 14));
JPanel sfn = new JPanel();
sfn.setLayout(new BoxLayout(sfn, BoxLayout.X_AXIS));
sfn.setPreferredSize(new Dimension(425, 20));
sfn.add(searchNumber);
sfn.add(searchFlightNum);
sfn.add(flightNumSearchButton);
JLabel searchCity = new JLabel("Enter City to Search For: ");
searchCity.setFont(new Font("Serif", Font.PLAIN, 14));
searchDestination = new JTextField(10);
citySearchButton = new JButton("Search");
citySearchButton.setFont(new Font("Serif", Font.PLAIN, 14));
JPanel sc = new JPanel();
sc.setLayout(new BoxLayout(sc, BoxLayout.X_AXIS));
sc.setPreferredSize(new Dimension(425, 20));
sc.add(searchCity);
sc.add(searchDestination);
sc.add(citySearchButton);
exitSearchButton = new JButton("Exit Search");
exitSearchButton.setFont(new Font("Serif", Font.PLAIN, 14));
JPanel es = new JPanel();
es.setAlignmentX(475);
es.setAlignmentY(10);
es.add(exitSearchButton);
JPanel searchMain = new JPanel();
searchMain.add(searchTitlePanel, BorderLayout.NORTH);
searchMain.add(sfn, BorderLayout.CENTER);
searchMain.add(sc, BorderLayout.CENTER);
searchMain.add(es, BorderLayout.CENTER);
s = new JFrame();
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
s.getContentPane().add(searchMain);
s.setSize(550, 200); // sets size of JFrame
s.setLocation(200, 200); // sets location of JFrame
s.setVisible(true); // makes JFrame visible
flightNumSearchButton.addActionListener(this);
citySearchButton.addActionListener(this);
exitSearchButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == exitSearchButton){
s.dispose();
}
if(e.getSource() == flightNumSearchButton){
String flightNumberSearch = searchFlightNum.getText();
}
if(e.getSource() == citySearchButton){
String destinationCitySearch = searchDestination.getText();
}
}
}