ilikebagels
Junior Member
Offline
Posts: 56
Re: searching arraylist
Reply #33 - May 10th , 2009, 4:50pm
mysqllayer class import de.bezier.data.sql.*; import java.sql.Timestamp; static final String TABLE_NAME = "inbound"; public class MySQLLayer { private MySQL m_mySQL; public MySQLLayer(PApplet pa) { m_mySQL = new MySQL(pa, "134.36.216.17", "daver", "daver", "superhero"); if (!m_mySQL.connect()) { System.err.println("Cannot connect to database!"); exit(); } } public void Disconnect() { m_mySQL.close(); } public int GetCount() { m_mySQL.query("SELECT COUNT(*) FROM " + TABLE_NAME); m_mySQL.next(); return m_mySQL.getInt(1); } public ArrayList GetNewMessages(Timestamp previousDate) { String query = "SELECT creator, message, date_added FROM " + TABLE_NAME + " WHERE date_added > '" + FormatTimestamp(previousDate) + "'" + " ORDER BY date_added ASC"; //~ System.out.println(query); m_mySQL.query(query); ArrayList newMessageList = new ArrayList(); while (m_mySQL.next()) { String a = m_mySQL.getString(1); String m = m_mySQL.getString(2); Timestamp d = m_mySQL.getTimestamp(3); Message msg = new Message(a, m, d); newMessageList.add(msg); } println("Read " + newMessageList.size() + " messages"); return newMessageList; } public Message GetMessage(int idx) { m_mySQL.query("SELECT creator, message, date_added FROM " + TABLE_NAME + " WHERE id=" + idx ); m_mySQL.next(); String a = m_mySQL.getString(1); String m = m_mySQL.getString(2); Timestamp d = m_mySQL.getTimestamp(3); return new Message(a, m, d); } public Message GetRandomMessage() { m_mySQL.query("SELECT creator, message, date_added FROM " + TABLE_NAME + " ORDER BY RAND() LIMIT 0, 1" ); m_mySQL.next(); String a = m_mySQL.getString(1); String m = m_mySQL.getString(2); Timestamp d = m_mySQL.getTimestamp(3); println("Read a random message"); return new Message(a, m, d); } public String FormatHour(Timestamp ts) { DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); return formatter.format(ts); } public String FormatTimestamp(Timestamp ts) { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return formatter.format(ts); } } shrinker class class Shrinker implements Drawer { String message; color col; Shrinker(String m, color c) { message = m; col = c; } void Draw(int frame) { float a = frame / (float) (GetDuration() * frameRate); pushStyle(); fill(col); textSize(lerp(BASE_DISPLAY_FONT_SIZE, 0, a)); float posX = lerp(width - textWidth(message), 0, a); float posY = lerp(height - BASE_DISPLAY_FONT_SIZE, 0, a); text(message, posX, posY); popStyle(); } float GetDuration() { return BASE_MESSAGE_DISPLAY_TIME * 2; } } class Grower implements Drawer { String message; color col; Grower(String m, color c) { message = m; col = c; } void Draw(int frame) { float a = frame / (float) (GetDuration() * frameRate); pushStyle(); fill(col); textSize(lerp(0, BASE_DISPLAY_FONT_SIZE, frame / (float) BASE_MESSAGE_DISPLAY_TIME * 2)); float posX = lerp(width - textWidth(message), 0, a); float posY = lerp(height - BASE_DISPLAY_FONT_SIZE, 0, a); text(message, posX, posY); popStyle(); } float GetDuration() { return BASE_MESSAGE_DISPLAY_TIME * 2; } //class Hello implements Drawer //{ // String message; // String col ; // PShape bot; // Hello(String m, color c) // { // bot = loadShape("arrow1.svg"); // message = m; // col = c; // } // void Draw() // { // float a = frame / (float) (GetDuration() * frameRate); // float x = random(100,500); // float y = random(100,900); // fill(col); // text(message, x,y); // shape(bot,x,y); // } // float GetDuration() // { // return BASE_MESSAGE_DISPLAY_TIME * 2; // } //} } also having a slight issue creating a new class i called it hello and tried to have a matcher but it came up with the error that the class didn't exist