i would like to reproduce a funny program that has a button that avoids the mouse cursor. The code in java looks like this:
// <code> Mobile quit button
// Peter van der Linden, March 9 1996
// Just Java.
// run from an html file like this:
// applet code=q.class height=125 width=200 /applet
// dont forget to put the chevrons round the HTML tags!
import java.awt.*;
import java.applet.Applet;
public class q extends Applet {
String s= new String(""
;
Button b= new Button("quit"
;
int bx, by; // button's present location.
int sx, sy; // button's size;
int wx, wy; // window limits.
final int hi = 10; // horiz increment for button moves
final int vi = 10; // vertical increment
final int a = 30; // buffer zone width
public void init() {
add(b);
repaint();
}
public void paint(Graphics g) {
g.drawString(s, 10, 50);
}
public boolean mouseMove(Event e, int x, int y) {
sy=b.size().height; sx=b.size().width;
bx=b.location().x; by=b.location().y;
wx=size().width; wy=size().height;
if (x>bx+sx+a || x<bx-a || y>by+sy+a || y<by-a) return true;
// cursor too close to button, so move it away.
bx += x>=bx? -hi:hi;
by += (y>=by? -vi:vi);
if (bx+sx > wx-hi) bx = wx-3*sx; else if (bx <0 ) bx = 2*sx;
if (by+sy > wy-vi) by = wy-2*sy; else if (by <0 ) by = 2*sy;
b.move(bx, by);
repaint();
return true;
}
public boolean action(Event e, Object o) {
if (e.target instanceof Button) {
s="You win!";
repaint();
return true;
}
return false;
}
}
// </code>
It doesn't have to work just like this, it is just an idea. I promise it isn't for class, we're too busy studying for finals. I just think it would be cool and I can't see how I can get it to work since I just recently got to binding. We skipped around in the Welch text so I can't see how to move a button unless we tear it off like I think you can do with a listbox menu. Anyway, I'd appreciate the input. Another possibility is a button that acts like a scrollbar as it shys away from the mouse. Better yet it could reappear on another part of the window on another side. I guess the change in row is possible. Text on the button may be a problem. This may not be so silly since a scrollbar that reacted this way might be attractive; well except for appearing on another row.
Thanks for letting me get away with this post,
BJ Corne
// <code> Mobile quit button
// Peter van der Linden, March 9 1996
// Just Java.
// run from an html file like this:
// applet code=q.class height=125 width=200 /applet
// dont forget to put the chevrons round the HTML tags!
import java.awt.*;
import java.applet.Applet;
public class q extends Applet {
String s= new String(""
Button b= new Button("quit"
int bx, by; // button's present location.
int sx, sy; // button's size;
int wx, wy; // window limits.
final int hi = 10; // horiz increment for button moves
final int vi = 10; // vertical increment
final int a = 30; // buffer zone width
public void init() {
add(b);
repaint();
}
public void paint(Graphics g) {
g.drawString(s, 10, 50);
}
public boolean mouseMove(Event e, int x, int y) {
sy=b.size().height; sx=b.size().width;
bx=b.location().x; by=b.location().y;
wx=size().width; wy=size().height;
if (x>bx+sx+a || x<bx-a || y>by+sy+a || y<by-a) return true;
// cursor too close to button, so move it away.
bx += x>=bx? -hi:hi;
by += (y>=by? -vi:vi);
if (bx+sx > wx-hi) bx = wx-3*sx; else if (bx <0 ) bx = 2*sx;
if (by+sy > wy-vi) by = wy-2*sy; else if (by <0 ) by = 2*sy;
b.move(bx, by);
repaint();
return true;
}
public boolean action(Event e, Object o) {
if (e.target instanceof Button) {
s="You win!";
repaint();
return true;
}
return false;
}
}
// </code>
It doesn't have to work just like this, it is just an idea. I promise it isn't for class, we're too busy studying for finals. I just think it would be cool and I can't see how I can get it to work since I just recently got to binding. We skipped around in the Welch text so I can't see how to move a button unless we tear it off like I think you can do with a listbox menu. Anyway, I'd appreciate the input. Another possibility is a button that acts like a scrollbar as it shys away from the mouse. Better yet it could reappear on another part of the window on another side. I guess the change in row is possible. Text on the button may be a problem. This may not be so silly since a scrollbar that reacted this way might be attractive; well except for appearing on another row.
Thanks for letting me get away with this post,
BJ Corne