Tipo sto le classi:
questa è grafica!
/*
* grafica.java
*
* Created on 31 agosto 2004, 11.59
*/
import java.util.Random;
public class grafica extends javax.swing.JFrame {
private static Random tmpRand; //numero casuale
javax.swing.JTable jTable1;
/** Creates new form grafica */
public grafica() {
initComponents();
}
private void initComponents() {//GEN-BEGIN:initComponents
desktopPane = new javax.swing.JDesktopPane();
jButton2 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
exitMenuItem = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
setTitle("Riassunto statistiche");
desktopPane.setMaximumSize(new java.awt.Dimension(800, 600));
desktopPane.setPreferredSize(new java.awt.Dimension(600, 400));
jButton2.setText("Avvia simulazione");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton2.setBounds(260, 30, 160, 60);
desktopPane.add(jButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);
jTextField1.setText("1");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField1.setBounds(160, 30, 90, 20);
desktopPane.add(jTextField1, javax.swing.JLayeredPane.DEFAULT_LAYER);
jTextField2.setText("1");
jTextField2.setBounds(160, 50, 90, 20);
desktopPane.add(jTextField2, javax.swing.JLayeredPane.DEFAULT_LAYER);
jTextField3.setText("1");
jTextField3.setBounds(160, 70, 90, 20);
desktopPane.add(jTextField3, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel1.setText("Numero di Chef");
jLabel1.setBounds(10, 30, 150, 20);
desktopPane.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel2.setText("Numero di Boat");
jLabel2.setBounds(10, 50, 150, 20);
desktopPane.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel3.setText("Numero di Diner");
jLabel3.setBounds(10, 70, 150, 20);
desktopPane.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
jButton1.setText("Chiudi");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton1.setBounds(240, 340, 71, 30);
desktopPane.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);
jScrollPane1.setViewportBorder(new javax.swing.border.MatteBorder(null));
jTable1.setBorder(new javax.swing.border.TitledBorder(""));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null}
{null, null, null}
},
new String [] {
"Nome", "Stato", "Posizione"
}
));
jTable1.setCellSelectionEnabled(true);
jTable1.setFocusCycleRoot(true);
jTable1.setName("Lista statistiche\n");
jTable1.setNextFocusableComponent(this);
jTable1.setSurrendersFocusOnKeystroke(true);
jScrollPane1.setViewportView(jTable1);
jTable1.getAccessibleContext().setAccessibleName(" tabella");
jTable1.getAccessibleContext().setAccessibleDescri ption("Tabella delle statistiche");
jScrollPane1.setBounds(20, 120, 490, 150);
desktopPane.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);
getContentPane().add(desktopPane, java.awt.BorderLayout.CENTER);
fileMenu.setText("File");
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);
pack();
}//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
System.exit(0);
}//GEN-LAST:event_jButton1ActionPerformed
private void jTextField1ActionPerformed(java.awt.event.ActionEv ent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
final int GRADI = 3; //Spostamento in gradi dei simulatori
int b =Integer.parseInt(jTextField1.getText()); //Integer.parseInt(args[0]); //Leggo il parametro Boat
int s =Integer.parseInt(jTextField2.getText()); //Integer.parseInt(args[1]); //Leggo il parametro Chef
int d =Integer.parseInt(jTextField3.getText()); //Integer.parseInt(args[2]); //Leggo il parametro Diner
if(((b>0) || (b<60)) && ((s>0) || (s<15)) && ((d>0) || (d<70))) { //controllo i valori inseriti.
GestoreMessaggi gestMsg = new GestoreMessaggi(b, s, d); // gestore dei messaggi
Chef[] chef = new Chef[s];
Boat[] boat = new Boat[b];
Diner[] diner = new Diner[d];
tmpRand = new Random();
int tempd=0; //variabile temporanea di contatore per il while
while (tempd<d)
{
int conto=tmpRand.nextInt(80) + 10; //indico quanto può spendere il diner.
try {
diner[tempd] = new Diner(GRADI*tempd, conto, gestMsg);//Inizializzo la classe Diner
}catch(nullRef e) { }
diner[tempd].start(); //lancio il diner
tempd++;
}
int tempi=0; //variabile temporanea di contatore per il while
while (tempi<b)
{
try {
boat[tempi] = new Boat(GRADI*tempi, gestMsg); //Inizializzo la classe Boat
}catch(nullRef e) { }
boat[tempi].start(); //lancio la nave boat
tempi++;
}
int temps=0; //variabile temporanea di contatore per il while
while (temps<s)
{
try {
chef[temps] = new Chef(GRADI*temps, gestMsg); //Inizializzo la classe chef
}catch(nullRef e) { }
chef[temps].start(); //lancio lo chef
temps++;
}
}
}//GEN-LAST:event_jButton2ActionPerformed
private void exitMenuItemActionPerformed(java.awt.event.ActionE vent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed
public void riceviMessaggi(int numero) throws NullPointerException{
jTable1.setValueAt("ciao", numero,0); //CON QUESTO RIEMPI LE CASELLE
jTable1.setValueAt("Chef", 1,0); //CON QUESTO RIEMPI LE CASELLE
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new grafica().show();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JDesktopPane desktopPane;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JMenuBar menuBar;
// End of variables declaration//GEN-END:variables
}
---------------------------
questaè l'altra classe
import java.util.Random;
public class Chef extends Thread {
private int posizione; // posizione dello shef
private static int iddiner = 0; //Identifico un diner
private int[] composizione; // Array contenente
private grafica statistiche;
composizione[0] = categoriapietanza e nel composizione[1] = prezzo
private GestoreMessaggi gestoremess;
private int numchef; //numero identificativo dello shef
private Random tmpRand; //numero casuale
// Costruttore
public Chef (int pos, GestoreMessaggi gestore) throws nullRef {
if (gestore == null) throw new nullRef();
gestoremess = gestore;
composizione = new int[2]; //inizializzo l'array composizione
posizione = pos; //posiziono lo shef
numchef = iddiner++; //Identificazione del tread corrispondente
tmpRand = new Random(); //creo un numero casuale
System.out.println("Sono lo chef numero: " + numchef + " e sono nella posizione: " + posizione);
}
private void lookingForBoat () {
// Aspetto una boat vuota per metterci il piatto preparato.
try {
gestoremess.preparaChef(posizione, composizione[0], composizione[1]);
} catch(InterruptedException err) { }
statistiche.riceviMessaggi(4); ------>>>>QUESTA è DOVE MI DA L'ERRORE.........................................
System.out.println("Sono lo chef numero: " + numchef + " e ho appena caricato una boat con la mia prelibatezza");
}
public void makingSushi () {
// Creazione del sushi
try {
sleep(900); //Preparo il sushi
} catch(InterruptedException err) { }
composizione[0] = tmpRand.nextInt(5) + 1; // categoria del piatto
composizione[1] = tmpRand.nextInt(20)+ 1; // prezzo della composizione
System.out.println("Sono lo chef numero:" + numchef + ": e ho preparato la composizione di Categoria: " + composizione[0] + " e costa euro: " + composizione[1]+ ".00");
}
public void run () {
//Eseguo il tutto
for(;{
makingSushi();
lookingForBoat();
}
}
}
Secondo me non dipende dall'arrayy voi che dite?