home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-03-14 | 1.6 KB | 75 lines |
- import java.applet.*;
- import java.awt.*;
- import java.net.*;
-
- public class ImageApplet3 extends Applet
- {
- final int HALFSIZE = 0;
- final int FULLSIZE = 1;
- final int DOUBLESIZE = 2;
-
- Image snake;
- int size;
-
- public void init()
- {
- Button button = new Button("50%");
- add(button);
- button = new Button("100%");
- add(button);
- button = new Button("200%");
- add(button);
-
- URL codeBase = getCodeBase();
- snake = getImage(codeBase, "snake.gif");
-
- size = FULLSIZE;
- }
-
- public void paint(Graphics g)
- {
- int width = snake.getWidth(this);
- int height = snake.getHeight(this);
-
- if (size == HALFSIZE)
- {
- int x = 75 - width / 4;
- g.drawImage(snake, x, 50, width/2, height/2, this);
- resize(150, height/2+50);
- }
- else if (size == FULLSIZE)
- {
- int x = 75 - width / 2;
- g.drawImage(snake, x, 50, this);
- resize(150, height+50);
- }
- else if (size == DOUBLESIZE)
- {
- int x = ((width*2+50)/2)-width;
- g.drawImage (snake, x, 50, width*2, height*2, this);
- resize(width*2+50, height*2+50);
- }
- }
-
- public boolean action(Event evt, Object arg)
- {
- if (arg == "50%")
- size = HALFSIZE;
- else if (arg == "100%")
- size = FULLSIZE;
- else if (arg == "200%")
- size = DOUBLESIZE;
-
- repaint();
-
- return true;
- }
-
- }
-
-
-
-
-
-
-