[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

TERMINATING MAIN THREADS

Posted on 2004-11-11
2
Medium Priority
?
235 Views
Last Modified: 2010-03-31
Below are my main and my GUI class.
i would like the main the terminate when i close the GUI. That is what i am trying to by including

 this.addWindowListener (  new WindowAdapter()
                {
                    public void windowClosing(WindowEvent e)
                    {
                        setVisible(false);
                        dispose();
                        System.exit(0);}} );
But i notice in my Tast list that the java.exe is still there after i close the window.
Why should i do.

==================== MAIN  ====================
{
   
    /** Creates a new instance of Main */
    public Main()
    {
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
       
     javax.swing.SwingUtilities.invokeLater
     (
        new Runnable()
        {
            public void run()
            {
               new DisplayCdCollection();
            }
        }
     );
       
    }
}
======================= GUI CLASS ====================
public class DisplayCdCollection extends JFrame
{
 
    private String selectedGenre;
    private JComboBox categories;
    private JTextArea CdList;
    private final String genres[] ;
   
    private CDCollection CDs;
     
    public DisplayCdCollection()
       {  
            super("CDs Display");
           
            CDs = new CDCollection();
            //CDs.read();
            genres = CDs.getCdCategoies();
                                   
            this.setLocation(300,300 );
            this.addWindowListener
            (
                new WindowAdapter()
                {
                    public void windowClosing(WindowEvent e)
                    {
                        setVisible(false);
                        dispose();
                        System.exit(0);
                    }
                }
            );
 
            //creating JTextArea to display the CDS
            CdList = new JTextArea("list of cd");
            CdList.setEditable(false);
           
            //create a contianer with scrollbar where the CdList should go.
            Container c = getContentPane();
            c.setLayout(new BorderLayout());
            c.add(new JScrollPane(CdList), BorderLayout.CENTER);
           
            /**creating combobox to hold the type of CD */
            categories = new JComboBox(genres);
            categories.setBackground(Color.white);
            categories.setMaximumRowCount(12);
           
            /**
             *add a listner to the combobox. When a genre of CD is chosen a
             *the selection will automatically trigger a processing of a list
             *of CDs of that type.
             */
            categories.addItemListener
            (
                new ItemListener()
                {
                    public void itemStateChanged(ItemEvent e)
                    {
                     selectedGenre= (String)categories.getSelectedItem();
                        {
                            if( selectedGenre.equals("All") )
                            {
                               CdList.setText("");
                               CdList.setText( CDs.printAll() );
                             }
                            else
                             {
                              CdList.setText("");
                              CdList.setText( CDs.getCDList(selectedGenre) );
                            }
                               
                        }
                    }
                }
            ); //end of addItemListener

        //creat a panel for the Cd categories combobox
        JPanel eastPanel = new JPanel();
        eastPanel.add(categories);
        c.add(eastPanel, BorderLayout.EAST);
           
        setSize(250,100);
        show();
    }
}

 
0
Comment
Question by:komlaaa
  • 2
2 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12562698
its probably java running something else on your computer.
does the app you are running finsh?

0
 
LVL 92

Accepted Solution

by:
objects earned 1200 total points
ID: 12562705
btw instead of using a listener as you are currently doing you can instead just use:

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question