View Single Post
Old 05-14-2010, 07:13 AM   #6 (permalink)
miz_g6
New Member
 
Join Date: May 2010
Model: 9700
PIN: N/A
Carrier: Zain (Vodafone)
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i tried all that,, and every other possiblity but i still can't make it push the screeen.. i hv done some modification but I still get error if i pushed the screen without using UiApplication.getUiApplication().. :(.. I'm a nooooob and 'm so confused !!!

Code:
package com.rim.samples.GPAcal;


import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.i18n.*;
import java.lang.*;

import com.rim.samples.GPAcal.GPAcalScreen.SemGPAScreen;

public class GPAcal extends UiApplication{
	public static void main (String[] args)
	{
		GPAcal app= new GPAcal();
		 app.enterEventDispatcher();
		
	}
	public GPAcal()
	{
		pushScreen(new GPAcalScreen());
	}
}


final class GPAcalScreen extends MainScreen implements FieldChangeListener
{
	public ButtonField sms;
	public ButtonField cum;
	public ButtonField major;
	
	
	
	public GPAcalScreen()
	{
	super();
	LabelField title = new LabelField("GPA Calculator",
            LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
		setTitle(title);

		add(new RichTextField("Choose type of GPA you want to calculate:"));
	
		sms= new ButtonField ("Semester GPA",ButtonField.FIELD_HCENTER|ButtonField.FIELD_VCENTER|ButtonField.VCENTER|ButtonField.HCENTER|ButtonField.CONSUME_CLICK);
		sms.setChangeListener(this);
		cum= new ButtonField ("Cumulative GPA",ButtonField.FIELD_HCENTER|ButtonField.FIELD_VCENTER|ButtonField.VCENTER|ButtonField.HCENTER|ButtonField.CONSUME_CLICK);
		cum.setChangeListener(this);
		major= new ButtonField ("Major GPA",ButtonField.FIELD_HCENTER|ButtonField.FIELD_VCENTER|ButtonField.VCENTER|ButtonField.HCENTER|ButtonField.CONSUME_CLICK);
		major.setChangeListener(this);
		add(sms);
		add(major);
		add(cum);
		
	}

		public void fieldChanged(Field field, int context)
			{
				
				if(field==sms)
				pushScreen(new  SemGPAScreen());
			}
				
		
		// when Exiting the software
		public boolean onClose()
	      {
	             System.exit(0);
	              return true;
	      }


	
	// Semester GPA screen	
	  class SemGPAScreen extends MainScreen 
	{
		private BasicEditField sub[];
		private ObjectChoiceField crd[];
		private ObjectChoiceField grd[];
		String[] credits={"3","4"};
		String[] grades={"A","A-","B+","B","B-","C+","C","C-","D+","D","F"};
		String totC;
		String cumG; 
		float gr=0;
		float cr=0;
		float total=0;
		
		public SemGPAScreen()
		{
			super();
			add(new RichTextField("Subject: "));
			add(new RichTextField("Credits: "));
			add(new RichTextField("Grades: "));
			for (int i=0; i<7; i++)
			{
				sub[i]= new BasicEditField(Field.EDITABLE);
				add(sub[i]);
				crd[i]= new ObjectChoiceField("", credits);
				add(crd[i]);
				grd[i]= new ObjectChoiceField("", grades);
				add(grd[i]);
			}
			BasicEditField cumg= new BasicEditField("Current GPA:", cumG, 4,Field.EDITABLE);
			BasicEditField tot= new BasicEditField("Credits Passed:", totC,3,Field.EDITABLE);
			add(cumg);
			add(tot);
			
			float cg= Float.parseFloat(cumG);
			float tt= Float.parseFloat(totC);
			for (int j=0; j<7; j++)
			{
				
				if(crd[j].getSelectedIndex()==0)
				{
					cr+=3;
				gr=Cal(j);
				total+=cr*gr;
				}
				
				else
				{		
					cr+=4;
					gr=Cal(j);
					total+=cr*gr;
					
				}
			}
			float semesterGPA= (total+cg)/(cr+tt);
			Dialog.alert(" Your GPA for this semester will be"+semesterGPA);
		}
			
			public float Cal(int k)
			{
					if(grd[k].getSelectedIndex()==0)
					{
						gr+=4.00;
						return gr;
					}
					else if (grd[k].getSelectedIndex()==1)
					{
						gr+=3.67;
						return gr;
					}
					else if (grd[k].getSelectedIndex()==2)
					{
						gr+=3.33;
						return gr;
					}
					else if (grd[k].getSelectedIndex()==3)
					{
						gr+=3.00;
						return gr;
					}
					else if (grd[k].getSelectedIndex()==4)
					{
						gr+=2.67;
						return gr;
					}
					else if (grd[k].getSelectedIndex()==5)
					{
						gr+=2.33;
						return gr;
					}
					else if (grd[k].getSelectedIndex()==6)
					{
						gr+=2.00;
						return gr;
					}
					else if (grd[k].getSelectedIndex()==7)
					{
						gr+=1.67;
						return gr;
					}
					else if (grd[k].getSelectedIndex()==8)
					{
						gr+=1.33;
						return gr;
					}
					else if (grd[k].getSelectedIndex()==9)
					{
						gr+=1.00;
						return gr;
					}
					else
					{
						gr+=0.00;
						return gr;
					}
				}
					
				
			
	}
	
	
}

Last edited by miz_g6 : 05-14-2010 at 07:16 AM.
Offline   Reply With Quote