The Artima Developer Community
Sponsored Link

Java Answers Forum
applet not working

1 reply on 1 page. Most recent reply: Nov 14, 2002 4:07 AM by Ger Deasy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
jaz

Posts: 4
Nickname: jaz
Registered: Oct, 2002

applet not working Posted: Nov 13, 2002 10:30 AM
Reply to this message Reply
Advertisement
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class RecBt extends Frame
{
DPanel pan = new DPanel();
int bars = 3;

public RecBt(int w, int h)
{
super();
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent ev)
{ dispose();
System.exit(0);
}
public void windowDeiconified(WindowEvent ev)
{
bars = 4;
}
});
setBounds(6,6,w,h);
add(pan);
setVisible(true);
}
public class DPanel extends Panel
{
Image image;
Color color[] = new Color[4];

public DPanel()
{
image = getToolkit().createImage("flower.jpeg");
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image,0);
try
{
tracker.waitForID(0);
}
catch (InterruptedException e){}
color[0] = Color.red;
color[1] = Color.blue;
color[2] = Color.gray;
color[3] = Color.orange;
}
public void paint(Graphics g)
{
super.paint(g);
int h2 = getHeight()/2;
for (int j=0; j < bars; j++)
{
Bar bar = new Bar(j,0,j*h2/bars,getWidth(),h2/bars);
g.setColor(color[j]);
bar.draw(g);
}
g.drawImage(image,0,h2,getWidth(),h2,null);
}
}
public class Bar
{
int x,y,width,height,num;
String text;

public Bar(int num, int x, int y, int w, int h)
{
this.num = num;
this.x = x;
this.y = y;
width = w;
height = h;
if (num == 3) text = num+" This Is The Extra Line "+num;
else text = num+"Agkgkgkgkgkgkgkgkgkgkgkgk"+num;
}
public void draw(Graphics g)
{
g.fillRect(x,y,width,height);
g.setColor(Color.white);
g.setFont(new Font("",0,height/2));
FontMetrics fm = getFontMetrics(g.getFont());
int tw = fm.stringWidth(text);
g.drawString(text,(width-tw)/2,y+height/2);
}
}
public static void main (String[] args)
{
new RecBt(500,350);
}
}







errors

C:\Documents and Settings\Administrator.DDNETTEST\My Documents\RecBt.java:34: Incompatible type for method. Can't convert java.lang.String to byte[].
image = getToolkit().createImage("flower.jpeg");
^
C:\Documents and Settings\Administrator.DDNETTEST\My Documents\RecBt.java:50: Method getHeight() not found in inner class RecBt. DPanel.
int h2 = getHeight()/2;
^
C:\Documents and Settings\Administrator.DDNETTEST\My Documents\RecBt.java:53: Method getWidth() not found in inner class RecBt. DPanel.
Bar bar = new Bar(j,0,j*h2/bars,getWidth(),h2/bars);
^
C:\Documents and Settings\Administrator.DDNETTEST\My Documents\RecBt.java:57: Method getWidth() not found in inner class RecBt. DPanel.
g.drawImage(image,0,h2,getWidth(),h2,null);
^
4 errors

Tool completed with exit code 1


Ger Deasy

Posts: 4
Nickname: gerd
Registered: Nov, 2002

Re: applet not working Posted: Nov 14, 2002 4:07 AM
Reply to this message Reply
you need to call the methods getHeigth() and getWidth() with whatver you're trying to get the width and heigth of.

for instance if its a Rectangle called rect to get the height you would use rect.getHeight() and for the width rect.getWidth()

Correct me if I'm wrong, as regard the image fault haven't a clue

Flat View: This topic has 1 reply on 1 page
Topic: Converting a String to an Integer Previous Topic   Next Topic Topic: String Tokenizer Output

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use