Name:
Anonymous
2009-03-20 16:43
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class ThrowAway extends Applet implements Runnable,MouseMotionListener{
int x,y,dx,dy,p,w,h;
public void init(){
w=getWidth();
h=getHeight();
new Thread(this).start();
addMouseMotionListener(this);
}
public void render(Graphics g){
x+=dx;
y+=dy;
if(x<10||x>w-10){
if(y>p&&y<p+30)
dx=-dx;
if(x<=0||x>w){
dx=dy=1;
x=y=w/2;
}
}
if(y<0||y>h) dy=-dy;
g.setColor(Color.black);
g.fillRect(0, 0, w, h);
g.setColor(Color.white);
g.fillRect(0, p, 10, 30);
g.fillRect(w-10, p, 120, 30);
g.fillRect(x-1, y-1, 3, 3);
}
public void run() {
Image buf=createImage(w,h);
Graphics g=buf.getGraphics();
while(true){
render(g);
getGraphics().drawImage(buf,0,0,this);
try{Thread.sleep(5);}catch(Exception ex){};
}
}
public void mouseMoved(MouseEvent e) {
p=e.getY()-15;
}
public void mouseDragged(MouseEvent e){}
}
Name:
Anonymous
2009-03-20 23:15
>>3
(can't do this in python)
Yes you can. You don't need whitespace in Python if you use semicolons.