|
Author |
Topic: importing java classes? (Read 508 times) |
|
kevinP
|
importing java classes?
« on: Jan 31st, 2004, 6:44pm » |
|
I did try searching on this... I'd like a date or time function that gives me something like epoch time so that I can do a date calculation. (Actually I thought this was available in Processing). So how do I import a java class? I got as far as trying: Code: import java.util.Calendar; public class Test extends BApplet { Calendar cal; void setup() { size(200, 200); background(0); stroke(153, 153, 0); cal = new Calendar; BFont fontA = loadFont("Meta-Bold.vlw.gz"); textFont(fontA, 44); // etc. } } |
| ...but I'm still getting errors, for example, "expecting EOF, found 'textFont'". -K
|
« Last Edit: Jan 31st, 2004, 6:46pm by kevinP » |
|
Kevin Pfeiffer
|
|
|
Koenie
|
Re: importing java classes?
« Reply #1 on: Jan 31st, 2004, 7:28pm » |
|
In this case I think the problem is you got 'cal = new Calendar;' This should be 'cal = new Calendar();' since it's a constructor method. Koenie
|
http://koeniedesign.com
|
|
|
kevinP
|
Re: importing java classes?
« Reply #2 on: Jan 31st, 2004, 9:24pm » |
|
on Jan 31st, 2004, 7:28pm, Koenie wrote:In this case I think the problem is you got 'cal = new Calendar;' This should be 'cal = new Calendar();' since it's a constructor method. |
| I think I was also misusing the class. java.util.Date worked fine. I will spend a few more minutes studying the java docs for both of them. -K
|
Kevin Pfeiffer
|
|
|
kevinP
|
Re: importing java classes?
« Reply #3 on: Feb 1st, 2004, 6:51pm » |
|
Hi all, Here's what I came up with (countdown for spring graduation)... http://www.tiros.net/pfeiffer/processing/2004/countdown/ Nothing fancy, but a chance to learn more about the programming. I need to ask a question in case someone has time to look at the code. To import an additional class I ended up doing this: Code: import java.util.Date; public class Countdown extends BApplet { // variables initialized, etc. void setup() { // days = countdown(y, m, d); // } void loop() { // some messy, slightly redundant code } int countdown(int _y, int _m, int _d) { int msDay = 86400000; // millseconds in a day Date date1 = new Date(); Date date2 = new Date(_y, _m, _d); return Math.round((date2.getTime() - date1.getTime()) / msDay); } } |
| I wonder if there is a better way to organize this? It was a bit confusing. I think that the strength (and weakness) of Processing for me is that it lets you write procedural programs in an OO-environment. Does it make any difference what I call this extension of BApplet?
|
« Last Edit: Mar 20th, 2004, 1:37am by kevinP » |
|
Kevin Pfeiffer
|
|
|
|