问题都在标题中:)。我不知道我的代码有什么问题以及为什么它不会将圆圈绘制到 Japplet 上。你能帮我吗?
这是我的代码:
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Event;
public class BouncingBall extends JApplet {
private static final long serialVersionUID = 1L;
boolean b = true;
long speed = 50;
int pos = 250;
public void init(){
setSize(500,500);
}
public boolean mouseDown(Event e, int x, int y)
{
if(y>250)
{
speed = speed - 10;
}
else
{
speed = speed + 10;
}
repaint();
return true;
}
public void paintComponents(Graphics g)
{
g.drawOval(250,pos,100,100);
if(speed <= 20)
{
speed++;
repaint();
}
try
{
Thread.sleep(speed);
}
catch(InterruptedException e){e.printStackTrace();}
if(pos>=400)
{
b = false;
}
if(pos<=100)
{
b = true;
}
if(b==true)
{
pos = pos +5;
}
else
{
pos = pos -5;
}
repaint();
}
}
乳液