Open main menu

CDOT Wiki β

Changes

Teams Winter 2011/team2/lab3

1,496 bytes removed, 21:18, 21 March 2011
no edit summary
}
return found;
}
public void addCity(String nCity)
{
Random randomGenerator = new Random();
float temp = randomGenerator.nextFloat()+35;
float rain = randomGenerator.nextFloat()+10;
float snow = randomGenerator.nextFloat()+10;
float windspeed = randomGenerator.nextFloat()+50;
char winddirection = '.';
int r = randomGenerator.nextInt(4);
switch(r){
case 0:
winddirection = 'E';
break;
case 1:
winddirection = 'W';
break;
case 2:
winddirection = 'N';
break;
case 3:
winddirection = 'S';
break;
}
Weather w = new Weather(nCity, temp, rain, snow, windspeed, winddirection);
this.weathers.add(w);
System.out.println(w.toString());
}
[[File:FWindowpop3T2.png]]
*Now click on "File" within the menu bar and click "Exit", this will close the program based on the small application we created for that command.
*Another way of creating commands and classes on the fly is is by doing it through the manifest file. Lets do this other method '''Pre-emptive work for our print weather command. Follow the same directions previously of creating a command and enter the following information within the "Extension Element Details" view.[[File:CommT2.png]]*Now click later on the "defaultHandler" link, this should pop up java class creation wizard.[[File:Comm2T2.png]]'''*Once the "New Java Class" Window is active click on highlighted button below.[[File:NjwinT2.png]]*This should pop up another window containing every package (including default and empty) available within the project. Double-click "ecl.team2.lab3.commands", this should enter automatically to the text box Given that dictates where you want the class now have context of how to be stored.[[File:Njwin2T2.png]]*After completing the previous step, you will be back on the previous window (New Java Class). Since we require this java class to be used for create a command, we must have this class inherit the AbstractHandler class. We do this by clicking the "Browse..." button under the "Superclass" category.*A window will now progress to select your superclass appears. In the textbox, please enter "AbstractHandler". The textbox provides a means of searching for a particular class. From the search results, select the "AbstractHandler" creating commands that's located in "org.eclipse.core.commands". The reason for selecting this specific class is because it is the most up-to-date standard for creating handlers.[[File:ScT2.png]]*To ensure we include all methods necessary for will be used later within our handler to function properly, we will now add an interface called "IHandler". Click the button "Add" near "Interfaces" category. The process of adding an interface is very similar to adding a superclass except we must highlight the interface we want, click add (clicking add allows you to create a list of interfaces to included in your application), and then click okay. After searching for "IHandler", ensure the interface is located in "org.eclipse.core.commands".*You are now back to your original window. As you may have noticed, you still cannot Please create the class. The reason is incredibly quite simple, you haven't named the class yet. Next to name, enter the following in commands along with the textbox "PrintWeather". You should have something that looks like the image below:[[Filerequired items:Classl3-2T2.png]]*The java file is now in your editor and will contain something like this:<source lang=java>package ecl.team2.lab3.commands;
import org'''AddCityHandler'''For Commmand<pre>id: ecl.eclipseteam2.corelab3.commandsrcpExample.AbstractHandler;AddCityimport org.eclipse.core.commands.ExecutionEvent;name: Add Cityimport orgdefaultHandler: ecl.eclipseteam2.corelab3.commands.ExecutionException;AddCityHandlerimport org.eclipse.core.commands.IHandler;</pre>
public class PrintWeather extends AbstractHandler implements IHandler {For Menu Command<pre>commandId: ecl.team2.lab3.rcpExample.AddCitylabel: Add Citytooltip: Adds a city to list</pre>
@OverrideFor AddCityHandler.java public Object execute(ExecutionEvent event) throws ExecutionException { // TODO Auto-generated method stub return null; }<source lang=java>
}
</source>
*We will now change this to the snippet code below.
<source lang=java>
</source> ===Define and Use Editor===
1
edit