Hy i`m new to java ,studin it for 3 months;
I got a code here ; works fine , no errors , but has a weird behavior
here is the code :
so far so good but just compile it and u will see that the lines will just have a bigger sleep time each time a Tread.strat() begins.
S oif someone can tell me how to stop sleep to sleep more each time pls tell me
Thank in advance
I got a code here ; works fine , no errors , but has a weird behavior
here is the code :
Code:
import java.awt.*; import javax.swing.*; public class MultiThread { public static void main (String []args) { Frame frame = new Frame("Frame"); Frame frame2 = new Frame("Frame 2"); Threads t1 = new Threads (); Threads t2 = new Threads (); frame.add(t1); frame.setVisible(true); frame.setSize(400,800); frame.setLocation(100, 0); frame2.add(t2); frame2.setVisible(true); frame2.setSize(400,800); frame2.setLocation(500, 0); new Thread(t1).start(); new Thread(t1).start(); new Thread(t2).start(); new Thread(t1).start(); new Thread(t2).start(); } } class Threads extends JComponent implements Runnable { int x,y; Threads( ) {} public void run () { while (x<100) { x++; y++; repaint(); try { Thread.sleep(23); } catch (Exception e){}; } if (x>=100) x =0; } public void paint (Graphics g) { g.drawLine(x,y,x+30,y+44); } }
S oif someone can tell me how to stop sleep to sleep more each time pls tell me
Thank in advance
Comment