Evernote API Sandbox Config using Java Scribe

I had some difficulty in the beginning to setup Evernote using the Scribe library as by default the Scribe uses the Public API and not the Sandbox API that Evernote first gives you. You can then register you app with Evernote to get it Publicly available and then swap to the Public API class in Scribe.

package com.example.controller;

import static org.springframework.web.context.request.RequestAttributes.SCOPE_SESSION;

import org.scribe.model.Token;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;

import com.example.oauth.OAuthServiceProvider;

import java.util.Map;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
 	
	@Autowired
	@Qualifier("evernoteServiceProvider")
	private OAuthServiceProvider evernoteServiceProvider;
	
    @RequestMapping(value="/login-evernote", method=RequestMethod.GET)
    public String loginToCloudSoleDevelop(Map<String, Object> map, WebRequest request) 
    {
    	// getting request and access token from session
		Token requestToken = (Token) request.getAttribute("oauthRequestToken", SCOPE_SESSION);
		Token accessToken = (Token) request.getAttribute("oauthAccessToken", SCOPE_SESSION);
		if(requestToken == null || accessToken == null) {
			// generate new request token
			OAuthService service = evernoteServiceProvider.getService();
			requestToken = service.getRequestToken();
			request.setAttribute("oauthRequestToken", requestToken, SCOPE_SESSION);
			
			// redirect to twitter auth page
			//service.getAuthorizationUrl(requestToken)
			System.out.println("RequestToken: " + requestToken.getToken());
			return "redirect:" + String.format("https://sandbox.evernote.com/OAuth.action?oauth_token=%s", requestToken.getToken());
		}
		return "login";
    }
    
    @RequestMapping(value={"/login"}, method = RequestMethod.GET)
	public ModelAndView callback(@RequestParam(value="oauth_token", required=false) String oauthToken,
			@RequestParam(value="oauth_verifier", required=false) String oauthVerifier, WebRequest request, Map<String, Object> map) {
		
		// getting request token
		OAuthService service = evernoteServiceProvider.getService();
		Token requestToken = (Token) request.getAttribute("oauthRequestToken", SCOPE_SESSION);
		
		// getting access token
		Verifier verifier = new Verifier(oauthVerifier);
		Token accessToken = service.getAccessToken(requestToken, verifier);
		
		// store access token as a session attribute
		request.setAttribute("oauthAccessToken", accessToken, SCOPE_SESSION);
		
		ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
		HttpSession session = attr.getRequest().getSession(true); //create a new session
		session.setAttribute("accessToken",accessToken);
		
		ModelAndView mav = new ModelAndView("redirect:notes");
		return mav;
	}
}

Application Config

Note use the org.scribe.builder.api.EvernoteApi.Sandbox and not org.scribe.builder.api.EvernoteApi as this is the public Evernote API.

<bean id="evernoteServiceConfig" class="com.example.oauth.OAuthServiceConfig">
		<constructor-arg value="YOURTOKEN" />
		<constructor-arg value="YOURSECURITYKEY"/>
		<constructor-arg value="YOURURLREDIRECT"/>
		<constructor-arg value="org.scribe.builder.api.EvernoteApi.Sandbox"/>
	</bean>
<bean id="evernoteServiceProvider" class="com.example.oauth.OAuthServiceProvider">
		<constructor-arg name="config" ref="evernoteServiceConfig" />
</bean>

Java Code: Export Salesforce Attachements to Dropbox

I wrote a class the exports Salesforce Attachements to be exported to your local Machine. I put the exported attachement files in a dropbox folder which is automatically the shared with others in the organization.

Note: make sure the export directory is shared on Dropbox.

package com.thys.michels.sfdc.doc;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;

import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.sobject.Attachment;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;

public class SFDCDoc {

	/**
	 * @param args
	 * @throws NumberFormatException 
	 * @throws IOException 
	 * @throws URISyntaxException 
	 * @throws DOMException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException, URISyntaxException {
		// TODO Auto-generated method stub
		

	   //Create a new connectionconfig to your Salesforce Org
	    ConnectorConfig sfconfig = new ConnectorConfig();
	    //Use your salesforce username = email
	    sfconfig.setUsername("yourusername");
	    //Use your saleforce password with your security token look like: passwordjeIzBAQKkR6FBW8bw5HbVkkkk
	    sfconfig.setPassword("passwordwithsecuritytoken");
	 
	    EnterpriseConnection partnercon = null;
	    
	    try {
	    	 
	        // create a salesforce connection object with the credentials supplied in your connectionconfig
	        partnercon = Connector.newConnection(sfconfig);
	        QueryResult describeGlobalResult = partnercon.query("select Id, Name, Body from Attachment where ContentType='application/pdf'");
	        System.out.println(describeGlobalResult.getRecords().length);
	        boolean done = false;
	     
	        while(!done)
	        {
	        	for (int k = 0; k < describeGlobalResult.getRecords().length; k++)
	        	{
	        		
	        	    Attachment a = (Attachment)describeGlobalResult.getRecords()[k];
	        	    File path = new File("//Users//tmichels//Dropbox//SFDCAttachments");
	        	    String mySubFolder = a.getId();
	        	    File newDir = new File(path + File.separator + mySubFolder);
	        	    System.out.println(newDir);
	        	    boolean success = newDir.mkdirs();
	        	    FileOutputStream fos = new FileOutputStream(newDir + File.separator+ a.getName());
	        	    fos.write(a.getBody());
	        	    fos.close();
	        	}
	        	if (describeGlobalResult.isDone()) {
	                done = true;
	             } else {
	            	 describeGlobalResult = partnercon.queryMore(describeGlobalResult.getQueryLocator());
	             }
	        }
	        
	        
	    } catch (ConnectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
	    }
	}
}

Two ways to Check Unique Char using Java

/**
 * 
 */
package com.thys.michels;

import java.util.HashSet;

/**
 * @author tmichels
 *
 */
public class Question1_1 {

	/**
	 * Use a hash map to count the amount of same values and see if all are 1. Using an HashMap
	 */
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String[] words = {"abcde", "hello", "apple", "kite", "padle"};
        for (String word : words) 
        {
                System.out.println(word + ": " + isUniqueChars(word) + " " + isUniqueChars2(word));
        }
	}
	//public static char[] getchararray;
	private static boolean isUniqueChars2(String word) {
		//unicode value of an char int charat
		for (int k = 1; k < word.length() -1 ; k++)
		{
			for (int m = 0; m < k; m++)
			{
				if ((int) word.charAt(m) == (int) word.charAt(k))
				{
					return false;
				}
			}		
		}
		
		return true;
	}

	private static boolean isUniqueChars(String word) {
		// TODO Auto-generated method stub
		HashSet wordset = new HashSet();
		for (int k = 0; k < word.length(); k++)
		{
			wordset.add(word.charAt(k));
		}
		if (wordset.size() == word.length())
		{
			return true;
		}
		else
			return false;
	}

}

Web Services from Stateless Session EJB3 with Websphere Integration Developer

How to create a bottoms-up Websphere with Websphere Integration Developer that is deployed to Websphere Application Server V7.

Below is the steps to create an simple Web Service using Websphere Integration Developer:

1. Open up Websphere Integration Developer and create an new EJB Project

Step 2: Click on the ‘New’ button to create a new EAR Membership.

The following 3 files will be created

Step 3: Create a new Stateless Session Bean

Step 4: Complete the following information below (Important to select Remote)

Step 5: Open the Bank interface object and add a method.

Step 6: Open your Stateless Session Bean File and right click and select ‘Override/Implementation Methods’, make sure the @Override notation is added to your code (see in red block)

Step 7: Add code inside your method

Step 8: Verify that there is no error.

Step 9: Add an Application Server to your WID IDE and start the server.

Step 10: Right click on your Application Server and click on ‘Add and Remove Projects’ and Select the BankAccount project

Step 11: Verify that the Application Server has successfully synchronized the new project and no errors occurred.

Step 12: Creating the Web Service is done in the following Steps, right click on your Stateless Session Bean and Select Web Service -> Create Web Service.  Your will see the following screens:

