View Single Post
  #1 (permalink)  
Old 11-02-2007, 08:59 PM
adlb1300 adlb1300 is offline
Member
 
Join Date: Jul 2007
Posts: 46
adlb1300 is on a distinguished road
Need Help With Button Events
I'm trying to create an application that utilizes a form to gather info from the user. The form has 4 buttons - start, exit, clear and search. I'm trying to program the appropriate actions for these buttons but no matter what I also have an error. When I have tried to compile I get and error to the effect that the variable is non-static and cannot be run.

Can anybody help me out?

Code:
import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class FlightInterface { /** * @param args the command line arguments */ public static void main(String[] args) { 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); JTextField nameInputField = new JTextField(); 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)); JTextField flightNumField = new JTextField(); 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)); JTextField originField = new JTextField(); 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)); JTextField destinationField = new JTextField(); 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)); JButton startButton = new JButton("Get Data"); startButton.setFont(new Font("Serif", Font.PLAIN, 14)); JButton exitButton = new JButton("Exit"); exitButton.setFont(new Font("Serif", Font.PLAIN, 14)); JButton searchButton = new JButton("Search"); searchButton.setFont(new Font("Serif", Font.PLAIN, 14)); JButton 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.setPreferredSize(new Dimension(250, 20)); buttonPanel.add(startButton); buttonPanel.add(clearButton); buttonPanel.add(searchButton); buttonPanel.add(exitButton); JPanel mainPanel = new JPanel(); 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); JFrame f = new JFrame(); // creates new instance of JFrame so graph can be displayed f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // tells JFrame to close on exit f.getContentPane().add(mainPanel); f.setSize(300, 265); // sets size of JFrame f.setLocation(200, 200); // sets location of JFrame f.setVisible(true); // makes JFrame visible } // end main } // end class
Thanks
Reply With Quote
Sponsored Links