Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help me on this simple applet

 
Manikantan Nair
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code of one simple applet.
But it is not working. It draws a rect. but then stopped.
what happened to it? Can anybody help me?
the files are following.
thanks...

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class ClickMe extends Applet implements MouseListener
{
private Spot spot=null;
private static final int RADIUS=7;
public void init()
{
addMouseListener(this);
}
public void paint(Graphics g)
{
//Draw a black border in a white background
g.setColor(Color.white);
g.fillRect(0,0, getSize().width-1, getSize().height-1);
g.setColor(Color.blue);
g.drawRect(0,0, getSize().width-1, getSize().height-1);
//Draw the spot
g.setColor(Color.red);
if (spot != null)
{
g.fillOval(spot.x - RADIUS,
spot.y - RADIUS,
RADIUS*2, RADIUS*2);
}
}
public void mousePressed(MouseEvent event)
{
if (spot==null)
{
spot=new Spot(RADIUS);
}
spot.x=event.getX();
spot.y=event.getY();
repaint();
}
public void mouseClicked(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}
---------------------
Spot.java
---------------------
public class Spot
{
public int size;
public int x, y;
public Spot(int intSize)
{
size=intSize;
x=-1;
y=-1;
}
---------------------------
myapplet.html
---------------------------
<HTML>
<BODY>
<applet code="ClickMe.class" width="300" height="150">
</applet>
</BODY>
</HTML>
}
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried it , it ran fine i was able to see a circle in given positions
<applet code = "wwwa5.ewebcity.com/vdn/ClickMe.class" width = 300 height = 300>
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i don't know but i saw someone was able to include gifs ebeded into their html it's nice so i want to know if this will work.
 
Golam Newaz
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I didn't compile and run the program but found one error in
public class Spot{}. Look where is your another } curly bracket
which should be at the last line of the Spot class. Kindly put
a curly bracket and then compile and run again
- Golam Newaz
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has ran fine on my machine only i made the second class with out public modifier .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic