Tuesday, 3 February 2015

Filled Under:

How to create exit option pane in java


Before creating OptionPane we need to understand What is OptionPane  in Java.

OPTION PANE IN JAVA:


It makes easy for a user to standard dialog box .OptionPane is use   to  show message,error,question and warning  to a user and we can use four standard icons for these situations.It is an independent sub window.
In this tutorial i have created option pane of question type therefore it has question icon. 

CODING:

import javax.swing.*;

import java.awt.*;

class myjframe1 extends JFrame 

{


public myjframe1() {

JOptionPane jp = new JOptionPane();

Object[] options = { "YES", "NO" };

JDialog.setDefaultLookAndFeelDecorated(true);

int button = jp.showOptionDialog(null,

" DO YOU WANT TO EXIT " , "Exit Confirmation",JOptionPane.DEFAULT_OPTION,JOptionPane.QUESTION_MESSAGE,

null, options, options[1]);

if (button == 0) {A

System.exit(0) ;}

}

}

class exit

{

public static void main(String args[])

{

myjframe1 x= new myjframe1();

}

}

OUTPUT:






 

0 comments:

Post a Comment