by the way, neither method worked natively in Processing, but i mixed the two methods (using the mysql wrapper library for db, but ImageIO for binary stream) and got it to compile in Eclipse. i had to do a bit of JAR tweaking, but it worked.
i'll get to writing my walkthrough for adding your applets to java programs.. but for now, here is the java source code.
MainClass.java
Code:package curseMap;
import de.bezier.mysql.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.imageio.ImageIO;
import processing.core.*;
// applet class
//
public class MainClass extends PApplet {
private static final long serialVersionUID = 1L;
ArrayList tiles = new ArrayList();
int[][] map = new int[9][9];
int x, y;
MySQL msql;
// initializing function
//
public void setup()
{
grabTiles();
x = 4;
y = 4;
grabMap("newbie_zone");
size(288, 288);
background(0);
}
// main applet function
//
public void draw()
{
for(int a = 0; a < 9; a++){
for(int b = 0; b < 9; b++){
image((PImage) tiles.get(map[a][b]), b*32, a*32);
}
}
noLoop();
}
// populate tiles list
//
public void grabTiles()
{
String db = "db";
String user = "user";
String password = "password";
int a = 0;
msql = new MySQL("some.server.com", db, user, password, this);
if(msql.connect()){
msql.query("select blob_content, blob_id from tiles__map order by blob_id asc");
while (msql.next()) {
try {
java.sql.Blob blob = msql.result.getBlob("blob_content");
InputStream is = blob.getBinaryStream();
Image raw = ImageIO.read(is);
PImage norm = new PImage(raw);
tiles.add(a++, norm);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
// populate map cells
//
public void grabMap(String mapName)
{
String tbl = "map__" + mapName;
String db = "db";
String user = "user";
String password = "password";
msql = new MySQL("some.host.com", db, user, password, this);
if(msql.connect()){
msql.query("select x, y, tile from " + tbl + " where "
+ "x >= " + (x - 4) + " AND "
+ "x <= " + (x + 4) + " AND "
+ "y >= " + (y - 4) + " AND "
+ "y <= " + (y + 4)
+ " order by x asc, y asc");
msql.next();
for(int a = 0; a < 9; a++)
for(int b = 0; b < 9; b++)
if(msql.getInt("x") != a || msql.getInt("y") != b){
map[b][a] = 0;
} else {
map[b][a] = msql.getInt("tile");
msql.next();
}
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "curseMap.MainClass" });
}
}
ExampleFrame.java
Code:package curseMap;
import java.awt.BorderLayout;
import java.awt.Frame;
import processing.core.*;
public class ExampleFrame extends Frame {
private static final long serialVersionUID = 1L;
public ExampleFrame() {
super("Embedded PApplet");
setLayout(new BorderLayout());
PApplet embed = new curseMap.MainClass();
add(embed, BorderLayout.CENTER);
// important to call this whenever embedding a PApplet.
// It ensures that the animation thread is started and
// that other internal variables are properly set.
embed.init();
}
}