Contenuto della lavagna elettronica

Venerdi' 12 Ottobre 2001 : 13 37 2 - zito da labmul4.fisica.uniba.it 193.204.188.61
oogetti: ChartTool applet
NumericSet sequenza di numeri
BarChart estende Canvas - grafico
TextField - finestrella dei numeri
GaphIt - tasto
un file contiene un'unica classe public

public,private,protected,(niente)
possibilita' di accesso

double vett[];
vett = new double[10]

metodi in C++ : member functions

while(s_.length() > ++idxSpace && !Character.isDigit(s_.charAt(idxSpace))
Venerdi' 12 Ottobre 2001 : 14 8 3 - zito da labmul4.fisica.uniba.it 193.204.188.61

while(condizione) { }

AND &&
OR ||
NOT !
==

BorderLayout - serve a disporre degli oggetti grafici in una finestra
North
East Center West
South

setLayout - metodo di applet che permette di definire un
oggetto di posizionamento
add - aggiunge un oggetto grafico

oggetto Color
Color c = new Color(.4,.3,.2);
Color.white;
Math.PI;

Java 2
Lunedi' 15 Ottobre 2001 : 13 59 1 - Anonimo da 193.204.188.61

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

public class Layout extends Applet{
Button bottone1,bottone2,bottone3,b1,b2,b3;
Panel p;

public void init(){
bottone1=new Button("nord");
bottone2=new Button("sud");
bottone3=new Button("est");
p=new Panel();
p.setLayout(new GridLayout(3,1));
p.add(new Button("b1"));
p.add(new Button("b2"));
p.add(new Button("b3"));
setLayout(new BorderLayout());
add(bottone1,BorderLayout.NORTH);
add(bottone2,BorderLayout.SOUTH);
add(bottone3,BorderLayout.EAST);
add(p,BorderLayout.CENTER);
}


Lunedi' 15 Ottobre 2001 : 14 45 4 - Anonimo da 193.204.188.61
import java.awt.Graphics;
import java.awt.Image;
import java.applet.Applet;

public class Immagine extends Applet{

Image img;

public void init(){

img = getImage( getCodeBase(), "infn1.gif" );

}

public void paint(Graphics g){

g.drawImage(img, 100,100,80,80, this);

}
}

Martedi' 16 Ottobre 2001 : 10 35 5 - Anonimo da 193.204.188.74

No comment

Martedi' 16 Ottobre 2001 : 10 50 5 - Anonimo da 193.204.188.74

No comment

Martedi' 16 Ottobre 2001 : 14 39 1 - Anonimo da labmul2.fisica.uniba.it 193.204.188.59
import java.awt.*;
import java.applet.Applet;
import java.awt.Graphics;

import java.awt.Image;



public class Immagine2 extends Applet{
Button b1,b2,b3;
Scrollbar sc;
Image img,img2;
Panel p;

public void init(){

img = getImage( getCodeBase(), "ace.jpg" );
img2 = getImage( getCodeBase(), "ace.gif" );
sc= new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,300);
b1 = new Button("fiesta");
b2 = new Button("la scienzassai");
b3 = new Button("ahio");
p = new Panel();
p.setLayout(new GridLayout());
p.add(b1);
p.add(b2);
p.add(b3);
setLayout(new BorderLayout());
//add(sc);
add("North",p);



}



public void paint(Graphics g){
g.drawImage(img, 300,100,180,180, this);
g.drawImage(img2, 80,100,80,80, this);
}
}


Martedi' 16 Ottobre 2001 : 15 11 - Anonimo da labmul4.fisica.uniba.it 193.204.188.61
import java.awt.*;
import java.awt.Graphics;
import java.awt.Image;
import java.applet.Applet;
import java.awt.event.*;
public class Immagine extends Applet implements ActionListener{
Button b1,b2,b3;
Scrollbar sc;
Image img,img2;
Panel p;
boolean im1,im2;

public void init(){
im1=true;
im2=false;
img = getImage( getCodeBase(), "infn1.gif" );
img2 = getImage( getCodeBase(), "max.gif" );

sc = new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,300);
b1 = new Button("Immagine1");
b2 = new Button("Immagine2");
b3 = new Button("Immagine3");
b1.addActionListener(this);
b2.addActionListener(this);
p = new Panel();
p.setLayout(new GridLayout());
p.add(b1);
p.add(b2);
p.add(b3);
setLayout(new BorderLayout());
//add(sc);
add("North",p);
}
public void actionPerformed(ActionEvent evt){
if(evt.getSource()==b1){
System.out.println("b1");
im1=true;
im2=false;
}
if(evt.getSource()==b2){
System.out.println("b2");

im1=false;
im2=true;
}
}

public void paint(Graphics g){

if(im1)g.drawImage(img, 100,100,80,80, this);
if(im2)g.drawImage(img2, 150,150,80,80, this);
}
}

