Mercoledi' 4 Dicembre 2002 : 15 29 4 - zito da 193.204.188.254

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class layout extends JApplet implements ActionListener {

JPanel panel;
JScrollBar vscroll;
JButton button;

public void init(){
panel= new JPanel();
vscroll = new JScrollBar();
button = new JButton("clicca qui");

button.addActionListener(this);
panel.setLayout(new BorderLayout());
panel.add(vscroll,BorderLayout.EAST);
panel.add(button,BorderLayout.SOUTH);
getContentPane().add(panel);

}

public void actionPerformed(ActionEvent evt) {
}

}
Mercoledi' 4 Dicembre 2002 : 15 57 3 - zito da 193.204.188.254

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Vita extends JApplet
implements ActionListener{
Display disegno;
JButton tasto;
boolean [][] matrice;
int np = 4;
Timer animazione;
public void start(){
if(animazione==null){
animazione = new Timer(100,this);
animazione.start();
}
}
public void stop(){
if(animazione!=null){
animazione.stop();
}
}
public void actionPerformed(ActionEvent e){
int nv ;
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
nv = contavicini(i,j);

if( matrice[i][j] &&
(nv==0 || nv==1 ||
nv==4 || nv==5 || nv==6 ||
nv==7 || nv==8)){
matrice[i][j]=false;} else {
if(!matrice[i][j]&& nv==3)
matrice[i][j]=true; } }
}
disegno.repaint();
}
int contavicini(int i, int j){
int nv = 0;
int i1,i2,j1,j2;
i1 = i-1;if(i1<0)i1=99;
i2 = i +1;if(i2>99)i2=0;
j1 = j-1;if(j1<0)j1=99;
j2 = j +1;if(j2>99)j2=0;

if(matrice[i1][j])nv=nv+1;//sopra
if(matrice[i1][j2])nv=nv+1;//sopra a destra
if(matrice[i][j2])nv=nv+1;//accanto a destra
if(matrice[i2][j2])nv=nv+1;//sotto a destra
if(matrice[i2][j])nv=nv+1;//sotto
if(matrice[i2][j1])nv=nv+1;//sotto a sinistra
if(matrice[i][j1])nv=nv+1;//accanto a sinistra
if(matrice[i1][j1])nv=nv+1;//sopra a sinistra
return(nv);
}

public void init(){
getContentPane().setLayout(new BorderLayout());
disegno = new Display();
getContentPane().add(disegno,BorderLayout.CENTER);
tasto = new JButton("genera disegno iniziale");
getContentPane().add(tasto,BorderLayout.NORTH);
matrice = new boolean[100][100];
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(Math.random()>.05)matrice[i][j]=true;
else matrice[i][j]=false;
}
}
}
class Display extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(new Color(255,0,0));
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(matrice[i][j])g.fillRect(
i*np,j*np,np,np);
}
}



}
}
}
Mercoledi' 4 Dicembre 2002 : 16 6 1 - Anonimo da labmul10.fisica.uniba.it 193.204.188.67
mj
Mercoledi' 4 Dicembre 2002 : 17 1 1 - zito da 193.204.188.254

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Vita extends JApplet
implements ActionListener{
Display disegno;
JButton tasto,tasto1;
boolean [][] matrice;
boolean anim;
int np = 4;
Timer animazione;
int c=0;

public void startanim(){
if(animazione==null){
animazione = new Timer(100,this);
animazione.start();
} else animazione.restart();
}
public void stopanim(){
if(animazione!=null){
animazione.stop();
}
}
public void actionPerformed(ActionEvent e){

if(e.getSource()==animazione){
int nv ;
// System.out.println("matrice= "+matrice);
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
nv = contavicini(i,j);
if(matrice[i][j]&&c<2)System.out.println("i,j,nv = "+
i+" "+j+" "+nv);
if( matrice[i][j] &&
(nv==0 || nv==1 ||
nv==4 || nv==5 || nv==6 ||
nv==7 || nv==8)){
matrice[i][j]=false;} else {
if(!matrice[i][j]&& nv==3)
matrice[i][j]=true; } }
}

disegno.repaint();
c = c+1;
}
if(e.getSource()==tasto){
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
matrice[i][j]=false;}}
matrice[2][1]=true;
matrice[2][3]=true;
matrice[1][3]=true;
matrice[3][2]=true;
matrice[3][3]=true;

disegno.repaint();

}
if(e.getSource()==tasto1){
if(e.getActionCommand().equals("Stop")){
tasto1.setText("Start");anim=false; stopanim();}
if(e.getActionCommand().equals("Start")){
tasto1.setText("Stop");anim=true;startanim();}
}
}
int contavicini(int i, int j){
int nv = 0;
int i1,i2,j1,j2;
i1 = i-1;if(i1<0)i1=99;
i2 = i +1;if(i2>99)i2=0;
j1 = j-1;if(j1<0)j1=99;
j2 = j +1;if(j2>99)j2=0;

if(matrice[i1][j])nv=nv+1;//sopra
if(matrice[i1][j2])nv=nv+1;//sopra a destra
if(matrice[i][j2])nv=nv+1;//accanto a destra
if(matrice[i2][j2])nv=nv+1;//sotto a destra
if(matrice[i2][j])nv=nv+1;//sotto
if(matrice[i2][j1])nv=nv+1;//sotto a sinistra
if(matrice[i][j1])nv=nv+1;//accanto a sinistra
if(matrice[i1][j1])nv=nv+1;//sopra a sinistra
return(nv);
}

public void init(){
getContentPane().setLayout(new BorderLayout());
disegno = new Display();
getContentPane().add(disegno,BorderLayout.CENTER);
tasto = new JButton("genera disegno iniziale");
tasto.addActionListener(this);
tasto1 = new JButton("Start");
getContentPane().add(tasto,BorderLayout.NORTH);
getContentPane().add(tasto1,BorderLayout.SOUTH);
tasto1.addActionListener(this);
matrice = new boolean[100][100];
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(Math.random()>.05)matrice[i][j]=true;
else matrice[i][j]=false;
}
}
}
class Display extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(new Color(255,0,0));
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(matrice[i][j])g.fillRect(
i*np,j*np,np,np);
}
}



}
}
}
Giovedi' 5 Dicembre 2002 : 15 5 - zito da 193.204.188.254
Lista dei test
Giovedi' 5 Dicembre 2002 : 15 29 3 - zito da 193.204.188.254
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class layout extends JApplet implements ActionListener {

JPanel panel;
JScrollBar vscroll;
JButton button;

public void init(){
panel= new JPanel();
vscroll = new JScrollBar();
button = new JButton("cambia sfondo");

button.addActionListener(this);
panel.setBackground(Color.white);
panel.setLayout(new BorderLayout());
panel.add(vscroll,BorderLayout.EAST);
panel.add(button,BorderLayout.SOUTH);
getContentPane().add(panel);

}

public void actionPerformed(ActionEvent evt) {
if(evt.getSource()==button){
if(evt.getActionCommand()=="cambia sfondo"){
button.setText("Tasto cliccato");
panel.setBackground(Color.black);
}
else{
panel.setBackground(Color.white);
button.setText("cambia sfondo");

}
}

}

}
Giovedi' 5 Dicembre 2002 : 15 40 4 - PC01 da labmul1.fisica.uniba.it 193.204.188.58
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class layout extends JApplet implements ActionListener {

JPanel panel;
JScrollBar vscroll;
JButton button;
JButton button1;

public void init(){
panel= new JPanel();
vscroll = new JScrollBar();
button = new JButton("cambia sfondo");
button1 = new JButton("ripristina");

button.addActionListener(this);
button1.addActionListener(this);
panel.setBackground(Color.white);
panel.setLayout(new BorderLayout());
panel.add(vscroll,BorderLayout.EAST);
panel.add(button,BorderLayout.SOUTH);
panel.add(button1,BorderLayout.NORTH);
getContentPane().add(panel);

}

public void actionPerformed(ActionEvent evt) {
if(evt.getSource()==button){
if(evt.getActionCommand()=="cambia sfondo"){
button.setText("Tasto cliccato");
panel.setBackground(Color.black);
}
}
if(evt.getSource()==button1){
if(evt.getActionCommand()=="ripristina"){
button1.setText("Tasto1 cliccato");
panel.setBackground(Color.white);
}
}
}

}
Giovedi' 5 Dicembre 2002 : 15 56 5 - Ehhh lo sapete fare voi da labmul12.fisica.uniba.it 193.204.188.69
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;

public class layout extends JApplet implements ActionListener {

JPanel panel;
JScrollBar vscroll;
JButton button;
JButton button2;

public void init(){
panel= new JPanel();
vscroll = new JScrollBar();
button = new JButton("cambia sfondo");
button2=new JButton("ripristina lo sfondo");

button.addActionListener(this);
button2.addActionListener(this);
panel.setBackground(Color.white);
panel.setLayout(new BorderLayout());
panel.add(vscroll,BorderLayout.EAST);
panel.add(button,BorderLayout.SOUTH);
panel.add(button2,BorderLayout.NORTH);
getContentPane().add(panel);

}

public void actionPerformed(ActionEvent evt) {
if(evt.getSource()==button){
if(evt.getActionCommand()=="cambia sfondo"){
button.setText("Tasto cliccato");
panel.setBackground(Color.black);
}
}

if(evt.getSource()==button2){
if(evt.getActionCommand()=="ripristina lo sfondo"){
button2.setText("Tasto cliccato");
panel.setBackground(Color.white);

}
}

}
}