• Java Applet Problem, HELP!
    2 replies, posted
  • Hey guys. I'm trying to make an applet where [B]Main[/B] class gets input from Mouse clicks processed in another class called [B]Mouse[/B]. The problem is, The number of clicks from the[B] Mouse[/B] class doesn't update when I run it. I'm only running the [B]Main[/B] applet. Only the number of clicks are updated inside the Main class. I'm new to Java programming, how do I make this work? Thanks. [B]Main[/B] [code]import java.applet.*; import java.awt.*; import java.awt.event.*; public class Main extends Applet { private Image dbImage;//BUFFER ANTIFLICKER CODE private Graphics dbg;//BUFFER ANTIFLICKER CODE public void update (Graphics g) { } public void init() { } public void paint(Graphics g) { Keyboard keyIO = new Keyboard(); Mouse mouseIO = new Mouse(); Expo.drawString(g,"Implement out: " + mouseIO.numClick(),400,200); Expo.drawString(g,"Local : " + numClick1(),400,300); repaint(); } //-----------MOUSE LISTENER----------- int numClicks; public int numClick1() { return numClicks; } public boolean mouseDown(Event e, int x, int y) { numClicks++; return true; } public boolean mouseDrag(Event e, int x, int y) { return true; } //-----------MOUSE LISTENER----------- } [/code] [B]Mouse[/B] [code]import java.applet.*; import java.awt.*; import java.awt.event.*; public class Mouse extends Applet { public void update (Graphics g) {} int numClicks; public int numClick() { return numClicks; } public boolean mouseDown(Event e, int x, int y) { numClicks++; repaint(); return true; } public boolean mouseDrag(Event e, int x, int y) { return true; } }[/code] So basically if I run the applet and clicks on it a few times, only one updates, the one inside the [B]Main[/B] class.
  • I'm not sure what you expect here. Java does not send mouse events to all Classes which extends Applet. You initialize but do not show the class "Mouse". You would not be able to click both different GUI's anyway. (with one click) What exactly do you wish to do? If it's adding a mouse listener to this applet, use one of these routines from the Applet class: - addMouseListener(MouseListener l) - addMouseMotionListener(MouseMotionListener l) - addMouseWheelListener(MouseWheelListener l)
  • Sounds like a good idea! [URL="http://www.saleoakleyshop.com"]http://[/URL]removed.com gagaghann [highlight](User was permabanned for this post ("Spambot" - Swebonny))[/highlight]