Solved

TabbedPane exit

Posted on 2000-02-20
4
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 238
xampp tool 12 58
type mismatch (Object[] to double[] 4 41
CSV file parsing thru Java 13 39
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

756 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