Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

TabbedPane exit

Posted on 2000-02-20
4
Medium Priority
?
245 Views
Last Modified: 2006-11-17
Could someone show me how to make a Tab that says "Exit" and when you click on it, it exits the program?
0
Comment
Question by:Dmitriy
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:vivexp
ID: 2542127
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);
       }


}

0
 
LVL 3

Author Comment

by:Dmitriy
ID: 2543731
Adjusted points to 50
0
 
LVL 3

Author Comment

by:Dmitriy
ID: 2543732
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?
0
 
LVL 1

Accepted Solution

by:
vivexp earned 400 total points
ID: 2544713
Hi,
    Try this out import javax.swing.event.*;  

Best of luck
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

926 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