Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 9th, 2007, 10:53 PM
SilentCodingOne SilentCodingOne is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 1 SilentCodingOne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 54 sec
Reputation Power: 0
MySpace
Help with JButton

I'm creating an application that manages the flights for an airline. I'm having trouble getting the exit button to work. I have not gotten to the point of programming the others yet as I will be doing that as I add those features. Any help would be appreciated.

Thanks

Code:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.*;

public class FlightManager implements ActionListener{
    
    // JDBC driver name and database url
    static final String DRIVER = "com.mysql.jdbc.Driver";
    static final String DATABASE_URL = "jdbc:mysql://localhost:3306/flightmanager";
    private JTextField fn = new JTextField(15);
    private JTextField oc  = new JTextField(15);
    private JTextField dc = new JTextField(15);
    private JTextField dt = new JTextField(15);
    private JLabel fnl = new JLabel("Flight Number: ");
    private JLabel ocl = new JLabel("City of Origin: ");
    private JLabel dcl = new JLabel("Destination City: ");
    private JLabel dtl = new JLabel("Departure Time: ");
    private int flightNum;
    private String originCity;
    private String destinationCity;
    private String departure;
    private JButton addButton;
    private JButton removeButton;
    private JButton searchButton;
    private JButton exitButton;
        
    public static void main(String[] args) throws SQLException {

        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
        
            Class.forName(DRIVER);
            connection = DriverManager.getConnection(DATABASE_URL, "root", "lilly");
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }

        FlightManager fm = new FlightManager();
        Container pc = new Container();
        pc.setLayout(new BoxLayout(pc, BoxLayout.Y_AXIS));
        JPanel blank = new JPanel();
        pc.add(blank);
        pc.add(fm.getFlightInputPanel());
        pc.add(fm.getOriginPanel());
        pc.add(fm.getDestinationPanel());
        pc.add(fm.getDepartureTimePanel());
        
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(pc, "First");
        f.add(fm.getButtonPanel(), "Last"); // adds button panel to JFrame
        f.setSize(500, 200);
        f.setLocation(200,200);
        f.setVisible(true);
        
        
        
    }
    
    private JPanel getFlightInputPanel(){
        FlowLayout flightInputLayout = new FlowLayout(FlowLayout.CENTER);
        JPanel fnp = new JPanel();
        fnp.add(fnl);
        fnp.add(fn);
        
        return fnp;
    }
    
    private JPanel getOriginPanel(){
        FlowLayout flightInputLayout = new FlowLayout(FlowLayout.CENTER);
        JPanel ocp = new JPanel();
        ocp.add(ocl);
        ocp.add(oc);
        
        return ocp;
    }
    
    private JPanel getDestinationPanel(){
        FlowLayout flightInputLayout = new FlowLayout(FlowLayout.CENTER);
        JPanel dcp = new JPanel();
        dcp.add(dcl);
        dcp.add(dc);
        
        return dcp;
    }
    
    private JPanel getDepartureTimePanel(){
        FlowLayout flightInputLayout = new FlowLayout(FlowLayout.CENTER);
        JPanel dtp = new JPanel();
        dtp.add(dtl);
        dtp.add(dt);
        
        return dtp;
    }
    
    private JPanel getButtonPanel(){
        
        FlowLayout buttonLayout = new FlowLayout(FlowLayout.CENTER);
        JPanel buttonPanel = new JPanel();
        addButton = new JButton("Add Flight");
        addButton.addActionListener(this);
        removeButton = new JButton("Delete Flight");
        removeButton.addActionListener(this);
        searchButton = new JButton("Search For Flight");
        searchButton.addActionListener(this);
        exitButton = new JButton("Exit");
        exitButton.addActionListener(this);
        buttonPanel.add(addButton);
        buttonPanel.add(removeButton);
        buttonPanel.add(searchButton);
        buttonPanel.add(exitButton);
     
        return buttonPanel;
    }
    
    
    // processes actions for when buttons are pushed
    public void actionPerformed(ActionEvent e) {

        // action to take if add ball button is pushed
        if(e.getSource() == addButton)
            
            flightNum = Integer.parseInt(fn.getText());
            originCity = oc.getText();
            destinationCity = dc.getText();
            departure = dt.getText();
            
            // clears out current contents of JTextFields
            fn = null;
            oc = null;
            dc = null;
            dt = null;
        
        // action to take if delete ball button is pushed
        if(e.getSource() == searchButton)

        if(e.getSource() == removeButton)
        
            
        // action to take if exit button is pushed
        if(e.getSource() == exitButton)
            System.exit(0);
    }
   }

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Help with JButton


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway