Display log with images
in
Programming Questions
•
1 year ago
Hi all,
I'm working on a project with bluetooth communication with a 'robot' (conducted by an arduino microcontroller).
I would like the application (with processing) to keep a log of the activities of the robot.
This log would show images of the activities.
Now, I've made another program to implement the 'tactic' that I'd use.
This is a program with 4 buttons, and when these buttons are clicked, the program should show a log (in a rectangle) with the buttons that have been pressed.
I've thought of some possibilities to do this. I think this is the right one. But I've been having a 'nullPointerException' Error.
I, first of all, don't know what this error means and why this program won't work.
Here you have the code:
(The images that I use, can be downloaded at: https://docs.google.com/open?id=0B1oVMH7b0UhfM3paXzFKbXBKN2s )
I've highlighted the part, where I think it goes wrong.
I'm working on a project with bluetooth communication with a 'robot' (conducted by an arduino microcontroller).
I would like the application (with processing) to keep a log of the activities of the robot.
This log would show images of the activities.
Now, I've made another program to implement the 'tactic' that I'd use.
This is a program with 4 buttons, and when these buttons are clicked, the program should show a log (in a rectangle) with the buttons that have been pressed.
I've thought of some possibilities to do this. I think this is the right one. But I've been having a 'nullPointerException' Error.
I, first of all, don't know what this error means and why this program won't work.
Here you have the code:
(The images that I use, can be downloaded at: https://docs.google.com/open?id=0B1oVMH7b0UhfM3paXzFKbXBKN2s )
I've highlighted the part, where I think it goes wrong.
- color currentcolor;
RectButton rect1, rect2, rect3, rect4, rect5, rect6;
color achtergrond = color(102);
PImage rood;
PImage blauw;
PImage groen;
PImage geel;
PImage niets;
int xlogboek = 255;
int ylogboek = 25;
boolean locked = false;
PImage[] logboek = new PImage[23];
int teller;
void setup()
{
for(int x = 0 ; x < 23 ; x = x + 1) {
logboek[x] = niets;
}
teller = 1;
size(400, 200);
smooth();
rood = loadImage("rood.jpg");
blauw = loadImage("blauw.jpg");
groen = loadImage("groen.jpg");
geel = loadImage("geel.jpg");
niets = loadImage("niets.jpg");
color baseColor = color(102);
currentcolor = baseColor;
color buttoncolor = color(255,0,0);
color highlight = color(178,34,34);
rect1 = new RectButton(80, 20, 40, buttoncolor, highlight);
buttoncolor = color(0,255,0);
highlight = color(34,178,34);
rect2 = new RectButton(80, 70, 40, buttoncolor, highlight);
buttoncolor = color(0,0,255);
highlight = color(34,34,178);
rect3 = new RectButton(30, 70, 40, buttoncolor, highlight);
buttoncolor = color(255,255,0);
highlight = color(178,178,34);
rect4 = new RectButton(130, 70, 40, buttoncolor, highlight);
buttoncolor = color(255,255,255);
highlight = color(221,221,221);
rect5 = new RectButton(55, 140, 40, buttoncolor, highlight);
buttoncolor = color(0,0,0);
highlight = color(34,34,34);
rect6 = new RectButton(105, 140, 40, buttoncolor, highlight);
}
void draw()
{
background(currentcolor);
stroke(255);
rect(250,20,100,160);
update(mouseX, mouseY);
rect1.display();
rect2.display();
rect3.display();
rect4.display();
rect5.display();
rect6.display();
}
void update(int x, int y)
{
if(locked == false) {
rect1.update();
rect2.update();
rect3.update();
rect4.update();
rect5.update();
rect6.update();
}
else {
locked = false;
}
if (rect1.pressed() || rect2.pressed() || rect3.pressed() || rect4.pressed()) {
currentcolor = achtergrond;
if(rect1.pressed() && mousePressed) {
currentcolor = rect1.basecolor;
rood();
}
else if(rect2.pressed() && mousePressed) {
currentcolor = rect2.basecolor;
groen();
}
else if(rect3.pressed() && mousePressed) {
currentcolor = rect3.basecolor;
blauw();
}
else if(rect4.pressed() && mousePressed) {
currentcolor = rect4.basecolor;
geel();
}
}
else if(rect5.pressed() || rect6.pressed()) {
if(rect5.pressed() && mousePressed){
currentcolor = rect5.basecolor;
}
else if(rect6.pressed() && mousePressed){
currentcolor = rect6.basecolor;
}
}
else if(( keyCode == UP || keyCode == DOWN || keyCode == RIGHT || keyCode == LEFT )) {
currentcolor = achtergrond;
if(keyCode == UP){
if(keyPressed == true) {
currentcolor = color(255,0,0);
rect1.basecolor = color(178,34,34);
rood();
}
}
else if(keyCode == DOWN){
if(keyPressed == true) {
currentcolor = color(0,255,0);
rect2.basecolor = color(34,178,34);
groen();
}
}
else if(keyCode == LEFT){
if(keyPressed == true) {
currentcolor = color(0,0,255);
rect3.basecolor = color(34,34,178);
blauw();
}
}
else if(keyCode == RIGHT){
if(keyPressed == true) {
currentcolor = color(255,255,0);
rect4.basecolor = color(178,178,34);
geel();
}
}
}
if(keyPressed == false) {
keyCode = 0;
rect1.basecolor = color(255,0,0);
rect2.basecolor = color(0,255,0);
rect3.basecolor = color(0,0,255);
rect4.basecolor = color(255,255,0);
}
for(int i = 0 ; i < 23 ; i = i + 1) {
image(logboek[i] , xlogboek , ylogboek);
if (logboek[i] != niets) {
if(xlogboek == 330) {
ylogboek = ylogboek + 25;
xlogboek = 230;
}
xlogboek = xlogboek + 25;
}
}
}
void rood() {
logboek[teller] = rood;
teller = teller + 1;
if(teller == 23){
teller = 0;
}
}
void groen() {
logboek[teller] = groen;
teller = teller + 1;
if(teller == 23){
teller = 0;
}
}
void blauw() {
logboek[teller] = blauw;
teller = teller + 1;
if(teller == 23){
teller = 0;
}
}
void geel() {
logboek[teller] = geel;
teller = teller + 1;
if(teller == 23){
teller = 0;
}
}
class Button
{
int x, y;
int size;
color basecolor, highlightcolor;
color currentcolor;
boolean over = false;
boolean pressed = false;
void update()
{
if(over()) {
currentcolor = highlightcolor;
}
else {
currentcolor = basecolor;
}
}
boolean pressed()
{
if(over) {
locked = false;
return true;
}
else {
locked = false;
return false;
}
}
boolean over()
{
return true;
}
boolean overRect(int x, int y, int width, int height)
{
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
}
else {
return false;
}
}
}
class RectButton extends Button
{
RectButton(int ix, int iy, int isize, color icolor, color ihighlight)
{
x = ix;
y = iy;
size = isize;
basecolor = icolor;
highlightcolor = ihighlight;
currentcolor = basecolor;
}
boolean over()
{
if( overRect(x, y, size, size) ) {
over = true;
return true;
}
else {
over = false;
return false;
}
}
void display()
{
stroke(255);
fill(currentcolor);
rect(x, y, size, size);
}
}
1