Contenuto della lavagna elettronica

Venerdi' 16 Novembre 2001 : 15 49 4 - zito da 193.204.188.194

import NumericSet;
public class SerieNumeri extends NumericSet{
/*media*/
public double media(){
int totale = 0;
for(int i=0; i < super._length; i++){
totale += super._set[i];
}
return((float)totale/super._length);
}
}
import SerieNumeri;
import java.awt.*;
import java.applet.*;
public class CiaoATutti1 extends Applet {
TextField a;
SerieNumeri serie;
public void init(){
a = new TextField("1 3 9 5");
serie = new SerieNumeri();
serie.setFromString(a.getText());
add(a);
repaint();
}
public void paint(Graphics g){
g.drawString(Double.toString(serie.media()),5,25);
}
}
//
// NumericSet.java - class NumericSet definition
//
// Code Developed for the Java Tutor column in Java Report Magazine
// Copyright (c) 1996 by Philip Meese, All Rights Reserved
//

public class NumericSet {
// member data
int _length=0; // actual no of elemts in set
private int _maxLength=25; // capacity of set
int _set[]; // internal storage array
private boolean _debug=false; // off by default

// member functions
//

// constructor
public NumericSet(){
_set=new int[_maxLength];
}

// parses a string with integers seperated by spaces in it
public void setFromString(String s_){
int idx=0, idxSpace=0;
for(_length=0; _length<_maxLength && idx < s_.length(); _length++){
// find end of first token
idxSpace=s_.indexOf(" ", idx);
if(idxSpace == -1) idxSpace=s_.length(); // end of string

_set[_length]=Integer.parseInt(s_.substring(idx, idxSpace));

// eat white space
while(s_.length() > ++idxSpace &&
!Character.isDigit(s_.charAt(idxSpace)))
;
idx=idxSpace;
}
}

// returns the value of a member of the set
public int value(int idx_){
if(idx_ >= _length) return 0;
else return _set[idx_];
}

// returns the maximum value in the set
public int max(){
int maxValue=0;
for(int i=0;i<_length; i++)
if(maxValue<_set[i]) maxValue=_set[i];
return(maxValue);
}

public int length() { return _length; }

public void dump(){
System.out.println(getClass().getName() + ": " );
for(int i=0; i<_length; i++)
System.out.println(" Elemt #" + i + "=" + _set[i]);
}

public void debugPrintln(String s_){
if(_debug) System.out.println(s_);
}

} // end of class NumericSet

Venerdi' 16 Novembre 2001 : 16 46 3 - zito da 193.204.188.194

import java.awt.*;
import java.applet.*;
public class Caleidoscopio extends Applet{
public void paint(Graphics g){
Color c = new Color((float)Math.random(),
(float)Math.random(),(float)Math.random());
g.setColor(c);
int larghezza = (int)(Math.random()*getSize().width/2.);
int lunghezza = (int)(Math.random()*getSize().height/2.);

g.fillOval(0,0,larghezza,lunghezza);
}
}
Lunedi' 19 Novembre 2001 : 15 0 5 - zito da labmul16.fisica.uniba.it 193.204.188.194

import java.awt.*;
import java.applet.*;
public class Caleidoscopio extends Applet{
public void paint(Graphics g){
int nelem =(int)( Math.random()*100.);
for(int i = 0; i Color c = new Color((float)Math.random(),
(float)Math.random(),(float)Math.random());
g.setColor(c);
int larghezza = (int)(Math.random()*getSize().width/2.);
int lunghezza = (int)(Math.random()*getSize().height/2.);

g.fillOval(0,0,larghezza,lunghezza);
g.fillOval(getSize().width-larghezza,0,larghezza,lunghezza);
g.fillOval(getSize().width-larghezza,getSize().height-lunghezza,larghezza,lunghezza);
g.fillOval(0,getSize().height-lunghezza,larghezza,lunghezza);
}
}
}
Lunedi' 19 Novembre 2001 : 15 21 3 - zito da labmul16.fisica.uniba.it 193.204.188.194
Thread a;
a = null quando l'oggetto non esiste
a = new Thread() a !=null e punta all'oggetto
a = null;
Lunedi' 19 Novembre 2001 : 16 17 2 - io da 193.204.188.59

import java.awt.*;
import java.applet.*;
public class Caleidoscopio extends Applet implements Runnable{

Thread animazione;
Image o;
Graphics og;

Color c;
int x0,y0,larghezza,lunghezza;
int x,y;

public void start() {
if (animazione == null) {
animazione = new Thread(this);
animazione.start();
}
}
public void stop() {
if (animazione != null) {
animazione = null;
}
}


public void run() {
while(animazione!=null) {
for (x = x0; x <= (size().width/2-x0) ; x=x+1) {
repaint();
try { Thread.sleep(100);}
catch (InterruptedException e) { }
}
}
}

public void init() {
o = createImage(size().width,size().height);
og = o.getGraphics();

//int nelem = (int) (Math.random()*100);
//for(int i =0; i < nelem; i++){
c=new Color ((float)Math.random(),(float)Math.random(),(float)Math.random());

larghezza = (int)(Math.random()*getSize().width/2.);
lunghezza = (int)(Math.random()*getSize().height/2.);
x0 = (int)(Math.random()*getSize().width/2.);
x = x0;
y0 = (int)(Math.random()*getSize().height/2.);
y = y0;

//}
}
public void paint (Graphics g){
//int nelem = (int) (Math.random()*100);
//for(int i =0; i < nelem; i++){

og.setColor(Color.white);
og.fillRect(0,0,size().width,size().height);

g.setColor(c);
g.fillOval(x,y,larghezza,lunghezza);
g.fillOval(getSize().width-larghezza-x,y,larghezza,lunghezza);
g.fillOval(getSize().width-larghezza-x,getSize().height-lunghezza-y,larghezza,lunghezza);
g.fillOval(x,getSize().height-lunghezza-y,larghezza,lunghezza);

g.drawImage(o, 0, 0 ,this);
//}
}
}
Lunedi' 19 Novembre 2001 : 17 10 4 - zito da labmul16.fisica.uniba.it 193.204.188.194

import java.awt.*;
import java.applet.*;
public class Caleidoscopio extends Applet implements Runnable{

Thread animazione;
Image o;
Graphics og;

Color c[];
int x0[],y0[],larghezza[],lunghezza[];
int x[],y[],dx[],dy[];
int nelem;
public void start() {
if (animazione == null) {
animazione = new Thread(this);
animazione.start();
}
}
public void stop() {
if (animazione != null) {
animazione = null;
}
}


public void run() {
while(animazione!=null) {
for (int ix = 0; ix <= (size().width/2) ; ix=ix+1) {
for(int i =0; i < nelem; i++){
x[i] = x[i] + dx[i] ;
y[i] = y[i] + dy[i] ;
}
repaint();
try { Thread.sleep(10);}
catch (InterruptedException e) { }
}
}
}

public void update(Graphics g) { paint(g); }

public void init() {
o = createImage(size().width,size().height);
og = o.getGraphics();

nelem = (int) (Math.random()*100);
c = new Color[nelem];
x = new int[nelem];
y = new int[nelem];
x0 = new int[nelem];
y0 = new int[nelem];
dx = new int[nelem];
dy = new int[nelem];
larghezza = new int[nelem];
lunghezza = new int[nelem];

for(int i =0; i < nelem; i++){
c[i]=new Color ((float)Math.random(),(float)Math.random(),(float)Math.random());

larghezza[i] = (int)(Math.random()*getSize().width/2.);
lunghezza[i] = (int)(Math.random()*getSize().height/2.);
x0[i] = (int)(Math.random()*getSize().width/2.);
dx[i] = (int)(Math.random()*getSize().width/80.);

x[i] = x0[i];
y0[i] = (int)(Math.random()*getSize().height/2.);
dy[i] = (int)(Math.random()*getSize().width/80.);
// System.out.println("dx,dy="+dx + " " +dy);
y[i] = y0[i];

//}
}
public void paint (Graphics g){
//int nelem = (int) (Math.random()*100);


og.setColor(Color.white);
og.fillRect(0,0,size().width,size().height);
for(int i =0; i < nelem; i++){
og.setColor(c[i]);
og.fillOval(x[i],y[i],larghezza[i],lunghezza[i]);
og.fillOval(getSize().width-larghezza-x[i],y[i],larghezza[i],lunghezza[i]);
og.fillOval(getSize().width-larghezza[i]-x[i],getSize().height-lunghezza[i]-y[i],larghezza[i],lunghezza[i]);
og.fillOval(x[i],getSize().height-lunghezza[i]-y[i],larghezza[i],lunghezza[i]);
}
g.drawImage(o, 0, 0 ,this);
//}
}
}