ComboBox

Hi Experts World!!

Please take a look at these two classes and tell me why a call the combox is not poping up

=============== FIRST CLASS =================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

/**
 *
 * @author  Agbeko Komla
 */
public class DiceGame {
   
    //private static DicePanel d = new DicePanel();
    //private static ChooseTypeOfDie  c = new ChooseTypeOfDie();
    //private static GetNumberOfSides g = new GetNumberOfSides();
   
    public static void main(String[] args) {
       
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
            String dieType =  (new ChooseTypeOfDie()).getDieType();
            //int  numOfSide = (new GetNumberOfSides()).getNumOfSides();
         //   if(dieType.equals("aRegularDie"))
          //  (new DicePanel(dieType, numOfSide)).createAndShowGUI();
            //d.createAndShowGUI();
           
            }
        });
       
    }
   
}
============================= SECOND CLASS ==========================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

/**
 *
 * @author  Agbeko Komla
 */
public class ChooseTypeOfDie extends JPanel {
   
    private static final String dieTypes[] = { "aRegularDie", "aLoadedDie"};
    private static String selectedType;
   
    /** Creates a new instance of ChooseTypeOfDie */
    public ChooseTypeOfDie() {  
        JComboBox dies = new JComboBox(dieTypes);
        selectedType =  (String)dies.getSelectedItem();  
        dies.setVisible(true);
        //setVisible(true);
 
    }
   
    public String getDieType(){
        return selectedType;
    }
   
}


Thanks,
Komlaaa
komlaaaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gnoonCommented:
The combobox should be added to a window, then show the window.
0
valcarCommented:
You need to put the JPanel within some window to display it.  In this case you probably want to use a JDialog, and, in fact, you should probably change ChooseTypeOf Die to extend JDialog.  Then just don't forget to call show() on it.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
komlaaaAuthor Commented:
sample code please
thanks
0
gnoonCommented:
/* ComboShowDemo.java */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Chooser extends JDialog implements ActionListener
{
     JComboBox combo;
     final String faces[] = { ":-)", ":-(", "<|:-)"};
     String selectedValue;

     Chooser()
     {
        // set this dialog with owner, title, modal
        super(new Frame(), "Please choose a face", true);

        // set dialog's size
        setSize(300,100);

        // set dialog's location to the center of screen
        setLocationRelativeTo(null);

        // get a reference to dialog's content
        Container c = getContentPane();

        // set layout manager of dialog's content
        c.setLayout( new BorderLayout() );

        // new instance of combo with init choices
        combo = new JComboBox( faces );

        // add a listener to the combo to get selected value when changed.
        combo.addActionListener(this);

        JPanel panel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );

        // add the combo to a panel for layout purpose
        panel.add(combo);

        // add the panel to the dialog's content
        c.add( panel );
        c.add( new JLabel("(Close me to get the selected face)",JLabel.CENTER), BorderLayout.SOUTH);
     }

     // invoked when the combo is selected
     public void actionPerformed(ActionEvent e)
     {
         // save the selected item
         selectedValue = (String)combo.getSelectedItem();
     }

     public String getSelectedChoice()
     {
         // show this dialog, and wait until user hits close button
         setVisible(true);

         // after this dialog is closed, return the selected value.
         return selectedValue;
     }
}

public class ComboShowDemo
{

    public static void main(String[] args)
    {
        String selectedChoice = new Chooser().getSelectedChoice();
        System.out.println("Selected face: "+selectedChoice);
    }

}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.