Now our suburban scene was quaint, but it was rather static. Let's add a second
interface to add some motion. The moveable interface has a method move, and we
give the number of seconds for the simulated motion. Now, cars are moveable,
our car class implements two interfaces, drawable, and movable. Lets see how
that start. The car class now needs to implement the methods of both the
drawable and the movable interface. Here is the draw method that we've always
had, here is the move method we'll arbitrarily say that these cars moves at 10
pixel per second. And each of the components of the car is moved by that
amount. What's it look like? When you run the program, you can see this car
here moving. Later, we'll move the other cars as well, but for now please go
ahead and move Fido as well.
Ahora bien, nuestra escena suburbana era pintoresca, pero más bien estática. Vamos a añadir una segunda
interfaz para añadir un poco de movimiento. La interfaz Movibles tiene un método move (mover) y nosotros le
damos el número de segundos para el movimiento simulado. Ahora, los coches son móviles,
nuestra clase Coche implementa dos interfaces, Dibujable y Movibles. Vamos a ver
cómo se hace. La clase Coche ahora tiene que implementar los métodos tanto de la
interfaz Dibujable como de la interfaz Movible. Aquí está el método draw que siempre
hemos tenido, aquí está el método move, vamos a decir arbitrariamente que este coche se mueve a 10
píxeles por segundo. Y cada uno de los componentes del coche se mueven por ese
tiempo. ¿Qué aspecto tiene? Al ejecutar el programa, se puede ver este coche
aquí en movimiento. Más tarde vamos a mover los otros coches también, pero ahora por favor
vamos adelante y movamos a Fido también.
Notre scène de banlieue était pittoresque
mais plutôt statique.
Ajoutons une seconde interface
pour avoir du mouvement.
L'interface mobile a une méthode Move,
et nous donnons le nombre de secondes
pour le mouvement simulé.
Les voitures sont mobiles,
notre classe Car implémente
deux interfaces, Drawable et Moveable.
Voyons comment cela est fait.
La classe Car doit implémenter
les méthodes de l'interface
Drawable et Moveable.
Voici la méthode Draw
que nous avons toujours eu,
voici la méthode Move que
nous dirons arbitrairement
que ces voitures se déplacent
à 10 pixels par seconde.
Et chacune des pièces de la voiture
est déplacée par ce nombre.
A quoi cela ressemble-t-il?
Lorsque vous exécutez le programme,
vous pouvez voir cette voiture bouger.
Plus tard, nous déplacerons
également les autres voitures,
mais pour l'instant, allez déplacer Fido.
郊外の風景に動きを加えるために
2つ目のインターフェースを追加しましょう
Movableインターフェースは
moveメソッドを持っています
そしてシミュレーションの秒数を設定します
車は動くものなので
CarクラスはDrawableとMovableの
2つのインターフェースを実装します
では見てみましょう CarクラスはDrawableと
Movableのインターフェースの両方のメソッドを
実装する必要があります これまでも使ってきた
drawメソッドがここにあります
そしてmoveメソッドです
ここでは毎秒10ピクセルで車を動かします
すると車の各コンポーネントが
その設定値で動きます
プログラムを実行して
どのように動くか見てみましょう
このように車が動きます
あとで他の車も動かします
では犬を動かしてみてください
Suburban Scene이 조금 예스럽지만 너무 정적입니다. 움직이게 만들도록
두 번째 인터페이스를 넣읍시다. Moveable 인터페이스는 move라는
메소드가 있고, 몇 초를 움직일건지 매개변수로 받습니다. 자동차는
움직일 수 있습니다. Car 클래스는 두 개의 인터페이스를 선언합니다. 어떻게
시작하는지 봅시다. Car 클래스는 Drawable과 Movable 인터페이스의 메소드들을
모두 구현해 놔야 합니다. 여기에 draw 메소드가 있고
여기에 move 메소드를 넣습니다. 이 메소드에 의해 자동차는 1초당 10 픽셀
움직입니다. 자동차는 매개변수에 얼마나 할당 됐는지에 따라
움직입니다. 어떻게 생겼을까요? 프로그램을 실행하면, 여기서 차가
움직이는 게 보입니다. 시간이 지난 후에, 다른 자동차들도 옮기지만,
지금으로서는 Fido만 움직여 주세요.
Cảnh vật của ta đã khá đẹp, nhưng nó vẫn hơi tĩnh mịch. Hãy thêm một interface nữa
để có thêm vài sự chuyển động. Movable interface có một method để move,
và ta cho nó số giây để di chuyển. Cars bây giờ đã có thể di chuyển (moveable),
Car class của ta đang implements 2 interfaces, drawable, và movable.
Hãy xem bắt đầu như nào. Car class cần phải implement các methods
của cả drawable và movable interface. Đây là draw method mà ta đã có,
đây là move method để làm cho chiếc xe move 10 pixel mỗi giây.
Và mỗi thành phần của cái xe cũng được di chuyển
một lượng như này. Nó sẽ trông như nào? Khi bạn chạy chương trình, bạn có thể thấy là
cái xe này đang di chuyển. Sau này, ta cũng sẽ di chuyển những cái xe khác nhữa, nhưng bây giờ,
hãy làm cho Fido di chyển đi.