Results 1 to 2 of 2
  1. #1
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Question Logic not working

    Hi,
    I have a two combo box, 1st is visible while 2nd is invisble at the frame start.
    When I click the 1st, then it should make 2nd visible with items related to the 1st combo box item selected.
    I have added item "New Connection .. " at the end of 2nd combo box list and when clicked should show Tabbed Pane.

    The problem is When I click the 1st combo box, it straight go to Tabbed Pane. Actually, what was needed is click 1st and then choose last item from 2nd and have Tabbed Pane show. But that's not happening.

    Here is the code for 1st combo box action listener
    Java Code:
    private void connectionTypeCBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        connTypeIndex = connectionTypeCBox.getSelectedIndex();
    
        dbManager.doConnection();
        if (connTypeIndex == 0) {
            availableConnectionTypeCBox.setVisible(false);
            ejbIdStore = 0;
            dbIdStore = 0;
        }
    
        if (connTypeIndex == 1) {
            List<EJBConnection> ejbConnection = dbManager.getEJBConnection(0);
            int sizeOfEJB = ejbConnection.size() + 1;
            ejbIdArray = new int[0];
            ejbIdArray = new int[sizeOfEJB];
            availableConnectionTypeCBox.removeAllItems();
            availableConnectionTypeCBox.addItem("Select");
    
            for (int i = 0; i < ejbConnection.size(); i++) {
                EJBConnection ejbConn = ejbConnection.get(i);
                String hostName = ejbConn.getEjbHostName();
                availableConnectionTypeCBox.addItem(hostName);
                ejbIdArray[i] = ejbConn.getId();
            }
            availableConnectionTypeCBox.addItem("New Connection..");
          
            dbIdStore = 0;
            availableConnectionTypeCBox.setVisible(true);
    
        } else if (connTypeIndex == 2) {
            List<DBConnection> dbConnection = dbManager.getDBConnection(0);
            dbIdArray = new int[0];
            dbIdArray = new int[dbConnection.size() + 1];
            availableConnectionTypeCBox.removeAllItems();
            availableConnectionTypeCBox.addItem("Select");
            for (int j = 0; j < dbConnection.size(); j++) {
                DBConnection dbConn = dbConnection.get(j);
                String serverIP = dbConn.getServerIp();
                availableConnectionTypeCBox.addItem(serverIP);
                dbIdArray[j] = dbConn.getId();
            }
    
            ejbIdStore = 0;
            availableConnectionTypeCBox.setVisible(true);
        }
    
    }

    Here is code for 2nd combo box action listener

    Java Code:
    private void availableConnectionTypeCBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                            
        int index = availableConnectionTypeCBox.getSelectedIndex();
        int count = availableConnectionTypeCBox.getItemCount();
    
        if (connTypeIndex == 1) {
            count = count - 1;
    
            if (index > 0 && index < count) {
                ejbIdStore = ejbIdArray[index - 1];
                dbIdStore = 0;
            } else if (index == 0 && index < count) {
                ejbIdStore = 0;
                dbIdStore = 0;
                return;
            }else if(index == count){
            mainFrame.tabbledPane.setSelectedIndex(1);
           }
    
      } else if (connTypeIndex == 2) {
    
            if (index > 0) {
                dbIdStore = dbIdArray[index - 1];
                ejbIdStore = 0;
            } else if (index == 0) {
                ejbIdStore = 0;
                dbIdStore = 0;
                return;
            }else if(index == count){
            mainFrame.tabbledPane.setSelectedIndex(2);
    }
        }
    I know that my logic is here not working but I can't figure it out what's wrong.
    Last edited by Prajin; 07-16-2010 at 09:01 AM.

  2. #2
    mrp3rf3ct83 is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default

    You should read up on the Builder design pattern. I had a similar issue when working with a database. Depending on how many items there are in combo box 1, you should consider putting them in a radio button instead of checkbox format. With the radio buttons, only one item can be selected. Then when the item in the radiobox is selected, it opens the correct items in combo box 2. You don't have to worry about indexes and writing code for radio buttons; they are handled for you. All you have to do is get the object that is clicked in the radiobox. Objects are the easiest things to work with in java. The way to process them and get the right answer is the problem.
    Last edited by mrp3rf3ct83; 07-19-2010 at 08:02 PM.

Similar Threads

  1. need a logic for this
    By rajivjoshi in forum New To Java
    Replies: 4
    Last Post: 06-12-2010, 02:18 PM
  2. help with a logic error
    By ShinTec in forum Advanced Java
    Replies: 11
    Last Post: 05-02-2010, 10:19 PM
  3. [SOLVED] need help with logic operator
    By auralius in forum New To Java
    Replies: 10
    Last Post: 12-25-2008, 10:01 PM
  4. Replies: 8
    Last Post: 05-28-2008, 07:00 AM
  5. Cant get the logic right
    By jermaindefoe in forum New To Java
    Replies: 4
    Last Post: 03-11-2008, 12:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •