3 Replies - 3738 Views - Last Post: 12 January 2004 - 10:35 PM Rate Topic: -----

#1 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4428
  • View blog
  • Posts: 28,356
  • Joined: 21-March 01

First Shot At Java

Posted 12 January 2004 - 03:25 PM

import javax.swing.*;//Allow JOptionPane
import java.io.*;//Allow input/output

class months//declare class 'months'
{
	public static void main(String[] args)//main function 
	{
  String month = JOptionPane.showInputDialog(null, //creates dialog box
  "Enter number for month, 1 to 12");//tells user what to do, closes dialog
  switch(month)
  {
 	 case 1: System.out.println("Jan"); break;
 	 case 2: System.out.println("Feb"); break;
 	 case 3: System.out.println("Mar"); break;
 	 case 4: System.out.println("Apr"); break;
 	 case 5: System.out.println("May"); break;
 	 case 6: System.out.println("Jun"); break;
 	 case 7: System.out.println("Jul"); break;
 	 case 8: System.out.println("Aug"); break;
 	 case 9: System.out.println("Sep"); break;
 	 case 10: System.out.println("Oct"); break;
 	 case 11: System.out.println("Nov"); break;
 	 case 12: System.out.println("Dec"); break;
 	 default: System.out.println("Please Try Again"); break;
  }
  System.exit(0);//exits system
	}	
}


im just looking to print out the month name based on a number input via jinputpane. what happens is the switch doesnt work cause joption has to be string, and switch has to be int. sucks. so i need a way to convert string to int, or help using the built in date function in java which i cant figure out for anything.

the only requirement is that i have to use joptionpane.

Is This A Good Question/Topic? 0
  • +

Replies To: First Shot At Java

#2 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4428
  • View blog
  • Posts: 28,356
  • Joined: 21-March 01

Re: First Shot At Java

Posted 12 January 2004 - 03:45 PM

bingo
int m=Integer.parseInt(month);


hehe, then i do the switch on the variable m.

works good, but if anyone wants to give me a rundown of how i would use the date functions in this what would be awesome.
Was This Post Helpful? 0
  • +
  • -

#3 illustrain  Icon User is offline

  • Voltron's Daddy
  • member icon

Reputation: 8
  • View blog
  • Posts: 1,597
  • Joined: 27-April 01

Re: First Shot At Java

Posted 12 January 2004 - 04:54 PM

good job.

Posted Image
Was This Post Helpful? 0
  • +
  • -

#4 cyberscribe  Icon User is offline

  • humble.genius
  • member icon

Reputation: 10
  • View blog
  • Posts: 1,062
  • Joined: 05-May 02

Re: First Shot At Java

Posted 12 January 2004 - 10:35 PM

supersloth, on Jan 12 2004, 03:45 PM, said:

if anyone wants to give me a rundown of how i would use the date functions in this what would be awesome.

Date is an object in Java that represents a specific moment in time. From a properly constructed Date object you can get out all kinds of formatted date output. But you have to construct it with (at least) a year, month, and day. So, I'm assuming if your application is a "real world" calendaring application you will have these variables as part of your program. If so, roll them into a Date object for easy manipulation and output. Here's more info:

http://java.sun.com/.../util/Date.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1