Solved

TabbedPane exit

Posted on 2000-02-20
4
236 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
Comment Utility
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
Comment Utility
Adjusted points to 50
0
 
LVL 3

Author Comment

by:Dmitriy
Comment Utility
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 100 total points
Comment Utility
Hi,
    Try this out import javax.swing.event.*;  

Best of luck
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now