Martedi' 16 Ottobre 2001 : 15 16 2 - Anonimo da labmul4.fisica.uniba.it 193.204.188.61
import java.awt.*;
import java.awt.Graphics;
import java.awt.Image;
import java.applet.Applet;
import java.awt.event.*;
public class Immagine extends Applet implements ActionListener{
Button b1,b2,b3;
Scrollbar sc;
Image img,img2;
Panel p;
boolean im1,im2;

public void init(){
im1=true;
im2=false;
img = getImage( getCodeBase(), "infn1.gif" );
img2 = getImage( getCodeBase(), "max.gif" );

sc = new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,300);
b1 = new Button("Immagine1");
b2 = new Button("Immagine2");
b3 = new Button("Immagine3");
b1.addActionListener(this);
b2.addActionListener(this);
p = new Panel();
p.setLayout(new GridLayout());
p.add(b1);
p.add(b2);
p.add(b3);
setLayout(new BorderLayout());
//add(sc);
add("North",p);
}
public void actionPerformed(ActionEvent evt){
if(evt.getSource()==b1){
System.out.println("b1");
im1=true;
im2=false;
}
if(evt.getSource()==b2){
System.out.println("b2");
setBackground(Color.red);
im1=false;
im2=true;
}
repaint();
}

public void paint(Graphics g){

if(im1)g.drawImage(img, 100,100,80,80, this);
if(im2)g.drawImage(img2, 150,150,80,80, this);
}
}

Martedi' 16 Ottobre 2001 : 15 31 1 - Anonimo da labmul2.fisica.uniba.it 193.204.188.59
import java.awt.*;
import java.applet.Applet;
import java.awt.Graphics;

import java.awt.Image;
import java.awt.event.*;


public class Immagine2 extends Applet implements ActionListener{
Button b1,b2,b3;
Scrollbar sc;
Image img,img2,img3;
Panel p;
boolean im1,im2,im3;

public void init(){

im1=false;
im2=false;
im3=false;
img = getImage( getCodeBase(), "ace.jpg" );
img2 = getImage( getCodeBase(), "ace.gif" );
img3 = getImage( getCodeBase(), "img3.gif" );
sc= new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,300);
b1 = new Button("fiesta");
b2 = new Button("la scienzassai");
b3 = new Button("ahio");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);

p = new Panel();
p.setLayout(new GridLayout());
p.add(b1);
p.add(b2);
p.add(b3);
setLayout(new BorderLayout());
//add(sc);
add("North",p);
}

public void actionPerformed (ActionEvent evt){

if(evt.getSource()==b1){

im1=true; im2=false; im3=false;
}

if(evt.getSource()==b2){

im2=true;im1=false; im3=false;
}
if(evt.getSource()==b3){

im3=true;im1=false; im2=false;
}
repaint();
}
public void paint(Graphics g){
if(im1==true)g.drawImage(img,300,100,180,180, this);
if(im2==true)g.drawImage(img2, 50,100,80,80, this);
if(im3==true)g.drawImage(img3, 180,100,80,80, this);
}
}

Martedi' 16 Ottobre 2001 : 15 44 2 - zito da labmul4.fisica.uniba.it 193.204.188.61
Interface - classe particolare
descrizione con solo metodi vuoti
Ogni classe estend un'unica classe normale e puo'
implementare un numero qualsiasi di interfacce
Mercoledi' 17 Ottobre 2001 : 13 36 4 - zito da labmul4.fisica.uniba.it 193.204.188.61
Thread - oggetto che serve per definire un programma da
eseguire in parallelo
run - metodo dove e' definito il programma in parallelo
this - indica l'oggetto nel quale ci troviamo
super - lo'oggetto genitore
this()- costruttore dell'oggetto nel quale ci troviamo
super() - costruttore dell'oggetto genitore
Mercoledi' 17 Ottobre 2001 : 14 21 2 - Anonimo da labmul6.fisica.uniba.it 193.204.188.63
import java.awt.*;
import java.applet.Applet;
import java.awt.Graphics;

import java.awt.Image;
import java.awt.event.*;