Confirm that the right Server type is selected, being WAS, WPS, WBM or any Application Server

For this example the binding type is HTTP, you can change it to JMS or EJB.

As we only have one method, select the method BankAccount. WS-Security can be added in this step to create a more secure Web Service.

Optional you can deploy your WSDL to the Websphere UDDI for Web Services discovery. Click Finish to complete. Confirm that Web Service creation was successful.

Step 13. Test your new Web Service by opening Web Services Explorer and browsing for the Bank.wsdl

Step 14: Enter the relevant information into the two fields provided and click ‘GO’

Web Service Completed successfully.  This Web Services can now be deployed to Websphere Registry and Repository to be discovered by all other systems in your environment.

Java Binary-to-Decimal Converter

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BinaryConverter
{
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
System.out.println(“Please select one of the following options: “);
System.out.println(“1. Decimal to Binary: “);
System.out.println(“2. Binary to Decimal:”);
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
Integer input = Integer.parseInt(bf.readLine());
System.out.println(“———————————————“);
if (input == 1)
{
BufferedReader bf1 = new BufferedReader(new InputStreamReader(System.in));
String input1 = bf1.readLine();
Converter con = new Converter();
System.out.println(“Answer: ” + con.TransInputbin(input1));
System.out.println(“———————————————“);
}
else
if (input == 2)
{
BufferedReader bf2 = new BufferedReader(new InputStreamReader(System.in));
String input2 = bf2.readLine();
Converter con = new Converter();
System.out.println(“Answer: ” + con.setInput(input2));
System.out.println(“———————————————“);
}
}
}

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;
public class BinaryConverter { public static void main(String[] args) throws IOException  { // TODO Auto-generated method stub System.out.println(“Please select one of the following options: “); System.out.println(“1. Decimal to Binary: “); System.out.println(“2. Binary to Decimal:”); BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); Integer input = Integer.parseInt(bf.readLine()); System.out.println(“———————————————“); if (input == 1) { BufferedReader bf1 = new BufferedReader(new InputStreamReader(System.in)); String input1 = bf1.readLine(); Converter con = new Converter(); System.out.println(“Answer: ” + con.TransInputbin(input1)); System.out.println(“———————————————“); } else if (input == 2) { BufferedReader bf2 = new BufferedReader(new InputStreamReader(System.in)); String input2 = bf2.readLine(); Converter con = new Converter(); System.out.println(“Answer: ” + con.setInput(input2)); System.out.println(“———————————————“); } }}

Raptor – Java fighter pilot game!

import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseListener;
import java.util.Random;
import static java.lang.Thread.sleep;
public class SetApplet extends Applet implements Runnable {
private static final long serialVersionUID = 1L;
private boolean shoot;
int startX, startY, endX, endY;
Color color;
Image img;
Thread newplane = null;
Integer counter = 50;
Integer[] plainy = new Integer[5];
Boolean[] hit = new Boolean[5];
String[] picname = new String[4];
Integer[] picval = new Integer[5];
Integer score = 0;
Integer level = 0;
// [Todo: Set Applet width and height and Applet Area]
public void init() {
img = null;
endX = 51;
endY = 600;
picname[0] = “plane1.png”;
picname[1] = “plane1.png”;
picname[2] = “plane2.png”;
picname[3] = “plane3.png”;
}
public void loadImage(String filename) {
try {
img = getImage(getDocumentBase(), filename);
} catch (Exception e) {
System.out.println(e);
}
}
public SetApplet() {
MouseMotionListener planemove = new MouseMotionListener() {
public void mouseDragged(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseMoved(MouseEvent arg0) {
if (endX >= 50 && endX <= 630) {
endX = arg0.getX();
endY = arg0.getY();
repaint();
}
if (endX <= 50) {
endX = arg0.getX();
endY = arg0.getY();
repaint();
}
if (endX >= 630) {
endX = arg0.getX();
endY = arg0.getY();
repaint();
}
}
};
addMouseMotionListener((MouseMotionListener) planemove);
MouseListener planeshoot = new MouseListener() {
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent arg0) {
repaint();
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent arg0) {
color = Color.RED;
shoot = true;
endX = arg0.getX();
endY = arg0.getY();
repaint();
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
color = Color.white;
shoot = false;
repaint();
}
};
addMouseListener((MouseListener) planeshoot);
}
Integer k = 50;
Integer counteriter = 0;
public void paint(Graphics g) {
g.setFont(new Font(“Arial”, Font.BOLD, 20));
g.setColor(Color.BLUE);
g.drawString(“Welcome to Raptor”, 20, 20);
g.drawString(“Score ” + score.toString() , 800, 680);
g.drawString(“Level ” + level.toString() , 800, 700);
Boolean flagallshotdown = true;
counteriter = counteriter + 1;
if (counter == 50) {
for (int m = 0; m < 5; m++) {
// newplane= new Thread(this);
Random random = new Random();
hit[m] = false;
plainy[m] = showRandomInteger((120 * m) + 50, 120 * (m + 1),
random);
picval[m] = showRandomInteger(0, 3, random);
}
}
g.drawRect(20, 20, 700, 700);
if (endX >= 50 && endX <= 630) {
loadImage(“plane.png”);
g.drawImage(img, endX, 600, 59, 87, this);
if (shoot == true) {
g.setColor(color);
g.drawLine(endX + 29, 20, endX + 29, 600);
for (int l = 0; l < 5; l++) {
if (endX + 29 > plainy[l] && endX + 29 < plainy[l] + 50) {
// g.drawImage(img, 700, 700, 0, 0, null);
hit[l] = true;
score = score + 5;
if (score % 100 == 0)
{
level = level + 1;
}
}
}
}
if (shoot == false) {
g.setColor(color);
g.drawLine(0, 0, 0, 0);
}
// newplane.start();
if (counter < 550) {
for (int p = 0; p < 5; p++) {
if (hit[p] == false) {
try {
flagallshotdown = false;
loadImage(picname[picval[p]]);
g.drawImage(img, plainy[p], counter, 50, 50, this);
//sleep(5);
g.drawLine(plainy[p], counter+50+score, plainy[p], counter + 55+score);
counter = counter + 1;
sleep(20-level);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// }
}
} else if (counter == 550)
counter = 50;
if (flagallshotdown == true)
counter = 50;
}
else {
if (endX > 631) {
if (counter < 550) {
for (int p = 0; p < 5; p++) {
if (hit[p] == false) {
try {
loadImage(picname[picval[p]]);
g.drawImage(img, plainy[p], counter, 50, 50,
this);
counter = counter + 1;
sleep(20-level);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// }
}
} else if (counter == 550)
counter = 50;
if (shoot == true) {
g.setColor(color);
g.drawLine(630 + 29, 20, 630 + 29, 600);
for (int l = 0; l < 5; l++) {
if (endX + 29 > plainy[l] && endX + 29 < plainy[l] + 50) {
// g.drawImage(img, 700, 700, 0, 0, null);
hit[l] = true;
//score = score + 10;
if (score % 100 == 0)
{
level = level + 1;
}
}
}
}
if (shoot == false) {
g.setColor(color);
g.drawLine(0, 0, 0, 0);
}
}
if (endX < 50) {
if (counter < 550) {
for (int p = 0; p < 5; p++) {
if (hit[p] == false) {
try {
loadImage(picname[picval[p]]);
g.drawImage(img, plainy[p], counter, 50, 50,
this);
counter = counter + 1;
sleep(20-level);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// }
}
} else if (counter == 550)
counter = 50;
if (shoot == true) {
g.setColor(color);
g.drawLine(50 + 29, 20, 50 + 29, 600);
for (int l = 0; l < 5; l++) {
if (endX + 29 > plainy[l] && endX + 29 < plainy[l] + 50) {
// g.drawImage(img, 700, 700, 0, 0, null);
hit[l] = true;
//score = score + 10;
if (score % 100 == 0)
{
level = level + 1;
}
}
}
}
if (shoot == false) {
g.setColor(color);
g.drawLine(0, 0, 0, 0);
}
}
}
}
private int showRandomInteger(int aStart, int aEnd, Random aRandom) {
if (aStart > aEnd) {
throw new IllegalArgumentException(“Start cannot exceed End.”);
}
// get the range, casting to long to avoid overflow problems
long range = (long) aEnd – (long) aStart + 1;
// compute a fraction of the range, 0 <= frac < range
long fraction = (long) (range * aRandom.nextDouble());
int randomNumber = (int) (fraction + aStart);
return randomNumber;
}
public void start() {
// user visits the page, create a new thread
if (newplane == null) {
newplane = new Thread(this);
newplane.start();
}
}
@SuppressWarnings(“deprecation”)
public void stop() {
if (newplane != null && newplane.isAlive())
newplane.stop();
newplane = null;
}
public void run() {
while (newplane != null) {
// if (paintplane == true)
// {
repaint();
// }
// Now the reason for threads
try {
Thread.sleep(100-(level*5));
} catch (InterruptedException e) {
System.out.println(e);
}
}
}
public void destroy() {
// destroy it.
newplane = null;
}
}

import java.applet.Applet;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.Image;import java.awt.event.MouseEvent;import java.awt.event.MouseMotionListener;import java.awt.event.MouseListener;import java.util.Random;
import static java.lang.Thread.sleep;
public class SetApplet extends Applet implements Runnable { private static final long serialVersionUID = 1L; private boolean shoot; int startX, startY, endX, endY; Color color; Image img; Thread newplane = null; Integer counter = 50; Integer[] plainy = new Integer[5]; Boolean[] hit = new Boolean[5]; String[] picname = new String[4]; Integer[] picval = new Integer[5]; Integer score = 0; Integer level = 0;
// [Todo: Set Applet width and height and Applet Area] public void init() { img = null; endX = 51; endY = 600; picname[0] = “plane1.png”; picname[1] = “plane1.png”; picname[2] = “plane2.png”; picname[3] = “plane3.png”; }
public void loadImage(String filename) { try { img = getImage(getDocumentBase(), filename); } catch (Exception e) { System.out.println(e); } }
public SetApplet() { MouseMotionListener planemove = new MouseMotionListener() { public void mouseDragged(MouseEvent arg0) { // TODO Auto-generated method stub
}
public void mouseMoved(MouseEvent arg0) { if (endX >= 50 && endX <= 630) { endX = arg0.getX(); endY = arg0.getY(); repaint(); } if (endX <= 50) { endX = arg0.getX(); endY = arg0.getY(); repaint(); } if (endX >= 630) { endX = arg0.getX(); endY = arg0.getY(); repaint(); } } };
addMouseMotionListener((MouseMotionListener) planemove);
MouseListener planeshoot = new MouseListener() { public void mouseClicked(MouseEvent arg0) { // TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent arg0) { repaint(); }
public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub
}
public void mousePressed(MouseEvent arg0) { color = Color.RED; shoot = true; endX = arg0.getX(); endY = arg0.getY(); repaint(); }
public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub color = Color.white; shoot = false; repaint(); } }; addMouseListener((MouseListener) planeshoot); }
Integer k = 50; Integer counteriter = 0;
public void paint(Graphics g) { g.setFont(new Font(“Arial”, Font.BOLD, 20)); g.setColor(Color.BLUE); g.drawString(“Welcome to Raptor”, 20, 20); g.drawString(“Score ” + score.toString() , 800, 680); g.drawString(“Level ” + level.toString() , 800, 700); Boolean flagallshotdown = true; counteriter = counteriter + 1; if (counter == 50) { for (int m = 0; m < 5; m++) { // newplane= new Thread(this); Random random = new Random(); hit[m] = false; plainy[m] = showRandomInteger((120 * m) + 50, 120 * (m + 1), random); picval[m] = showRandomInteger(0, 3, random); } } g.drawRect(20, 20, 700, 700); if (endX >= 50 && endX <= 630) { loadImage(“plane.png”); g.drawImage(img, endX, 600, 59, 87, this); if (shoot == true) { g.setColor(color); g.drawLine(endX + 29, 20, endX + 29, 600); for (int l = 0; l < 5; l++) { if (endX + 29 > plainy[l] && endX + 29 < plainy[l] + 50) { // g.drawImage(img, 700, 700, 0, 0, null); hit[l] = true; score = score + 5; if (score % 100 == 0) { level = level + 1; } } } } if (shoot == false) { g.setColor(color); g.drawLine(0, 0, 0, 0); }
// newplane.start(); if (counter < 550) { for (int p = 0; p < 5; p++) { if (hit[p] == false) { try { flagallshotdown = false;
loadImage(picname[picval[p]]); g.drawImage(img, plainy[p], counter, 50, 50, this); //sleep(5); g.drawLine(plainy[p], counter+50+score, plainy[p], counter + 55+score); counter = counter + 1; sleep(20-level); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // } } } else if (counter == 550) counter = 50; if (flagallshotdown == true) counter = 50; }
else { if (endX > 631) { if (counter < 550) { for (int p = 0; p < 5; p++) { if (hit[p] == false) { try {
loadImage(picname[picval[p]]); g.drawImage(img, plainy[p], counter, 50, 50, this);
counter = counter + 1; sleep(20-level); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // } } } else if (counter == 550) counter = 50;
if (shoot == true) { g.setColor(color); g.drawLine(630 + 29, 20, 630 + 29, 600); for (int l = 0; l < 5; l++) { if (endX + 29 > plainy[l] && endX + 29 < plainy[l] + 50) { // g.drawImage(img, 700, 700, 0, 0, null); hit[l] = true; //score = score + 10; if (score % 100 == 0) { level = level + 1; } } } } if (shoot == false) { g.setColor(color); g.drawLine(0, 0, 0, 0); } } if (endX < 50) { if (counter < 550) { for (int p = 0; p < 5; p++) { if (hit[p] == false) { try {
loadImage(picname[picval[p]]); g.drawImage(img, plainy[p], counter, 50, 50, this);
counter = counter + 1; sleep(20-level); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // } } } else if (counter == 550) counter = 50;
if (shoot == true) { g.setColor(color); g.drawLine(50 + 29, 20, 50 + 29, 600);
for (int l = 0; l < 5; l++) { if (endX + 29 > plainy[l] && endX + 29 < plainy[l] + 50) { // g.drawImage(img, 700, 700, 0, 0, null); hit[l] = true; //score = score + 10; if (score % 100 == 0) { level = level + 1; } } } } if (shoot == false) { g.setColor(color); g.drawLine(0, 0, 0, 0); } } } }
private int showRandomInteger(int aStart, int aEnd, Random aRandom) { if (aStart > aEnd) { throw new IllegalArgumentException(“Start cannot exceed End.”); } // get the range, casting to long to avoid overflow problems long range = (long) aEnd – (long) aStart + 1; // compute a fraction of the range, 0 <= frac < range long fraction = (long) (range * aRandom.nextDouble()); int randomNumber = (int) (fraction + aStart); return randomNumber; }
public void start() {
// user visits the page, create a new thread
if (newplane == null) { newplane = new Thread(this); newplane.start(); } }
@SuppressWarnings(“deprecation”) public void stop() {
if (newplane != null && newplane.isAlive()) newplane.stop(); newplane = null; }
public void run() {
while (newplane != null) { // if (paintplane == true) // { repaint(); // } // Now the reason for threads try { Thread.sleep(100-(level*5)); } catch (InterruptedException e) { System.out.println(e); } } }
public void destroy() { // destroy it. newplane = null; }}

Developing Web applications with the Java Persistence API and JavaServer Faces

The Java™ Persistence API (JPA) provides an easy mechanism to use with relational databases when you need applications to persist data. Although it is traditionally used with Enterprise Java™Beans (EJBs), JPA works quite well directly with Web applications. This article describes the simplified programming model and tools that IBM® Rational® Application Developer for WebSphere® Software Version 7.5 provides for easily building Web applications that use JPA.

http://www.ibm.com/developerworks/rational/library/08/0819_mutdosch/index.html