View Single Post
  #3 (permalink)  
Old 11-04-2007, 01:27 AM
adlb1300 adlb1300 is offline
Member
 
Join Date: Jul 2007
Posts: 46
adlb1300 is on a distinguished road
The array can vary as it depends on the number of flights to be added. Also I do have a class that is meant to process the data so not sure if it would be better once I grab I data to send it to that class and add to the array there. I will post that code at the end. Here is the source for the data being added to the loop

Code:
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(); nameInputField.setText(""); flightNumField.setText(""); originField.setText(""); destinationField.setText(""); for(int nameCounter = 0; nameCounter < name.length; nameCounter++){ name[nameCounter] = airline; } JOptionPane.showMessageDialog(null, "Flight data added."); }
And here is the codefor the whole thing:

Code:
import java.awt.event.*; import java.awt.*; import javax.swing.*; public class FlightInterface implements ActionListener { JButton exitButton; JButton getDataButton; JButton clearButton; JButton searchButton; JTextField nameInputField; JTextField flightNumField; JTextField originField; JTextField destinationField; String[] name = new String[1000]; 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(); nameInputField.setText(""); flightNumField.setText(""); originField.setText(""); destinationField.setText(""); for(int nameCounter = 0; nameCounter < name.length; nameCounter++){ name[nameCounter] = airline; } JOptionPane.showMessageDialog(null, "Flight data added."); } if(ae.getSource() == clearButton){ nameInputField.setText(""); flightNumField.setText(""); originField.setText(""); destinationField.setText(""); } if(ae.getSource() == searchButton){ } 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 }
Code:
public class Flight { private String airlineName; private int flightNumber; private String originCity; private String destinationCity; private static int totalFlights = 0; public Flight(){ airlineName = getAirlineName(); flightNumber = getFlightNumber(); originCity = getOriginCity(); destinationCity = getDestinationCity(); totalFlights++; }// end Flight constructor public String getAirlineName(){ return airlineName; } public void setAirlineName(String airline){ airlineName = airline; } public int getFlightNumber(){ return flightNumber; } public void setFlightNumber(int flightNum){ flightNumber = flightNum; } public String getOriginCity(){ return originCity; } public void setOriginCity(String origin){ originCity = origin; } public String getDestinationCity(){ return destinationCity; } public void setDestinationCity(String destination){ destinationCity = destination; } public String toStringFlightInfo(){ return String.format("%d", airlineName); } } // end Flight class
Thanks for the help

Last edited by adlb1300 : 11-04-2007 at 06:22 AM. Reason: added info
Reply With Quote