public class Immagine2 extends Applet implements ActionListener,Runnable{
Thread animazione;
Button b1,b2,b3,b4;
Scrollbar sc;
Image img,img2,img3;
Panel p;
boolean im1,im2,im3,im4;
int x,y,r;

public void init(){

r = 100;
im1=false;
im2=false;
im3=false;
im4=true;
img = getImage( getCodeBase(), "fufis.jpg" );
img2 = getImage( getCodeBase(), "RIGHT1.gif" );
img3 = getImage( getCodeBase(), "MARE.gif" );
sc= new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,300);
b1 = new Button("gatto1");
b2 = new Button("gatto2");
b3 = new Button("mare");
b4 = new Button("animazione");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);



p = new Panel();
p.setLayout(new GridLayout());
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(sc);
setLayout(new BorderLayout());
add("North",p);
}
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 = r; x <= size().width ; x=x+1) { repaint();
try { Thread.sleep(100);} catch (InterruptedException e) { } } } }



public void actionPerformed (ActionEvent evt){

if(evt.getSource()==b1){

im1=true; im2=false; im3=false; im4=false;

}

if(evt.getSource()==b2){
im2=true; im1=false; im3=false; im4=false;

}
if(evt.getSource()==b3){

im3=true; im1=false; im2=false; im4=false;


}
if(evt.getSource()==b4){

im3=false;im1=false; im2=false; im4=true;
}
repaint();
}
public void paint(Graphics g){
if(im1==true)g.drawImage(img,0,100, this);
if(im2==true)g.drawImage(img2,0,100, this);
if(im3==true)g.drawImage(img3, 0,100,this);
if(im4)g.drawImage(img3, 0,100,this);
g.drawImage(img2, x,200,this);

}
}
Mercoledi' 17 Ottobre 2001 : 14 26 1 - zito da labmul4.fisica.uniba.it 193.204.188.61

import java.awt.*;
import java.applet.Applet;
import java.awt.Graphics;

import java.awt.Image;
import java.awt.event.*;


public class Immagine2 extends Applet implements ActionListener,
Runnable{
Thread animazione;
Button b1,b2,b3,b4;
Scrollbar sc;
Image img,img2,img3;
Panel p;
boolean im1,im2,im3,im4;
int x,y,r;
public void init(){
r = 100;
im1=false;
im2=false;
im3=false;
im4=true;
img = getImage( getCodeBase(), "fufis.jpg" );
img2 = getImage( getCodeBase(), "RIGHT1.gif" );
img3 = getImage( getCodeBase(), "MARE.gif" );
sc= new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,300);
b1 = new Button("gatto1");
b2 = new Button("gatto2");
b3 = new Button("mare");
b4 = new Button("animazione");


b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);


p = new Panel();
p.setLayout(new GridLayout());
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(sc);
setLayout(new BorderLayout());
add("North",p);
}
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 = r; x <= size().width ; x=x+1) { repaint();
try { Thread.sleep(100);} catch (InterruptedException e) { } } } }

public void actionPerformed (ActionEvent evt){
if(evt.getSource()==b1){

im1=true; im2=false; im3=false;im4=false;
}

if(evt.getSource()==b2){
im2=true;im1=false; im3=false;im4=false;
}
if(evt.getSource()==b3){

im3=true;im1=false; im2=false;im4=false;
}
if(evt.getSource()==b4){

im3=false;im1=false; im2=false;im4=true;
}

repaint();
}
public void paint(Graphics g){
if(im1==true)g.drawImage(img,0,100, this);
if(im2==true)g.drawImage(img2,0,100, this);
if(im3==true)g.drawImage(img3, 0,100,this);
if(im4){g.drawImage(img3, 0,100,this);
g.drawImage(img2, x,200,this);

}
}
}
Mercoledi' 17 Ottobre 2001 : 14 36 1 - zito da labmul4.fisica.uniba.it 193.204.188.61

import java.awt.*;
import java.applet.Applet;
import java.awt.Graphics;

import java.awt.Image;
import java.awt.event.*;


public class Immagine2 extends Applet implements ActionListener,
Runnable{
Image o;
Graphics og;

Thread animazione;
Button b1,b2,b3,b4;
Scrollbar sc;
Image img,img2,img3;
Panel p;
boolean im1,im2,im3,im4;
int x,y,r;
public void init(){
o = createImage(size().width,size().height);
og = o.getGraphics();

r = 100;
im1=false;
im2=false;
im3=false;
im4=true;
img = getImage( getCodeBase(), "fufis.jpg" );
img2 = getImage( getCodeBase(), "RIGHT1.gif" );
img3 = getImage( getCodeBase(), "MARE.gif" );
sc= new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,300);
b1 = new Button("gatto1");
b2 = new Button("gatto2");
b3 = new Button("mare");
b4 = new Button("animazione");


b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);


p = new Panel();
p.setLayout(new GridLayout());
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(sc);
setLayout(new BorderLayout());
add("North",p);
}
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 = r; x <= size().width ; x=x+1) { repaint();
try { Thread.sleep(100);} catch (InterruptedException e) { } } } }

public void actionPerformed (ActionEvent evt){
if(evt.getSource()==b1){

im1=true; im2=false; im3=false;im4=false;
}

if(evt.getSource()==b2){
im2=true;im1=false; im3=false;im4=false;
}
if(evt.getSource()==b3){

im3=true;im1=false; im2=false;im4=false;
}
if(evt.getSource()==b4){

im3=false;im1=false; im2=false;im4=true;
}

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

public void paint(Graphics g){
if(im1==true)og.drawImage(img,0,100, this);
if(im2==true)og.drawImage(img2,0,100, this);
if(im3==true)og.drawImage(img3, 0,100,this);
if(im4){
og.setColor(Color.white);
og.fillRect(0,0,size().width,size().height);

og.drawImage(img3, 0,100,this);
og.drawImage(img2, x,200,this);

}
g.drawImage(o, 0, 0 ,this);

}
}
Mercoledi' 17 Ottobre 2001 : 15 20 3 - zito da labmul10.fisica.uniba.it 193.204.188.67

import java.awt.*;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.image.*;
import java.awt.event.*;

public class Immagine2 extends Applet implements ActionListener, Runnable {
Thread animazione;
Image o;
Graphics og;
InverseColorFilter filter;
Image negative;

Button b1,b2,b3,b4,b5;
Scrollbar sc;
Image img,img2,img3;
Panel p;
boolean im1,im2,im3,im4,im5;
int x,y,r;

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

r = 100;
im1=false;
im2=false;
im3=false;
im4=true;
im5=false;
img = getImage( getCodeBase(), "fufis.jpg" );

filter = new InverseColorFilter ();
negative = createImage (new FilteredImageSource (img.getSource (), filter));

img2 = getImage( getCodeBase(), "RIGHT1.gif" );
img3 = getImage( getCodeBase(), "MARE.gif" );

sc= new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,300);
b1 = new Button("gatto1");
b2 = new Button("gatto2");
b3 = new Button("mare");
b4 = new Button("animazione");
b5 = new Button("nuovo colore");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);

p = new Panel();
p.setLayout(new GridLayout());
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(sc);
setLayout(new BorderLayout());
add("North",p);
}
public void start() {
if(im4==true)
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 = r; x <= size().width ; x=x+1) {
repaint();
try { Thread.sleep(100);}
catch (InterruptedException e) { } } } }


public void actionPerformed (ActionEvent evt){

if(evt.getSource()==b1){
im1=true;
im2=false;
im3=false;
im4=false;
im5=false;
stop();

}

if(evt.getSource()==b2){
im2=true;
im1=false;
im3=false;
im4=false;
im5=false;
stop();

}

if(evt.getSource()==b3){
im3=true;
im1=false;
im2=false;
im4=false;
im5=false;
stop();
}

if(evt.getSource()==b4){
im3=true;
im1=false;
im2=false;
im4=true;
im5=false;
start();
}

if(evt.getSource()==b5){
im5=true;
im1=false;
im2=false;
im3=false;
im4=false;
start();
}


repaint();
}
public void paint(Graphics g){
og.setColor(Color.white);
og.fillRect(0,0,size().width,size().height);
if(im1==true)og.drawImage(img,0,100, this);
if(im2==true)og.drawImage(img2,0,100, this);
if(im3==true)og.drawImage(img3, 0,100,this);
if(im4==true){


og.drawImage(img3, 0,100,this);
og.drawImage(img2, x,200,this);

}
if(im5==true)og.drawImage(negative,0,100, this);
g.drawImage(o, 0, 0 ,this);

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

}

class InverseColorFilter extends RGBImageFilter
{
public InverseColorFilter () {
canFilterIndexColorModel = true; }

public int filterRGB (int x, int y, int rgb) {
int red = (rgb & 0xff0000) >>16;
int green = (rgb & 0xff00) >> 8;
int blue = rgb & 0xff;

red = 255-red; green = 255-green; blue = 255 - blue;

return (0xff000000 | (red << 16) | (green << 8) | blue); }
}