home *** CD-ROM | disk | FTP | other *** search
Java Source | 2001-05-30 | 3.0 KB | 123 lines |
- package nl.pcactive.gfx;
-
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.*;
- import java.net.URL;
-
- /**
- * Title: GFX
- * Description:
- * Copyright: Copyright (c) 2001
- * Company: Pc-Active
- * @author Benny Lootens
- * @version 1.0
- */
-
- public class Monkey extends Applet {
- private boolean isStandalone = false;
- private URL bgURL = null;
- private Image bgIMG = null;
- private Image[] sprite = new Image[4];
- private MediaTracker mt = new MediaTracker(this);
-
- /**Get a parameter value*/
- public String getParameter(String key, String def) {
- return isStandalone ? System.getProperty(key, def) :
- (getParameter(key) != null ? getParameter(key) : def);
- }
-
- /**Initialize the applet*/
- public void init() {
- try {
- jbInit();
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- /**Component initialization*/
- private void jbInit() throws Exception {
- bgURL = new URL(getCodeBase()+"\\shots\\bg.gif");
- bgIMG = getImage(bgURL);
-
- for (int i=0; i<4; i++) {
- URL url = new URL(getCodeBase()+ "\\shots\\"+(i+1)+".gif");
- sprite[i] = getImage(url);
-
- System.out.println(getCodeBase());
- mt.addImage(sprite[i],i);
- }
- mt.addImage(bgIMG,4);
- this.setBackground(Color.blue);
- }
- /**Start the applet*/
- public void start() {
- }
- /**Stop the applet*/
- public void stop() {
- }
- /**Destroy the applet*/
- public void destroy() {
- }
- /**Get Applet information*/
- public String getAppletInfo() {
- return "Aap";
- }
- /**Get parameter info*/
- public String[][] getParameterInfo() {
- return null;
- }
-
- public void paint(Graphics g) {
- try {
- for (int i=0; i<5; i++)
- mt.waitForID(i);
- }
- catch (InterruptedException e) {
- return;
- }
-
- g.drawImage(bgIMG,0,0,getBounds().width,getBounds().height,Color.white,this);
-
- for (int x=0; x<400; x++) {
- double angle=((double)x) / 20;
- int y = (int) (Math.abs(Math.sin(angle))*80);
- g.drawImage(sprite[0],x,80-y,this);
- delay(25);
- }
- this.setBackground(Color.yellow);
- System.exit(0);
- }
-
- private void delay(int millis) {
- try { Thread.sleep(millis); } catch(Exception ignored) {}
- }
-
- /**Main method*/
- public static void main(String[] args) {
- Monkey applet = new Monkey();
- applet.isStandalone = true;
- Frame frame;
- frame = new Frame() {
- protected void processWindowEvent(WindowEvent e) {
- super.processWindowEvent(e);
- if (e.getID() == WindowEvent.WINDOW_CLOSING) {
- System.exit(0);
- }
- }
- public synchronized void setTitle(String title) {
- super.setTitle(title);
- enableEvents(AWTEvent.WINDOW_EVENT_MASK);
- }
- };
- frame.setTitle("Aap");
- frame.add(applet, BorderLayout.CENTER);
- applet.init();
- applet.start();
- frame.setBounds(0,0,177,160);
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- //frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
- frame.setVisible(true);
- }
- }