public static void main(String[] args) { Animate a = new Cat(); // 向上转型,自动类型提升,猫对象提升了动物类型。但是特有功能无法访问。 a.eat(); // 如果还想用具体动物猫的特有功能,则需向下转型。 Cat cat = (Cat) a; // 向下转型 cat.swarm(); // 注意:对于转型,自始至终都是子类对象在做着类型的变化。 }
// This is where things get started public static void main(String args[]) { // Create a new frame to hold the canvas and put it up. Frame fm = new Frame(); Animate b = new Animate(); // Make it visible and set size b.setVisible(true); b.setSize(300, 300); System.out.println("Here we go"); // Add the canvas to the frame and make it show fm.add("Center", b); fm.pack(); fm.show(); }
@Override protected void tick() throws LostGroundException, VariableException { super.tick(); if (getTime() == getAnimation().getDuration() - 1) { // 増える breed(); } }
public static void main(String[] args) { Animate.animate( "Zombicus humans", (Cell<Double> time, Stream<Unit> sTick, Dimension windowSize) -> { World world = new World(windowSize); List<Cell<Character>> chars = new ArrayList<>(); int id = 0; for (int x = 100; x < windowSize.width; x += 100) for (int y = 150; y < windowSize.height; y += 150) { Point pos0 = new Point(x, y); HomoSapiens h = new HomoSapiens(world, id, pos0, time, sTick); chars.add(h.character); id++; } return sequence(chars); }); }