JOptionPane: Understanding Message Box in Java
Jun 3, 2015
Make sure to subscribe to our newsletter and be the first to know the news.
Jun 3, 2015
Make sure to subscribe to our newsletter and be the first to know the news.
JOptionPane |
DEFAULT_OPTION
YES_NO_OPTION
YES_NO_CANCEL_OPTION
OK_CANCEL_OPTION
int val=JOptionPane.showConfirmDialog(null, "message", "title", JOptionPane.YES_NO_OPTION);
Confirm Dialog |
ERROR_MESSAGE
INFORMATION_MESSAGE
WARNING_MESSAGE
QUESTION_MESSAGE
PLAIN_
MESSAGE
Object options[]={"Option 1","Option 2","Option 3"};
Object o=JOptionPane.showInputDialog(null,"Select a Name","Title",JOptionPane.PLAIN_MESSAGE,null,options,"Select Option");
Input Dialog |
JOptionPane.showMessageDialog(null, "message");
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class OptionDemo extends JFrame
{
JButton jbtnInput,jbtnMessage,jbtnSelect;
JFrame f=this;
OptionDemo()
{
super("Option Demo");
setSize(700,500);
setResizable(true);
setDefaultCloseOperation(3);
Container c=getContentPane();
setLayout(new FlowLayout());
jbtnInput=new JButton("Input");
jbtnInput.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
Object options[]={"Option 1","Option 2","Option 3"};
JOptionPane.showInputDialog(f,"Select a Name","Title",JOptionPane.PLAIN_MESSAGE,null,options,"Select Option");
}
});
c.add(jbtnInput);
jbtnSelect=new JButton("Confirm");
jbtnSelect.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showConfirmDialog(f, "message", "title", JOptionPane.YES_NO_OPTION);
}
});
c.add(jbtnSelect);
jbtnMessage=new JButton("Message");
jbtnMessage.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(f, "message");
}
});
c.add(jbtnMessage);
setVisible(true);
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(new com.jtattoo.plaf.hifi.HiFiLookAndFeel());
}
catch (Exception e)
{
e.printStackTrace();
}
new OptionDemo();
}
}