Java code of JOptionPane Dialogs

import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class TestDialogue extends JFrame implements ActionListener {
    JButton button1 =null;
    JButton button2 =null;
    JButton button3 =null;

  public TestDialogue() throws HeadlessException {
    setSize(200, 200);

    button1 = new JButton("Simple Message dialog");
    button2 = new JButton("Dialog with InputBox");
    button3 = new JButton("Yes/No dialog");

    setLayout(new FlowLayout(FlowLayout.CENTER));


  public static void main(String[] rk) {
	}catch(Exception e)
        new TestDialogue().setVisible(true);

    public void actionPerformed(ActionEvent e) {
    String Action;
    Action = e.getActionCommand ();

        if(Action.equals("Simple Message dialog")){
            JOptionPane.showMessageDialog((Component) e.getSource(), "Hello ! Thank you!");

        }else if(Action.equals("Dialog with InputBox")){
            String name = JOptionPane.showInputDialog((Component) e.getSource(), "Hello, please Input your name.");
            if (name != null && !name.equals("")) {
                JOptionPane.showMessageDialog((Component) e.getSource(), "Hi, " + name);

        }else if(Action.equals("Yes/No dialog")){

            int result = JOptionPane.showConfirmDialog((Component) e.getSource(), "Close this application?");
            if (result == JOptionPane.YES_OPTION) {
            } else if (result == JOptionPane.NO_OPTION) {
            System.out.println("No Action performed.");



About rajkirpal

i am a software engineer. and i have decent knowledge about java technologies like ANDROID, Servlet, Jsp, Struts, Hibernet, Spring, J2ME, Java Script, Ajax, JQuery, CSS. Further i am Preparing Easy understandable materials/documents upon the same java technologies and developing project in core java , advanced java and j2me , ANDROID as per the requirements Also designing the web sites and logos Thank You.
This entry was posted in J2SE. Bookmark the permalink.

One Response to Java code of JOptionPane Dialogs

  1. Pingback: Pane e Pizza « GUSTO E SAPORI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s