Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.Applet;
- import java.awt.*;
- import java.util.ArrayList;
- import java.util.Collections;
- /**
- * Created by DoublyDead on 28.08.14.
- */
- public class Test extends Applet implements Runnable
- {
- String msg = "Лол";
- Thread t = null;
- boolean stopFlag;
- java.util.List<String> list;
- public void init()
- {
- setBackground(Color.white);
- setForeground(Color.black);
- list = new ArrayList<>();
- list = Collections.synchronizedList(list);
- list.add("Привет");
- list.add("Я твой");
- list.add("Друг");
- }
- public void start()
- {
- t = new Thread(this);
- stopFlag = true;
- t.start();
- }
- @Override
- public void run()
- {
- for(;;)
- {
- repaint();
- try
- {
- int rand = (int)(Math.random()*3);
- System.out.println(rand);
- msg = list.get(rand);
- Test.this.repaint();
- Thread.sleep(500);
- }catch (InterruptedException e)
- {}
- }
- }
- public void paint(Graphics g)
- {
- super.paint(g);
- g.drawString(msg, 10, 40);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement