Ahoj, predem se omlouvam za strasne zpraseny kod. S Javou zacinam.
Rad bych v cyklu postupne neco vykresloval, napr. radek s textem. Kdyz ale uspim vlakno, tak se program neda zavrit (to chapu). Jde to uspat nejak jinak, nebo je nutne vytvorit pro vykreslovani nove vlakno? To jsem nikdy nedelal.
btw, jak se daji vsechny vykreslene graficke objekty smazat?
package aplikace;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Line2D;
import javax.swing.JApplet;
import javax.swing.JFrame;
public class Test extends JApplet {
final static int oknoX = 850;
final static int oknoY = 500;
public void init() {
setBackground(Color.white);
setForeground(Color.white);
}
public void paint(Graphics g) {
int x = 50;
int y = 50;
Graphics2D g1 = (Graphics2D) g;
g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g1.setStroke(new BasicStroke(1F));
g1.setPaint(new Color(224, 224, 224));
for (int i = 0; i <= 5; i++) {
g1.draw(new Line2D.Double(10, (i * 25), 800, (i * 25)));
}
while (true) {
g1.drawString("Hello world!", x, y);
x += 15;
y += 15;
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
JFrame f = new JFrame("test");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
JApplet applet = new Test();
f.getContentPane().add("Center", applet);
applet.init();
f.pack();
f.setSize(new Dimension(oknoX, oknoY));
f.setVisible(true);
}
}
Moc dekuji za pomoc.