📄 sport.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package ballanim;import java.awt.Canvas;import java.awt.Color;import java.awt.Graphics;import java.util.logging.Level;import java.util.logging.Logger;/** * * @author Administrator */public class Sport extends Canvas{ int ballX = 0; int ballDirection = 0; //int x = BallAnim.MAXIMIZED_HORIZ; //int y = BallAnim.MAXIMIZED_VERT; Sport(){ new Thread(new Runnable() { public void run() { while (true){ try { repaint(); moveBall(); Thread.sleep(10); } catch (InterruptedException ex) { Logger.getLogger(Sport.class.getName()).log(Level.SEVERE, null, ex); } } } }).start(); } public void moveBall(){ if(ballDirection==0){ ballX++; if(ballX>=270){ ballDirection=1; ballX=270; } } else{ ballX--; if(ballX<=0) { ballDirection=0; ballX=0; } } } @Override public void paint(Graphics g){ g.setXORMode(getBackground()); //g.fillRect(40, 10, 40, 40); g.setColor(Color.RED); g.fillOval(ballX, 10, 30, 30); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -