public class InputBilangan {
public static void main (String [] args) {
int bil1,bil2,jum;
String srt=JOptionPane.showInputDialog("Masukkan bilangan1 : ");
bil1=Integer.parseInt(srt);
String srt1=JOptionPane.showInputDialog("Masukkan bilangan2 : ");
bil2=Integer.parseInt(srt1);
jum=bil1+bil2;
JOptionPane.showMessageDialog(null, "Bilangan "+bil1+ "+"+"Bilangan "
+bil2+" ="+jum,"Hasil Penjumlahan",
JOptionPane.INFORMATION_MESSAGE);
}}
Penjelasan diambil dari : http://download.oracle.com/javase/1.5.0/docs/api/javax/swing/JOptionPane.html
| Method Name | Description | 
|---|---|
| showConfirmDialog | Asks a confirming question, like yes/no/cancel. | 
| showInputDialog | Prompt for some input. | 
| showMessageDialog | Tell the user about something that has happened. | 
| showOptionDialog | The Grand Unification of the above three. | 
Parameters:
The parameters to these methods follow consistent patterns:
When the selection is changed,
- parentComponent
 - Defines the
 Componentthat is to be the parent of this dialog box. It is used in two ways: theFramethat contains it is used as theFrameparent for the dialog box, and its screen coordinates are used in the placement of the dialog box. In general, the dialog box is placed just below the component. This parameter may benull, in which case a defaultFrameis used as the parent, and the dialog will be centered on the screen (depending on the L&F).- message
 - A descriptive message to be placed in the dialog box. In the most common usage, message is just a
 StringorStringconstant. However, the type of this parameter is actuallyObject. Its interpretation depends on its type:
- Object[]
 - An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive -- each object in the array is interpreted according to its type.
 - Component
 - The
 Componentis displayed in the dialog.- Icon
 - The
 Iconis wrapped in aJLabeland displayed in the dialog.- others
 - The object is converted to a
 Stringby calling itstoStringmethod. The result is wrapped in aJLabeland displayed.
- messageType
 
- Defines the style of the message. The Look and Feel manager may lay out the dialog differently depending on this value, and will often provide a default icon. The possible values are:
 
ERROR_MESSAGEINFORMATION_MESSAGEWARNING_MESSAGEQUESTION_MESSAGEPLAIN_MESSAGE
- optionType
 
- Defines the set of option buttons that appear at the bottom of the dialog box:
 
You aren't limited to this set of option buttons. You can provide any buttons you want using the options parameter.
DEFAULT_OPTIONYES_NO_OPTIONYES_NO_CANCEL_OPTIONOK_CANCEL_OPTION
- options
 
- A more detailed description of the set of option buttons that will appear at the bottom of the dialog box. The usual value for the options parameter is an array of
 Strings. But the parameter type is an array ofObjects. A button is created for each object depending on its type:
- Component
 - The component is added to the button row directly.
 - Icon
 - A
 JButtonis created with this as its label.- other
 - The
 Objectis converted to a string using itstoStringmethod and the result is used to label aJButton.
- icon
 
- A decorative icon to be placed in the dialog box. A default value for this is determined by the
 messageTypeparameter.
- title
 
- The title for the dialog box.
 
- initialValue
 
- The default selection (input value).
 
setValue is invoked,  which generates a PropertyChangeEvent.  If a
JOptionPane has configured to all input  setWantsInput  the bound property JOptionPane.INPUT_VALUE_PROPERTY   can also be listened  to, to determine when the user has input or selected a value.  When one of the
showXxxDialog methods returns an integer,   the possible values are:  YES_OPTIONNO_OPTIONCANCEL_OPTIONOK_OPTIONCLOSED_OPTION
- Show an error dialog that displays the message, 'alert':
 JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);- Show an internal information dialog with the message, 'information':
 JOptionPane.showInternalMessageDialog(frame, "information",- "information", JOptionPane.INFORMATION_MESSAGE);
 
- Show an information panel with the options yes/no and message 'choose one':
 JOptionPane.showConfirmDialog(null,- "choose one", "choose one", JOptionPane.YES_NO_OPTION);
 
- Show an internal information dialog with the options yes/no/cancel and message 'please choose one' and title information:
 JOptionPane.showInternalConfirmDialog(frame,- "please choose one", "information",
 
- JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
 
- Show a warning dialog with the options OK, CANCEL, title 'Warning', and message 'Click OK to continue':
 Object[] options = { "OK", "CANCEL" }; JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",- JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
 
- null, options, options[0]);
 
- Show a dialog asking the user to type in a String:
 String inputValue = JOptionPane.showInputDialog("Please input a value");- Show a dialog asking the user to select a String:
 Object[] possibleValues = { "First", "Second", "Third" }; Object selectedValue = JOptionPane.showInputDialog(null,- "Choose one", "Input",
 
- JOptionPane.INFORMATION_MESSAGE, null,
 
- possibleValues, possibleValues[0]);
 
Tidak ada komentar:
Posting Komentar