NEED URGENT HELP! (JOptionPane)

Hi. Can someone help me figure out what is wrong with the JOptionPane.showMessageDialog box? The program was working fine until i used JOptionPane. Its showing me the input but not the messages..
p.s. I am using Eclipse
-----------------------------------
package Assigments;

import java.util.Scanner;
import javax.swing.JOptionPane;


public class DaysInMonth {

public static void main(String[] args) {

// create a Scanner
Scanner input = new Scanner(System.in);

int numMonths = Integer.parseInt (JOptionPane.showInputDialog("Enter a Month:"));
//String month = JOptionPane.showInputDialog("Enter a Month:");
JOptionPane.showInputDialog("Enter a Year:");
int year = input.nextInt();
int[] myList = {31,28,31,30,31,30,31,31,30,31,30,31};

//Check if the year is a leap year
boolean isLeapYear=
(year % 4 == 0 && year % 100 !=0)||(year % 400 == 0);
// if leap year is true then check for the month and display number of days
if(isLeapYear){
if (numMonths==2)
{
JOptionPane.showMessageDialog(null,numMonths + "/" + year + " has 29 days");
}
else{

JOptionPane.showMessageDialog(null,numMonths + "/" + year + " " + myList[numMonths-1] + " days. ");

}}
else{
JOptionPane.showMessageDialog(null,numMonths + "/" + year + " " + myList[numMonths-1] + " days. ");


}
//Display the result

Comments

  • Have a look at how you're retrieving the months (which is working) and how you're retrieving the years (which isn't working).

    There is something subtly different that you are doing which is causing the broken behaviour.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion