Solved

TabbedPane exit

Posted on 2000-02-20
4
238 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 100 total points
ID: 2544713
Hi,
    Try this out import javax.swing.event.*;  

Best of luck
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

810 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