import javax.swing.*;
import java.awt.*;public class EllipseDemo1 extends JApplet implements Runnable{ int radiu=0;
int inc=10; public void paint(Graphics g){
super.paint(g);
int width =getWidth();
int height=getHeight();
System.out.println("hello");
setBackground(Color.blue);
g.setColor(Color.green);
int x =(int)(width/2-radiu/2);
int y =(int)(height/2-radiu/2);
g.fillOval(x,y,radiu,radiu);
}
public void run(){
while(true){
radiu+=inc;
try{
Thread.sleep(1000);
}catch(InterruptedException e)
{
System.out.println(e.getMessage());
}
//update(getGraphics());
repaint();
if (radiu==100)
break;
}
}
public void init(){
EllipseDemo1 demo=new EllipseDemo1();
Thread t =new Thread(demo);
t.start();
}
}我想实现画一个圆球让它的半径不断增大,可是不能刷新啊,用update(Graphics g)又不对,这是怎么回事?
import java.awt.*;public class EllipseDemo1 extends JApplet implements Runnable{ int radiu=0;
int inc=10; public void paint(Graphics g){
super.paint(g);
int width =getWidth();
int height=getHeight();
System.out.println("hello");
setBackground(Color.blue);
g.setColor(Color.green);
int x =(int)(width/2-radiu/2);
int y =(int)(height/2-radiu/2);
g.fillOval(x,y,radiu,radiu);
}
public void run(){
while(true){
radiu+=inc;
try{
Thread.sleep(1000);
}catch(InterruptedException e)
{
System.out.println(e.getMessage());
}
//update(getGraphics());
repaint();
if (radiu==100)
break;
}
}
public void init(){
EllipseDemo1 demo=new EllipseDemo1();
Thread t =new Thread(demo);
t.start();
}
}我想实现画一个圆球让它的半径不断增大,可是不能刷新啊,用update(Graphics g)又不对,这是怎么回事?
解决方案 »
- byte转string问题
- java.nio
- 请问如何在J#中使用非阻塞的ServerSocketChannel和ServerSocket,顶者有分
- 听说12月16日有个java技术研讨会,有那位同仁报名了~~
- linux下运行报段错误
- 想问各位兄台,是学j2me好呢,还是j2ee好
- 太奇怪了!!我的程序锁不住文件,也锁不住端口,百思不得其解……
- Interface HttpServletRequest,HttpServletRequest req, req.setCharacterEncoding("GB2312");???
- 请教高手---怎样在用JAVA语言连接加密的ACCESS数据库
- 猛将兄,救命!问一个JavaScript的问题!十万火急!
- 把图片都放在了同一个目录下运行后,没有显示图片,不知道那出了问题
- HttpURLConnection的郁闷问题,请问这个问题谁碰到过啊?
import java.awt.*;public class EllipseDemo1 extends JApplet implements Runnable {
int radiu=0;
int inc=10;
public void init(){
Thread t =new Thread(this);
t.start();
}
public void run(){
while(true){
radiu+=inc;
if (radiu==100)
break;
repaint();
try{
Thread.sleep(1000);
}catch(InterruptedException e)
{
System.out.println(e.getMessage());
}
//update(getGraphics());
}
}
public void paint(Graphics g){
super.paint(g);
int width =getWidth();
int height=getHeight();
setBackground(Color.blue);
g.setColor(Color.green);
int x =(int)(width/2-radiu/2);
int y =(int)(height/2-radiu/2);
g.fillOval(x,y,radiu,radiu);
}
}
试试
import java.awt.*;public class EllipseDemo1 extends JApplet{
int radiu=0;
int inc=10;
public void init(){
this.getContentPane().add(new Ell());
this.setVisible(true);
}
private class Ell extends JPanel implements Runnable{
public Ell()
{
setBackground(Color.blue);
Thread t =new Thread(this);
t.start();
}
public void run(){
while(true){
radiu+=inc;
if (radiu==100)
break;
repaint();
try{Thread.sleep(1000);}catch(InterruptedException e){System.out.println(e.getMessage());}
}
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.green);
int x =(int)(getHeight()/2-radiu/2);
int y =(int)(getWidth()/2-radiu/2);
g.fillOval(x,y,radiu,radiu);
}
}
}
moveall();repaint()