📄 fallingtomato.java~
字号:
import java.awt.Color;import objectdraw.DrawingCanvas;import objectdraw.FilledOval;// FallingSleet classpublic class FallingTomato extends FallingObject { // size of a sleet pellet private static final int SIZE = 40; private static final int SPLATTER_DELAY = 1000; private DrawingCanvas canvas; // initialize the instance variables and start the active object public FallingTomato(DrawingCanvas theCanvas, double x, double aSpeed, int aScreenHeight) { // first, call "up" to the constructor of the FallingObject class super(aScreenHeight - SIZE / 2, aSpeed); canvas = theCanvas; object = new FilledOval(x, -SIZE, SIZE, SIZE, canvas); object.setColor(Color.RED); start(); } // we override the hitBottom method from FallingObject // since we want extra functionality protected void hitBottom() { // first, remember our x position double x = object.getX(); object.removeFromCanvas(); // but then a little extra FilledOval splat = new FilledOval(x - SIZE / 2, fallToPos, SIZE * 2, SIZE / 2, canvas); splat.setColor(Color.red); pause(SPLATTER_DELAY); splat.removeFromCanvas(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -