Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 18th, 2009, 01:57 PM
Authorized User
 
Join Date: Nov 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chris1012
Default 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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Applet - Search with Slider options itHighway Classic ASP Basics 0 June 10th, 2006 02:49 AM
java applet trick convet to c# chall3ng3r General .NET 0 February 8th, 2005 11:22 PM
display element (layer) over java applet mateenmohd Java GUI 0 January 6th, 2004 12:39 AM
Java Applet that can read an XML file sankar J2EE 1 December 25th, 2003 05:40 AM
Plotting a graph on a Java Applet cooldude87801 BOOK: Beginning Java 2 1 June 12th, 2003 08:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.