Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem in running the Applet in a browser

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am trying to run an applet which should draw a graph with parameters it is passed with. When i run this with the help of applet viewer it works good. But when i try running it in a browser with the applet tag on it. It is giving a problem at setBounds method telling that java.awt.component nosuchmethod setBounds() at the bottom of the Browser at the status line.
Can any one help me in solving this problem.
Thanks a bunch
Chandar
The program is
import java.awt.*;
import java.applet.Applet;
/* <APPLET CODE=Graph width=1000 height=1000>
<param name=Hidden1 value="100000">
<param name=Hidden2 value="430000">
.....
<param name=Hidden2 value="430000">
<param name=Text1 value="Total Purchase Balance for jan 1998">
<param name=Text2 value="Total Purchase Balance for feb 1998">
....
<param name=Text12 value="Total Purchase Balance for dec 1998">
</applet> */
public class Graph extends Applet {
private String t[] = new String[100];
public double d[] = new double[100];
private int intD[] = new int[100];
public double bigElement,scaleFactor;
public int noOfElements;
private GraphCanvas drawArea;
public static final int CANVASXPOS = 20 ,CANVASYPOS = 20 , CANVASHEIGHT = 600, BARGRAPHWIDTH = 25;
public Color colorArray[] = {Color.yellow,Color.green,Color.blue,Color.cyan};
private void processParms() {
for (int i=0;i>=0;i++) {
String temp = getParameter("Hidden"+(i+1));
if (temp != null) {
try {
d[i] = Long.parseLong(temp);
}catch(Exception e) {
d[i] = 0;
}
bigElement = (d[i] > bigElement) ? d[i]:bigElement;
t[i] = getParameter("Text"+(i+1));
}
else {
noOfElements = i;
System.out.println(" No of Elements = " + noOfElements);
i = -10;
}
}
}
public void init() {
drawArea = new GraphCanvas();
drawArea.setBackground(Color.red);
drawArea.setBounds(CANVASXPOS,CANVASYPOS,GRAPHWIDTH,GRAPHHEIGHT);
add(drawArea);
processParms();
}
public void paint(Graphics g) {
super.paint(g);
setScale();
System.out.println("TEXT");
drawArea.storeApplet(this);
Graphics g1 = drawArea.getGraphics();
/*for (int i=0;i<noOfElements;i++) {
System.out.println("color = " + (i%colorArray.length) + " i = " + i);
g1.setColor(colorArray[i%colorArray.length]);
g1.fillRect(2*i*BARGRAPHWIDTH ,GRAPHHEIGHT - (int) (scaleFactor * d[i]),BARGRAPHWIDTH,(int)(scaleFactor * d[i]));
}*/
drawArea.paint(g1);
}
public void setScale() {
int i = 0;
while((bigElement = bigElement/Math.pow(10,i)) > Integer.MAX_VALUE) i++;
for (int x=0;x<noOfElements;x++) {
intD[x] =(int)(d[i] = d[i]/Math.pow(10,i));
}

scaleFactor = GRAPHHEIGHT / bigElement;
return;
}
}

The code for GraphCanvas is
import java.awt.*;
public class GraphCanvas extends Canvas {
Graph GraphApplet;
public void storeApplet(Graph x) {
GraphApplet = x;
}
public void paint(Graphics g){
for (int i=0;i<GraphApplet.noOfElements;i++) {
System.out.println("color = " + (i%GraphApplet.colorArray.length) + " i = " + i);
g.setColor(GraphApplet.colorArray[i%GraphApplet.colorArray.length]);
g.fillRect(2*i*GraphApplet.BARGRAPHWIDTH ,GraphApplet.GRAPHHEIGHT - (int) (GraphApplet.scaleFactor * GraphApplet.d[i]),GraphApplet.BARGRAPHWIDTH,(int)(GraphApplet.scaleFactor * GraphApplet.d[i]));
}
}
}








 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like your browser is using an older version of Java which doesn't support "setBounds". setBounds was only introduced in Java 1.1, so if your browser doesn't fully support Java 1.1 you need to either:
1. Use the deprecated "reshape" method in your code. This takes the same parameters, but is deprecated, and may not be supported properly, if at all, in later Java versions.
2. Upgrade your browser to one which supports Java 1.1 properly
(Netscape 4.6 and above seem to work fairly well with Java 1.1 applets)
3. Install a Java plugin which supports a more recent version of Java.
If you are writing your code for Java 2 (ie Jave SDK 1.2 or 1.3), then option 3 is the only generally workable solution. In most cases Java 1.3 is much better than 1.2.
 
Chandar S Vellithirumutha
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks frank. from where can i download the plugins. I have Internet Explorer.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my reply to an earlier thread at:
http://www.javaranch.com/ubb/Forum23/HTML/000091.html .
    Bookmark Topic Watch Topic
  • New Topic