Link to home
Start Free TrialLog in
Avatar of Dmitriy
DmitriyFlag for United States of America

asked on

TabbedPane exit

Could someone show me how to make a Tab that says "Exit" and when you click on it, it exits the program?
Avatar of vivexp
vivexp

Hi,

if jtp is a JTabbedPane, add the change listener like this

class aa implements ChangeListener{

public   aa(){

///code
    jtp.addChangeListener (this);

///code
}

 public void stateChanged(ChangeEvent e){
       System.out.println (" change occurred at " + jtp.getSelectedIndex ());
// Get the index of  the tab say(1)
       if(jtp.getSelectedIndex ()==1){
        System.exit (0);
       }


}

Avatar of Dmitriy

ASKER

Adjusted points to 50
Avatar of Dmitriy

ASKER

How do I import ChangeListener?  I get a message that the interface not found.

Here is what I have so far... I made two tabs that have different properties.  One of them has name Exit.  

tabbedPane.addTab("Exit",null,panel3, "Exit");
where panel3 is Component type, which will have a function Exit().  This function will have to have the necessary code to exit the program. Is it possible to make it in form of a function instead of a separate class?
ASKER CERTIFIED SOLUTION
Avatar of vivexp
vivexp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial