?? ball.java
字號:
// Ball.java
import java.awt.*;
// Class representing the MODEL of a ball
public class Ball
{
/////////////////////////// VARIABLES //////////////
// Ball is circle, with centre (x,y) and radius "radius"
int x;
int y;
int radius;
// each time ball moves it moves (dx, dy)
int dx;
int dy;
// colour of ball is "color" (note we use US spelling)
Color color;
///////////////////////// METHODS //////////////
// initialise new ball object
public Ball (int newX, int newY, int newRadius, int newXMotion, int newYMotion)
{
x = newX;
y = newY;
radius = newRadius;
color = Color.blue; // default colour is blue
dx = newXMotion;
dy = newYMotion;
}
// display the ball (using location and color variables)
public void paint (Graphics g)
{
g.setColor(color);
g.fillOval(x,y,radius, radius);
}
// set the location of the centre of the ball
public void setXY(int newX, int newY)
{
x = newX;
y = newY;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public int getXMotion()
{
return dx;
}
public int getYMotion()
{
return dy;
}
public void setColor( Color newColor )
{
color = newColor;
}
public void setMotion( int newXMotion, int newYMotion )
{
dx = newXMotion;
dy = newYMotion;
}
public void move()
{
x = x + dx;
y = y + dy;
}
} // end of class definition
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -