JOptionPane

JOptionPane

  1. Write a Java Program with file name SectionB.java using Switch control Statement

The program will use the JOptionPane and ask the user to enter any number between 1 to 12.

Based on the input, then the program will show how many days in that month. For example if the user enters 1, the program will show â??The Month you entered is January and it has 31 daysâ??. The output will be shown in the JOptionpane.

  1. Now modify the program; if the user enters â??2â?? the program will ask the user if it is a leap year. If the answer from the user is â??Yesâ?? it will show the message â??February has 29 daysâ??, if the response from the user is â??Noâ?? it will show â??February has 28 daysâ??. Again, the output should be shown in JOptionPane.

NOTE:

[In this program use try and catch block to handle any unacceptable and invalid input from the user]

View Answers

March 21, 2011 at 12:01 PM

  1. Write a Java Program with file name SectionB.java using Switch control Statement

The program will use the JOptionPane and ask the user to enter any number between 1 to 12.

Based on the input, then the program will show how many days in that month. For example if the user enters 1, the program will show â??The Month you entered is January and it has 31 daysâ??. The output will be shown in the JOptionpane.

  1. Now modify the program; if the user enters â??2â?? the program will ask the user if it is a leap year. If the answer from the user is â??Yesâ?? it will show the message â??February has 29 daysâ??, if the response from the user is â??Noâ?? it will show â??February has 28 daysâ??. Again, the output should be shown in JOptionPane.

NOTE:

[In this program use try and catch block to handle any unacceptable and invalid input from the user]


March 25, 2011 at 4:22 PM

import javax.swing.*;
import java.util.*;
import java.text.*;

class SectionB{
    static String getMonthName(int m) {
    String month = "invalid";
    DateFormatSymbols dfs = new DateFormatSymbols();
    String[] months = dfs.getMonths();
    if (m >= 0 && m <= 11 ) {
        month = months[m];
    }
    return month;
}

    public static void main(String[] args){
            int days=0;
        String st=JOptionPane.showInputDialog(null,"Enter number between 1 and 12: ");
        int num=Integer.parseInt(st);
        switch(num){
            case 1:
            days=31;
            break;

            case 2:
            String str=JOptionPane.showInputDialog(null,"Is this a leap year?");
            if(str.equalsIgnoreCase("yes")){
            days=29;
            }
            else{
            days=28;
            }
            break;

            case 3: 
            days=31;
            break;

            case 4:
            days=30;
            break;

            case 5: 
            days=31;
            break;

            case 6:
            days=30;
            break;

            case 7: 
            days=31;
            break;

            case 8: 
            days=31;
            break;

            case 9: 
            days=30;
            break;

            case 10:
            days=31;
            break;

            case 11: 
            days=30;
            break;

            case 12: 
            days=31;
            break;

            default:
            System.out.println("Invalid!");
            System.exit(0);
        }
        JOptionPane.showMessageDialog(null,"The Month you entered is "+getMonthName(num-1)+" and it has "+days+" days");
    }
}









