1 / 6

JOptionPane

JOptionPane. JOptionPane. Import javax.swing.JOptionPane Use showInputDialog () for input . Only string values can be input. To convert an input value from a string to an integer use the parseInt () method from the Integer class, use appleCount = Integer.parseInt ( appleString );.

Download Presentation

JOptionPane

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JOptionPane

  2. JOptionPane • Import javax.swing.JOptionPane • UseshowInputDialog() for input . • Only string values can be input. • To convert an input value from a string to an integer use the parseInt() method from the Integer class, use appleCount = Integer.parseInt(appleString);

  3. JOptionPane • Output is displayed using the showMessageDialogmethod. JOptionPane.showMessageDialog(null, "The total number of fruits = " + totalFruitCount);

  4. JOptionPane Demo import javax.swing.JOptionPane; public class JOptionPaneDemo { public static void main(String[] args) { String appleString = JOptionPane.showInputDialog("Enter number of apples:"); intappleCount = Integer.parseInt(appleString); String orangeString= JOptionPane.showInputDialog("Enter number of oranges:"); intorangeCount = Integer.parseInt(orangeString); inttotalFruitCount = appleCount + orangeCount; JOptionPane.showMessageDialog(null, "The total number of fruits = " + totalFruitCount); System.exit(0); } }

  5. JOptionPane Sample Screen Output

  6. JOptionPane Cautions • If the input is not in the correct format, the program will crash. • If you omit the last line (System.exit(0)), the program will not end, even when theOK button in the output window is clicked. • Always label any output.

More Related