import java.awt.*; public class interactinglettersnorefresh extends fallingletter { public static final Font FONT= new Font("Serif", Font.BOLD, 20); protected int xmax, ymax, x2ago, y2ago, lastx, lasty; protected float vx; public final int UP=1, DOWN=2, LEFT=4, RIGHT=8; public interactinglettersnorefresh(char newletter, int newx, int newy, int rightbound, int ground) { super(newletter, newx, newy); xmax=rightbound; ymax=ground; } public Point getPoint() { return (new Point(x, y)); } //no setBackground() method, I don't need it public void update() { x+=(int)vx; y+=v; v+=1; if (vx<=-1) vx+=.1; else if (vx>=1) vx-=.1; if (y>ymax) { y=ymax; bounce(UP); } else if (y<0) bounce(DOWN); if (x>xmax-10) bounce(LEFT); else if (x<0) bounce(RIGHT); } public void bounce(int direction) { if ((direction&UP)>0) v=-9*Math.abs(v)/10; else if ((direction&DOWN)>0) v=Math.abs(v); if ((direction&LEFT)>0) vx=-Math.abs(vx); else if ((direction&RIGHT)>0) vx=Math.abs(vx); } public void interact(interactinglettersnorefresh letter2) { int x2 = letter2.getPoint().x; int y2 = letter2.getPoint().y; int bounce1=0, bounce2=0; if (Math.abs(x-x2)<=10 && Math.abs(y-y2)<=20 &! Character.isWhitespace(letter) &! Character.isWhitespace(letter2.getLetter())) { if (xy2) { bounce1 |=DOWN; bounce2 |=UP; } else if (y2>y) { bounce1 |=UP; bounce2 |=DOWN; } bounce(bounce1); letter2.bounce(bounce2); } } public void update(int x, int y) { this.x=x+xoffset; this.y=y+yoffset; v=0; vx=0; } public void release(int x, int y) { vx = (x-x2ago)/2; v = (y-y2ago)/2; } public void setVX(int newvx) { vx=newvx; } public void draw(Graphics g) //no more undrawing, but I still track the last two locations for throwing purposes. { g.setColor(color); g.drawString(new String("") + letter, x, y); x2ago=lastx; y2ago=lasty; lastx=x; lasty=y; } public char getLetter() { return letter; } }