Related Tutorials/Questions & Answers:
joptionpane validation
joptionpane validation  import javax.swing.*; import java.util.regex.*; public class joptionpane { public static void main(String[] args... help me!i need to validate the user input on the joptionpane,and if the user
joptionpane - Java Beginners
joptionpane  Hi, I need joptionpane validation. I have joptionpane inputdialog textbox.I need to enter the string values only in the textbox for validation. Please send the sample code immediately. Its very urgent
Advertisements
joptionpane - Java Beginners
joptionpane   I need joptionpane showinputdialog textbox integer validation. Please send the sample code for me. Please its very urgent.... Thanks, Valarmathi  Hi Friend, Try the following code: import
joptionpane - Java Beginners
joptionpane  Hi, I need joptionpane showinputdialog textbox string validation. Please send the sample code for me. Please its very urgent.... Thanks, Valarmathi  Hi Friend, Try the following code: import
Array in JOptionPane - Java Beginners
Array in JOptionPane  Hello, I'm having trouble with printing an array in a JOptionPane. I am supposed to make a 2 dimensional int array called BlasTable. I'm supposed to use a method to print the array in a JOptionPane
joptionpane - Java Beginners
joptionpane  Hi, I need to change the JOptionpane foreground text color only. Please send the sample code. JOptionPane.showMessageDialog(createqmbutton, "Succesfully Create the Queue Manager", "Create Queue
Selection Using JoptionPane
Selection Using JoptionPane  Help, can someone provide me the code using JOptionPane for the following:- Part A 1) Prompt user to make 3 selection i.e 1)Orchid $4.00 2)Rose $2.50 3)Daisy $5.00 or 0 to Quit 2) if user
Get and Display using JOptionPane
from student, name and age, by using JOptionPane. Then display it. Really
joptionpane - Java Beginners
joptionpane  Hi, I need to hide the joptionpane message dialogs. import javax.swing.*; import java.util.regex.*; public class ValidateJOptionPane { public static void main(String[]args){ String input
JOptionPane - Java Beginners
and output should be via JOptionPane dialogue boxes. Examples are shown below
Set Color in JOptionPane
Set Color in JOptionPane       In this section, you will learn how to set color in JOptionPane. Now to do... following key value pair, we have set the background color for JOptionPane
JOptionPane Validation
JOptionPane Validation JOptionPane allow you to create dialog boxes easily... look complex. Here we are going to validate the textfield of JoptionPane dialog. JOptionPane String Validation We have used regular expression that 
Set delay time in JOptionPane
Set delay time in JOptionPane       In this section, you will learn how to set the time after which the message should be displayed using JOptionpane. For this, first of all we prompt
Set text color in JoptionPane
Set text color in JoptionPane In this section, you will learn how to set text color in JOptionPane. Now to do this, we have used UIManager class which... color for JOptionPane and background color for JPanel: um.put
Java ComboBox in JOptionPane
Java ComboBox in JOptionPane In this section, you will learn how to create combo box in JOptionPane dialog box. We have created a button to perform an action.On clicking the button, you will get the dialog box with combo box in it. 
Display JList value selected from the JOptionPane
Display JList value selected from the JOptionPane In this section, we are going to select the particular value from the JOptionPane combobox and displayed.... To proceed further, when the user click the button, the JOptionPane with combobox
While Loop with JOptionPane
Unable looping using JOptionPane - Java Beginners
Java Message Box
of the message box is used for error message. Using JOptionPane class you can create..._TO_REPLACE_1 There are  several feature JOptionPane like customizing icon... should appear on screen. JOptionPane icon let you decide which icon you want
Show Dialog Box in Java
messages to the user. In this section we will use JOptionPane class to display... description: JOptionPane Class: In non-swing application we were using System.in class... can use JOptionPane to show the output or show the message. This way
Java Alert Box
JOptionPane class to display the message alert box.  JOptionPane class is available in the javax.swing.*; package. JOptionPane is a swing application we can use JOptionPane to show message and we can use any java application. JOptionPane
Java error icon
; JOptionPane's icon support specify icon to which the dialog displays. We can use four standard icon using JOptionPane icons  like...;jop = new JOptionPane();     
java swings - Java Beginners
java swings  Hi, I have JoptionPane combobox,in the joptionpane jcombobox have array of values. If i select one value from the joptionpane combobox ,then the selected value will be displayed in the listbox. Please send
java swings - Java Beginners
java swings   Hi, I need the code for joptionpane with jcombobox. my requirement is click on add button,one joptionpane will come.from the option pane i need to select the combobox values. Please send the sample code
java swings - Java Beginners
java swings  Hi, I need the code for how can i set the joptionpane color(background and foreground). can i set the delay time for joptionpane display. Please send the code .its urgent. Thanks, Valarmathi
roob
the JOptionPane and ask the user to enter any number between 1 to 12. Based... and it has 31 daysâ??. The output will be shown in the JOptionpane. Now modify...??February has 28 daysâ??. Again, the output should be shown in JOptionPane
roob
the JOptionPane and ask the user to enter any number between 1 to 12. Based... and it has 31 daysâ??. The output will be shown in the JOptionpane. Now modify...?? it will show â??February has 28 daysâ??. Again, the output should be shown in JOptionPane
roob
the JOptionPane and ask the user to enter any number between 1 to 12. Based... and it has 31 daysâ??. The output will be shown in the JOptionpane. Now modify...?? it will show â??February has 28 daysâ??. Again, the output should be shown in JOptionPane
java coding
java coding  using swing i want to give an exit button which on clicking ask a msg "JOptionPane" is select "yes" then it should exit or else not....plez help me...... JOptionPane.showConfirmDialog(null,"DO YOU REALLY WANT
customer
object to check the current balance f. Use JOptionPane to allow a user enter a deposit. The program should display the new balance. g. Use JOptionPane to allow
JOptionPane.showMessageDialog(this, Ex.getMessage().toString());
with JOPtionPane class, like JOptionPaneERROR_MESSAGE. They are of integer type. So if you write 1, nothing will get happen. But if you will use JOptionPane
rob
or Square in JOPtionPane Question) and the number of shapes to be drawn. Based
rob
in JOPtionPane Question) and the number of shapes to be drawn. Based on the input
rob
in JOPtionPane Question) and the number of shapes to be drawn. Based
rob
in JOPtionPane Question) and the number of shapes to be drawn. Based on the input
rob
a shape type (Circle or Square in JOPtionPane Question) and the number of shapes
rob
in JOPtionPane Question) and the number of shapes to be drawn. Based on the input number
keyboard input
keyboard input  how do I use JOptionPane to accept keyboard input? I know how to import but not specific command on input line   import javax.swing.*; class JOPtionPaneExample { public static void main(String
java swings - Java Beginners
java swings  Hi, How can i set the color in joptionpane. Please send the code as soon as possible. Thanks, valarmathi  Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; public
Table
, JOptionpane, Integer.parseInt. Please use only these above methods to make table
java
repetitive processes and the JOptionPane method for input
java
java  Write a complete Java program that utilizes the JOptionPane method to get six names from the user and keep these names in an array of two rows and three columns named myNames[][]. Display all these twelve names in its
java
javax.swing.JFrame Import javax.swing. JOptionPane Import javax.swing.JButton etc
Student Marks
. (hint: used JOptionPane Class
Message Box Java
. Generally the message box is used to display error message. JOptionPane class... box and where the box must appear on screen. JOptionPane icon is used to create the icon you want to display. Though there are four standard JOptionPane
roov
the JOptionPane and ask the user to enter any number between 1 to 12. Based on the input... daysâ??. The output will be shown in the JOptionpane. Now modify...??February has 28 daysâ??. Again, the output should be shown in JOptionPane. NOTE
raaz
using Switch control Statement The program will use the JOptionPane and ask...??. The output will be shown in the JOptionpane. Now modify the program... daysâ??. Again, the output should be shown in JOptionPane. NOTE
need help - Swing AWT
need help  Create a program to correct and grade a set of multiple choice test result. this is a console program that uses JOptionPane dialog boxes as well. Must read a set of 10 correct answers, using a JOptionPane dislog box
java swings - Java Beginners
java swings  Hi, I have joptionpane inputmessage combobox . but hoew can i select the particular value in joptionpane jcombobox. Please send the sample code. This is very urgent.please help me. Thanks, Valarmathi. 
different output trying to execute same java code
from netbeans, JOptionPane showing "portList : true" but when i double click on the jar file and tried to run, JOptionPane showing "portList : false" Why

Ads