DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2003
    Posts
    4

    Angry JCombobox - verversen?

    Hey,

    I`ve got a question about comboboxes,
    i want that the list of a JCB is changed when i choose between 2 options from another JCB.
    I thougt it word work with only changeing the string- arrays, and the interface
    changes automatically --> nope..

    This is the code...

    PHP Code:
    // Fig. 12.26: GridLayoutDemo.java
    // Demonstrating GridLayout.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    import java.awt.Color.*;

    public class 
    GridLayoutDemo extends JFrame implements ActionListener {

        private 
    boolean toggle true;
        private 
    Container c;
        private 
    GridLayout grid1;
        private 
    JButton zoek;
        private 
    Connection connection;
        private 
    JTextField vDagaDatumvTijdaTijdvlucht;

        
    boolean inAnApplet true;
        final 
    boolean shouldFill true;
        final 
    boolean shouldWeightX true;

        
    Color myPink1 = new Color(254,224,192);

        private 
    JComboBox vertreknaarvdagvmaandvolwassenenkinderenbabys;

        
    // vertrekdag
        
    private String dag[] = { "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"};

        
    // vetrekmaand+jaar
        
    private String maand[] = { "April 2003" "Mei 2003"};

        
    // volwassenen
        
    private String volwassen[] = { "1""2""3""4""5""6""7""8""9""10" };

        
    // kinderen
        
    private String kind[] = { "1""2""3""4""5""6""7""8""9""10" };

        
    // baby's.
        
    private String baby[] = { "1""2""3""4""5""6""7""8""9""10" };

        
    //vetrekplaatsen-combobox
        
    private String vPlaatsen[] = { "Amsterdam""Rotterdam" };

        
    // aangeven wat in het combobox van Rotterdam mag staan
        
    private String raPlaatsen[] = { "Alicante""Faro" };

        
    // aangeven wat in het combobox van Amsterdam
        
    private String aaPlaatsen[] = { "Bacelona""Antalya""Arrecife""Alicante""Bodrun" };

        private 
    String[] plaats aaPlaatsen;

        
    //thread-safe gui changing with swingUtilities.invokeLater( Runnable )
        
    private Runnable run = new Runnable(){
        public 
    void run()
            {
            
    getContentPane().invalidate();
            
    getContentPane().removeAll();
            
    getContentPane().add(vertrek);
            
    getContentPane().add(naar);// = new JComboBox( plaats ));
            
    getContentPane().add(vdag);
            
    getContentPane().add(vmaand);
            
    getContentPane().add(volwassenen);
            
    getContentPane().add(kinderen);
            
    getContentPane().add(babys);
            
    getContentPane().add(zoek);
            
    getContentPane().add(vDag);
            
    getContentPane().add(aDatum);
            
    getContentPane().add(vTijd);
            
    getContentPane().add(aTijd);
            
    getContentPane().add(vlucht);
            
    getContentPane().validate();
            }
        };


       public 
    GridLayoutDemo()
       {
         
    super"GridLayout Demo" );

              
    // The URL specifying the Books database to which
               // this program connects using JDBC to connect to a
               // Microsoft ODBC database.
               
    String url "jdbc:odbc:vluchtinformatie";


               
    // Load the driver to allow connection to the database
               
    try {
                  Class.
    forName"sun.jdbc.odbc.JdbcOdbcDriver" );

                  
    connection DriverManager.getConnectionurl );
               }
               catch ( 
    ClassNotFoundException cnfex ) {
                  
    System.err.println(
                     
    "Failed to load JDBC/ODBC driver." );
                  
    cnfex.printStackTrace();
                  
    System.exit( );  // terminate program
               
    }
               catch ( 
    SQLException sqlex ) {
                  
    System.err.println"Unable to connect" );
                  
    sqlex.printStackTrace();
                  
    System.exit( );  // terminate program
          
    }

        
    grid1 = new GridLayout431010 );

        
    Container c getContentPane();
        
    c.setLayoutgrid1 );
        
    setSize(500,200);
        
    vertrek = new JComboBox(vPlaatsen);
        
    vertrek.setName("vertrek");
        
    vertrek.setMaximumRowCount(2);
        
    vertrek.addActionListenerthis );
        
    c.add(vertrek);
        
    show();

        
    //als de comment code bij run weggehaald zou worden, moet deze ook weg,
        //dit omdat je 2 verschillende arrays moet kunnen tonen bij aankomstplaatsen
         
    naar = new JComboBox(plaats);
         
    naar.setName("naar");
        
    naar.setMaximumRowCount(6);
        
    naar.addActionListenerthis );
        
    c.add(naar);
         
    show();

         
    vdag = new JComboBox(dag);
         
    vdag.setName("dag");
         
    vdag.setMaximumRowCount(5);
         
    vdag.addActionListenerthis );
         
    c.add(vdag);
         
    show();

         
    vmaand = new JComboBox(maand);
         
    vmaand.setName("maand");
         
    vmaand.setMaximumRowCount(5);
         
    vmaand.addActionListenerthis );
         
    c.add(vmaand);
         
    show();

         
    volwassenen = new JComboBox(volwassen);
         
    volwassenen.setName("volwassen");
         
    volwassenen.setMaximumRowCount(5);
         
    volwassenen.addActionListenerthis );
         
    c.add(volwassenen);
         
    show();

         
    kinderen = new JComboBox(kind);
         
    kinderen.setName("kind");
         
    kinderen.setMaximumRowCount(5);
         
    kinderen.addActionListenerthis );
         
    c.add(kinderen);
         
    show();

         
    babys = new JComboBox(baby);
         
    babys.setName("baby");
         
    babys.setMaximumRowCount(5);
         
    babys.addActionListenerthis );
         
    c.add(babys);
         
    show();

         
    zoek = new JButton"Zoek vlucht" );
         
    zoek.addActionListenerthis );
         
    c.add(zoek);
        
    show();

        
    vDag = new JTextField"Vertrekdatum" );
        
    c.add(vDag);
        
    show();

        
    aDatum = new JTextField"Aankomstdatum" );
        
    c.add(aDatum);
        
    show();

        
    vTijd = new JTextField"Vertrektijd" );
        
    c.add(vTijd);
        
    show();

        
    aTijd = new JTextField"Aankomsttijd" );
        
    c.add(aTijd);
        
    show();

        
    vlucht = new JTextField("Vluchtnummer" );
        
    c.add(vlucht);
        
    show();

    }

    public 
    void actionPerformed(ActionEvent e)
        {

          
    Object source4 e.getSource();
               if (
    source4 instanceof JComboBox)
               {
                   
    JComboBox combo = (JComboBoxsource4;
                   if (
    combo.getName().equals("dag"))
                   {
                       
    JComboBox avrida = (JComboBox)e.getSource();
                    
    String dag = (String)avrida.getSelectedItem();
                        
    System.out.println("dag is "+dag);
                   }
                if (
    combo.getName().equals("naar"))
                {
                    
    JComboBox avrida = (JComboBox)e.getSource();
                    
    String naar = (String)avrida.getSelectedItem();
                    
    System.out.println("naar is "+naar);
                   }
                   if (
    combo.getName().equals("maand"))
                {
                    
    JComboBox avrida = (JComboBox)e.getSource();
                    
    String maand = (String)avrida.getSelectedItem();
                    
    System.out.println("maand is "+maand);
                   }
                   if (
    combo.getName().equals("vertrek"))
                {
                    if (((String) 
    combo.getSelectedItem()).equals(vPlaatsen[0]))
                           {
                               
    plaats aaPlaatsen;
                               
    SwingUtilities.invokeLaterrun );
                                
    System.out.println("aaplaatseb? "+plaats);
                           }
                       else if (((String) 
    combo.getSelectedItem()).equals(vPlaatsen[1]))
                           {
                               
    plaats raPlaatsen;
                               
    SwingUtilities.invokeLaterrun );
                                
    System.out.println("raplaatsen? "+plaats);
                           }
                      
    JComboBox avrida = (JComboBox)e.getSource();
                    
    String vertrek = (String)avrida.getSelectedItem();
                       
    System.out.println("vertrek is "+vertrek);

                   }
                if (
    combo.getName().equals("volwassen"))
                {
                       
    JComboBox avrida = (JComboBox)e.getSource();
                    
    String volwassen = (String)avrida.getSelectedItem();
                       
    System.out.println("volwassen is "+volwassen);
                   }
                if (
    combo.getName().equals("kind"))
                {
                       
    JComboBox avrida = (JComboBox)e.getSource();
                    
    String kind = (String)avrida.getSelectedItem();
                       
    System.out.println("kind is "+kind);
                   }
                if (
    combo.getName().equals("baby"))
                {
                       
    JComboBox avrida = (JComboBox)e.getSource();
                    
    String baby = (String)avrida.getSelectedItem();
                       
    System.out.println("baby is "+baby);
                   }
               }
    }
           public static 
    void mainString args[] )
           {
        try
               {
               
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
               }
            catch (
    Exception e) { }

            
    GridLayoutDemo app = new GridLayoutDemo();

              
    app.addWindowListener(
            new 
    WindowAdapter()
                 {
                public 
    void windowClosingWindowEvent e )
                {
                
    System.exit( );
                }
             }
          );
       }

    The purpose is that if you change something with "vertrek" (Amsterdam or Rotterdan) Then the index is changed bij "naar" (plaatsen, raplaatsen, aaplaatsen)

    How can i make it so ?

    If you can help, i would really appreciate it!

    Thanx,

    Wouter

  2. #2
    Join Date
    Jun 2003
    Posts
    4

    Database

    Here is the database if you want to connect it...

    u have to make a connection with administrive tools - JDBC to vluchtinformatie.mdb
    Attached Files

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links