import java.applet.*; import java.awt.*; public class tekst extends Applet implements Runnable //dziedziczymy z klasy Applet i korzystamy z interfejsu Runnabled { private Thread m_tekst = null; private int xpos = 0; private Font font = null; private int nwidth = -1; // szerokosc napisu private String napis = "jest OK !!!"; public void init() // procedura inicjujaca applet { napis = getParameter("napis"); font = new Font("Helvetica", Font.BOLD, 36); resize(200, 100); setBackground(Color.blue); } public void paint(Graphics g) { if (nwidth == -1) { FontMetrics fm = getFontMetrics(font); nwidth = fm.stringWidth(napis); }; Dimension d = size(); g.setColor(Color.yellow); g.setFont(font); g.drawString(napis, xpos, d.height/2 + 16); } public void start() { if (m_tekst == null) { m_tekst = new Thread(this); m_tekst.start(); } } public void stop() { if (m_tekst != null) { m_tekst.stop(); m_tekst = null; } } public void run() { while (true) { try { // cykliczne przerysowywanie napisu xpos += 5; Dimension d = size(); if (xpos > d.width) xpos = -nwidth; repaint(); Thread.sleep(100); } catch (InterruptedException e) { stop(); } } } }