⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moveball.java

📁 是一个用于显示球的哦,呵呵,代码简短,功能均已实现,不可多得啊,
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;

public class moveball extends Applet implements Runnable
{
 /*public static void main(String[] args){*/
 int x_pos = 10;        
 int y_pos = 100;      
 int radius = 20;     
 
 private Image dbImage; 
 private Graphics dbg; 


 public void init()
 {
  setBackground (Color.blue);
 }

 public void start ()
 {
  
  Thread th = new Thread (this);
  
  th.start ();
 }

 public void stop()
 {

 }

 public void destroy()
 {

 }

 public void run ()
 {
        
  Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

            while (true) {
  
         
   x_pos++ ;
     
          
   repaint();

   try
   {
           
    Thread.sleep (20);
   }
   catch (InterruptedException ex)
   {
   }

   
   Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
  }
 }


 public void update (Graphics g) 
 { 
   
 if (dbImage == null) 
 { 
 dbImage = createImage (this.getSize().width, this.getSize().height); 
 dbg = dbImage.getGraphics (); 

 } 

   
 dbg.setColor (getBackground ()); 
 dbg.fillRect (0, 0, this.getSize().width, this.getSize().height); 

    
 dbg.setColor (getForeground()); 
 paint (dbg); 

    
 g.drawImage (dbImage, 0, 0, this); 

 } 


 public void paint (Graphics g)
 {
   
  g.setColor  (Color.red);
  
  g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);
 }

}/*}*/

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -