Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. Image loader, applet ce afişează un şir de imagini, în timp ce se poate de scris text în TextArea;
Programul:
package lab_pc_img;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.ActionListener;
import javax.swing.JTextArea;
TextArea jtextArea;
int delay;
Thread animatorThread;
Dimension offDimension;
Image offImage;
Graphics offGraphics;
Image[] images;
add(jtextArea);
setBackground(Color.blue);
String str;
int fps = 2;
str = getParameter("fps");
try {
if (str != null) {
fps = Integer.parseInt(str);
} catch (Exception e) {}
images[i-1] = getImage(getCodeBase(),"images/loading"+i+".gif");
if (frozen) {
} else {
//Start animating!
if (animatorThread == null) {
animatorThread.start();
}
animatorThread = null;
offGraphics = null;
offImage = null;
if (frozen) {
frozen = false;
start();
} else {
frozen = true;
animatorThread = null;
return true;
frameNumber++;
//Display it.
repaint();
try {
startTime += delay;
Thread.sleep(Math.max(0,
startTime-System.currentTimeMillis()));
} catch (InterruptedException e) {
break;
update(g);
if ( (offGraphics == null)
|| (d.width != offDimension.width)
|| (d.height != offDimension.height) ) {
offDimension = d;
offGraphics = offImage.getGraphics();
offGraphics.setColor(getBackground());
offGraphics.setColor(Color.black);
g.drawImage(offImage, 0, 0, this);
}
Rezultatul: