Results 1 to 2 of 2
Thread: Applet and multithreading
- 08-03-2009, 08:03 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 1
- Rep Power
- 0
Applet and multithreading
hey guyz...am really having trouble with this prog...can anyone plzzz help....i'll explain the code...
I have a simple applet code..it marquees a line...i want to make it stop at a particular interval and make it continue on mouse clicking...so I use wait()..but on using notifyAll() nothing happens...can anyone plz help...and forgive me if there is any stupid errors in the code...
Java Code:import java.awt.*; import java.awt.event.*; import java.applet.*; public class threadtest extends Applet implements MouseListener{ String msg,statusmsg; int x=20,y=30,i; newthread nt=new newthread(); public void init() { setForeground(Color.blue); addMouseListener(this); } public void paint(Graphics g) { g.drawString(msg, x, y); } public void mouseExited(MouseEvent me){} public void mouseEntered(MouseEvent me){} public void mousePressed(MouseEvent me){} public void mouseReleased(MouseEvent me){} public void mouseClicked(MouseEvent me) { showStatus("Mouse is clicked"); msg="look at the mouse"; repaint(); nt.t.start(); } synchronized void resumenow() { notify(); } synchronized void suspendnow() { try { showStatus("Thread is in suspendnow()"); wait(); } catch (InterruptedException ex) {} } public void start() { msg = "Started"; for(i=0;i<100;i++) { if(x>200) { x=20; } x=x+1; repaint(); if(i%3==0) { showStatus("This thread is gonna wait"); repaint(); suspendnow(); showStatus("thread is waiting"); } } } } class newthread implements Runnable{ Thread t; public newthread() { t=new Thread(this); } public void run() { resumenow(); } synchronized void resumenow() { notifyAll(); } synchronized void suspendnow() { try { wait(); } catch (InterruptedException ex) {} } }
thanks in advance
- 08-03-2009, 09:47 PM #2
Member
- Join Date
- Aug 2009
- Location
- Kharkov, Ukraine
- Posts
- 29
- Rep Power
- 0
Similar Threads
-
multithreading
By shilpa.krishna in forum New To JavaReplies: 2Last Post: 06-27-2008, 04:18 PM -
socket Multithreading - & - Obtaining the IP of a client!
By bluebarca in forum NetworkingReplies: 1Last Post: 11-16-2007, 10:09 AM -
Multithreading + Networking (desperate)
By bluebarca in forum New To JavaReplies: 1Last Post: 11-07-2007, 02:14 PM


LinkBack URL
About LinkBacks

Bookmarks