Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calling Month names by first three letters

807600Nov 8 2007 — edited Nov 8 2007
I'm trying to synchronize the dateSpinner with the Day, Month, and Year spinners. however, the information I'm getting from dateInfo is a string with the first three letters of the month, and the setValue function takes an integer. The spinnerMonth is created with an array:
private JSpinner spinnerMonth = new JSpinner
    (new SpinnerListModel(Arrays.asList(monthNames).subList(0, 12)));
Anyhow, all I need is to be able to re-call the assigned integer in the array based on the first three letters, if that's even possible? I'm just trying to avoid have a 12-case if-loop.
  private void updateOthers() 
  {
	  String dateInfo = spinnerDate.getValue().toString();
	  
	  String tempDay = dateInfo.substring(8,10);
	  int day1 = Integer.parseInt(tempDay);
	  
	  String tempMonth = dateInfo.substring(4,7);
	  int month1 = Integer.parseInt(tempMonth);
	  
	  String tempYear = dateInfo.substring(24,28);
	  int year1 = Integer.parseInt(tempYear);
	  
	  spinnerDay.setValue(day1);
	  //spinnerMonth.setValue(month1);
	  spinnerYear.setValue(year1);
  }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 6 2007
Added on Nov 8 2007
9 comments
453 views