Novità! Stufi delle solite icone? Ecco NuovoNew, un nuovo modo di dire new! Non si può dire che non attiri lo sguardo (però non bisogna abusarne).


Parametri: Questa applet è configurabile. Con i parametri "msg" e "msg2" si possono scegliere i due messaggi che vengono visualizzati. Se inserite messaggi più lunghi, forse bisognerà cambiare le dimensioni dell'applet. Il parametro s (in millisecondi) regola la frequenza del cambiamento nella scritta.
   Finalmente, si può scegliere il colore dello sfondo; per questo bisogna impostare i parametri "rosso", "blu", "verde", che devono essere interi tra 0 e 255. Il colore di sfondo delle pagine web è dato nel modo RGB in esadecimale; se avete difficoltà nel tradurre dall'esadecimale al decimale, si ricorda che la calcolatrice di Windows fà questo lavoro gratis (troverete per esempio che ee in esadecimale vale 238 in decimale).
In conclusione, l'inserzione in una pagina web si fa col seguente codice html:

<applet code="NuovoNew.class" width= 200 height=100 align="left">
<param name="rosso" value="238">
<param name="verde" value="238">
<param name="blu" value="238">
<param name="msg" value="hot!">
<param name="msg2" value="New!!">
<param name="sleep" value="5">
</applet>


Per scaricare l'applet.

Codice sorgente:

import java.applet.*;
import java.awt.*;

public class NuovoNew extends Applet implements Runnable{

/* (c) 2000 ELLIA Ph.
 *
 * Permission to use, copy, modify, and distribute this software
 * for NON-COMMERCIAL purpose and without fee is hereby granted.
 */ 
 
	
Thread runner;
Image miaI;
Graphics offscr;
int a = 0;
int s ;
int f = 20;
int r, gr, bl;
Color bg;
Color colore = Color.blue;
Font ft = new Font("Times",Font.BOLD,f);
int w,h,b;
String St = "";
String S, S2;

public void init() {
	String Pr = getParameter("rosso");
	r = Integer.parseInt(Pr);
	String Pv = getParameter("verde");
	gr = Integer.parseInt(Pv);
	String Pb = getParameter("blu");
	bl = Integer.parseInt(Pb);
	bg = new Color(r, gr, bl);
	S = getParameter("msg");
	S2 = getParameter("msg2");
  	setBackground(bg);
  	String Sl = getParameter("sleep");
  	s = Integer.parseInt(Sl);
  w = getSize().width;
  h = getSize().height;
  miaI = createImage(getSize().width, getSize().height);
  offscr = miaI.getGraphics(); 
	}

public void paint(Graphics g){
	offscr.setColor(bg);
	offscr.fillRect(0,0,w,h);
	offscr.setColor(colore);
	offscr.setFont(ft);
	offscr.drawString(St, 10, 90);
	g.drawImage(miaI, 0, 0, this);
	}
	
public void start() {
  if(runner == null) {
	runner = new Thread(this);
	runner.start();
    	}
     }


public void run() {
  Thread thisThread = Thread.currentThread();
  while(runner == thisThread) {
	if((a % 100) <= 30) {
	  St = S;
	  f += 5;
	  ft = new Font("Times",Font.BOLD,f);
		}
	else if((30 <(a%100))&&((a%100) <= 60)){
	  f -= 5;
	  ft = new Font("Times",Font.BOLD,f);
	}
	else if((a%100)>60){
	  St = S2;
	}
	if(b < 400){
		b += 10;
	}
	else{
		colore = new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
		b = 0;
		}
	a += 1;
	if(f > 200){ f = 160; }
	repaint();
  try {
	Thread.sleep(s);
      } catch(InterruptedException e) { }
    }
 }
 

public void stop() {
 if(runner != null) {
	runner = null;
	}
  }
public void update(Graphics g) {
	paint(g);
	}
}
}