-
BoxApplet
The applet does not run. all i get is a message saying the applet is not initialised.
package applets;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class BoxApplet extends JApplet {
private boolean isStandalone = false;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public BoxApplet() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public void paint(Graphics g) {
drawX(g, 30, 50, 300, 200, 10);
}
private void drawX(Graphics g, int x, int y, int width, int height, int inset) {
Graphics gim = g.create();
gim.setColor(Color.yellow);
gim.fillRect(x, y, width, height);
gim.setColor(Color.black);
gim.drawRect(x, y, width, height);
int innerWidth = width - 2*inset;
int innerHeight = height - 2*inset;
if (innerWidth <= 0 || innerHeight <= 0)
return;
int innerX = x + inset;
int innerY = y + inset;
gim.setColor(Color.red);
gim.drawRect(innerX, innerY, innerWidth, innerHeight);
gim.setColor(Color.black);
gim.drawLine(innerX, innerY, innerX + innerWidth, innerY+innerHeight);
gim.drawLine(innerX + innerWidth, innerY, innerX, innerY + innerHeight);
gim.dispose();
}
//Component initialization
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
//static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks