Java Applet problem
can anyone help me display a jave applet heres my code below i've tried its annoiying like hell i keep getting a blue background when i display it in the web page. grrr driving me nuts
Web page code
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> erosion demonstration </title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<body>
<font face="comic sans" size="18px">
<center>
<b>
<i>
welcome to wheald of kent erosion demonstration
<i/>
<b/>
<applet code="StructureShapes.class" width=600 height = 400>
</applet>
</center>
<br>
</body>
</html>
Jframe properties
import javax.swing.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.awt.event.*;
class TemplateAbstract extends Applet
{
public TemplateAbstract()
{
setSize(500,500);
setBackground(Color.cyan); /*defines the background colour*/
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);*/
setVisible(true);
}
}
program functionality
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.geom.Arc2D;
import java.awt.geom.Point2D;
public class StructureShapes extends TemplateAbstract
{
int layerheight = 0;
int counter = 0;
//------------------------------------------------------------------------------------------------------//
public StructureShapes()
{
do
{
try
{
Thread.sleep(60); /*controls the drawing speed of the arcs*/
}
catch (InterruptedException e) /*if the program gets interrupted*/
{
}
counter = counter + 1;
layerheight = layerheight+1;
repaint();
}
while (counter < 50);
do
{
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
}
layerheight = layerheight+1;
repaint();
}
while (layerheight<100);
do
{
try
{
Thread.sleep(100);/*controls the speed of the erosion process*/
}
catch (InterruptedException e)
{
}
layerheight = layerheight + 1;
repaint();
}
while (layerheight<160);
}
//---------------------------------------------------------------------------------------------------------//
public void paint(Graphics g)
{
Graphics2D g2D = (Graphics2D) g;
if (layerheight < 100)
{
Point2D.Double position = new Point2D.Double(-40,510-layerheight);/*sets the position of the different layer/*/
/*defines the size of the layer*/
Arc2D.Double water = new Arc2D.Double(position.x, position.y, 575, 120, 30, 140, Arc2D.OPEN);
Arc2D.Double oil = new Arc2D.Double(position.x, position.y-50, 575, 120, 30, 140, Arc2D.OPEN);
Arc2D.Double shale = new Arc2D.Double(position.x, position.y-100, 575, 120, 30, 140, Arc2D.OPEN);
Arc2D.Double sandstone = new Arc2D.Double(position.x, position.y-150, 575, 120, 30, 140, Arc2D.OPEN);
Arc2D.Double limestone = new Arc2D.Double(position.x, position.y-200, 575, 160, 30, 140, Arc2D.OPEN);
g2D.setPaint(Color.BLUE);/*defines the water layer colour*/
g2D.draw(water);
g2D.setPaint(Color.BLACK);/* defines the oil layer colour*/
g2D.draw(oil);
g2D.setPaint(Color.GRAY);/* defines the shale layer colour*/
g2D.draw(shale);
g2D.setPaint(Color.GREEN); /* defines the sandstone layer colour*/
g2D.draw(sandstone);
g2D.setPaint(Color.YELLOW);/* defines the limestone layer colour*/
g2D.draw(limestone);
//------------------------background objects----------------------------//
g2D.setPaint(Color.YELLOW); /* defines the sun layer colour*/
g2D.fillOval(30, 30,100,100);
g2D.setPaint(Color.WHITE); /* defines the cloud1 layer colour*/
g2D.fillOval(60, 90,180,50);
g2D.setPaint(Color.WHITE); /* defines the cloud2 layer colour*/
g2D.fillOval(140, 90,180,50);
g2D.setPaint(Color.WHITE); /* defines the cloud3 layer colour*/
g2D.fillOval(110, 65,180,50);
//---------------------------Erosion layer labels-----------------------//
g2D.setPaint(Color.RED);
g2D.drawString("Erosion", 225,200);
g2D.setPaint(Color.RED);
g2D.drawString("Sandstone", 215,230);
g2D.setPaint(Color.RED);
g2D.drawString("Limestone", 215,280);
g2D.setPaint(Color.RED);
g2D.drawString("Shale", 225,340);
g2D.setPaint(Color.RED);
g2D.drawString("Oil", 230,380);
g2D.setPaint(Color.RED);
g2D.drawString("Water", 225,450);
}
/*erosion process*/
if (layerheight > 100)
{
g2D.setPaint(Color.WHITE);
g2D.fillRect(0,158,500, layerheight-80);
}
}
public static void main (String[] args)
{
StructureShapes frames=new StructureShapes();
}
}
__________________
in opposite world i love programming
|