Advertisement
Yoghurt_92

Untitled

Aug 28th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.awt.*;
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5.  
  6. /**
  7.  * Created by DoublyDead on 28.08.14.
  8.  */
  9. public class Test extends Applet implements Runnable
  10. {
  11.     String msg = "Лол";
  12.     Thread t = null;
  13.     boolean stopFlag;
  14.     java.util.List<String> list;
  15.  
  16.     public void init()
  17.     {
  18.         setBackground(Color.white);
  19.         setForeground(Color.black);
  20.         list = new ArrayList<>();
  21.         list = Collections.synchronizedList(list);
  22.         list.add("Привет");
  23.         list.add("Я твой");
  24.         list.add("Друг");
  25.     }
  26.  
  27.     public void start()
  28.     {
  29.         t = new Thread(this);
  30.         stopFlag = true;
  31.         t.start();
  32.     }
  33.  
  34.     @Override
  35.     public void run()
  36.     {
  37.         for(;;)
  38.         {
  39.             repaint();
  40.             try
  41.             {
  42.                 int rand = (int)(Math.random()*3);
  43.                 System.out.println(rand);
  44.                 msg = list.get(rand);
  45.                 Test.this.repaint();
  46.  
  47.                 Thread.sleep(500);
  48.             }catch (InterruptedException e)
  49.             {}
  50.         }
  51.     }
  52.  
  53.     public void paint(Graphics g)
  54.     {
  55.         super.paint(g);
  56.         g.drawString(msg, 10, 40);
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement