1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/*
* COPYRIGHT
*/
// Example of defining macros. Used in mouse event methods
#define MOUSE_CLICK iNum= _CLICK; repaint(); launch();
#define MOUSE_EXIT iNum= _EXIT; repaint();
#define MOUSE_OVER iNum= _OVER; repaint();
package tildeslash;
import java.applet.*;
import java.awt.*;
#ifdef JAVA1_1
import java.awt.event.*;
#endif
/**
* This is just some demo code to demonstrate the usage of the
* C-preprocessor facilities in <I>mmake</I>. This particular code
* demonstrate how You can use the Makefile generated by mmake to
* manage java 1.0 and java 1.1 code in the same file.
*
* <P><H2>DESCRIPTON:</H2><P>
* This class displays an Image. When clicked on, the Image changes
* and a new class is launched. This class is intended for launching
* different demo Applets in a "fancy" way.
*
* <P>The class to launch is given as a parameter (class)
*
* <P>The Images to load are loaded from IMAGE_DIR and must have
* name image0.gif, image1.gif and image2.gif
*
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com>
* @version $Id: StartApp.xjava,v 1.5 2001/02/18 17:06:16 hauk Exp $
*/
public class StartApp extends Applet
{
private static final String IMAGE_DIR= "images/";
private static final int _EXIT= 0,
_OVER= 1,
_CLICK= 2;
private int iNum= 0;
private Image[] myImages;
private MediaTracker myTracker;
private String myClass;
// -------------------------- Public methods ------------------------- //
/**
* Init StartApp, load background Images. Get class to launch
* from parameter <I>name=class</I>. If this class is compiled as
* java 1.1 code, add a Mouse Listener.
*/
public void init()
{
this.setBackground(Color.black);
// Get class to load
myClass= getParameter("class");
myImages= new Image[3];
myTracker= new MediaTracker(this);
// Load Images
try {
for (int i=0; i<3; i++) {
myImages[i]= this.getImage(this.getCodeBase(),
IMAGE_DIR+"image"+i+".gif");
myTracker.addImage(myImages[i], 0);
}
myTracker.waitForAll();
} catch(Exception e) {
System.out.println("Error: "+ e.getMessage());
e.printStackTrace();
this.stop();
}
#ifdef JAVA1_1
// Listener for Mouse Events
this.addMouseListener(new MouseAdapter () {
public void mouseClicked(MouseEvent e)
{
MOUSE_CLICK // Substituted when running CPP, see #define above
}
public void mouseEntered(MouseEvent e)
{
MOUSE_OVER // Substituted when running CPP
}
public void mouseExited(MouseEvent e)
{
MOUSE_EXIT // Substituted when running CPP
}
});
this.setSize(new Dimension(myImages[0].getHeight(this),
myImages[0].getWidth(this)));
#else
this.resize(myImages[0].getHeight(this),myImages[0].getWidth(this));
#endif
}
#ifdef JAVA1_0
/**
* Handle mouseExit Events in Java 1.0 code
*/
public boolean mouseExit(Event e, int x, int y)
{
MOUSE_EXIT // Substituted when running CPP
return true;
}
/**
* Handle mouseEnter Events in Java 1.0 code
*/
public boolean mouseEnter(Event e, int x, int y)
{
MOUSE_OVER // Substituted when running CPP
return true;
}
/**
* Handle mouseDown Events in Java 1.0 code
*/
public boolean mouseDown(Event e, int x, int y)
{
MOUSE_CLICK // Substituted when running CPP
return true;
}
#endif
/**
* Call update
*/
public void paint(Graphics g)
{
update(g);
}
/**
* Draw the background image
*/
public void update(Graphics g)
{
g.drawImage(myImages[iNum], 0, 0, this);
}
/**
* Launch a class
*/
public void launch()
{
new TestLoader(myClass);
}
}
|