This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Date currentTime = new Date(); | |
| long lastRenderedTime = 0; | |
| @Override | |
| public boolean animate() { | |
| if ( System.currentTimeMillis()/1000 != lastRenderedTime/1000){ | |
| currentTime.setTime(System.currentTimeMillis()); | |
| return true; | |
| } | |
| return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void start(){ | |
| this.getComponentForm().registerAnimated(this); | |
| } | |
| public void stop(){ | |
| this.getComponentForm().deregisterAnimated(this); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AnalogClock clock = new AnalogClock(); | |
| parent.addComponent(clock); | |
| clock.start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Find out the current translation | |
| int currX = g.getTranslateX(); | |
| int currY = g.getTranslateY(); | |
| // Reset the translation to zeroes | |
| g.translate(-currX, -currY); | |
| // Now we are working in absolute screen coordinates | |
| g.drawRect(10, 10, 100, 100); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RectangleComponent extends Component { | |
| public void paint(Graphics g){ | |
| g.setColor(0x0000ff); | |
| g.drawRect(getX()+5, getY()+5, getWidth()-10, getHeight()-10); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RectangleComponent extends Component { | |
| @Override | |
| protected Dimension calcPreferredSize() { | |
| return new Dimension(250,250); | |
| } | |
| public void paint(Graphics g) { | |
| g.setColor(0x0000ff); | |
| g.rotate((float) (Math.PI / 4.0)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyForm extends Form { | |
| public MyForm() { | |
| super("Rectangle Rotations"); | |
| for ( int i=0; i< 10; i++ ){ | |
| this.addComponent(new RectangleComponent()); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void paint(Graphics g) { | |
| g.setColor(0x0000ff); | |
| g.rotate((float)(Math.PI/4.0), getAbsoluteX(), getAbsoluteY()); | |
| g.drawRect(getX() + 5, getY() + 5, getWidth() - 10, getHeight() - 10); | |
| g.rotate(-(float) (Math.PI / 4.0), getAbsoluteX(), getAbsoluteY()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void paint(Graphics g) { | |
| g.setColor(0x0000ff); | |
| g.rotate( | |
| (float)(Math.PI/4.0), | |
| getAbsoluteX()+getWidth()/2, | |
| getAbsoluteY()+getHeight()/2 | |
| ); | |
| g.drawRect(getX() + 5, getY() + 5, getWidth() - 10, getHeight() - 10); | |
| g.rotate( | |
| -(float)(Math.PI/4.0), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void pointerPressed(int x, int y) { | |
| addPoint(x-getParent().getAbsoluteX(), y-getParent().getAbsoluteY()); | |
| } |