JOptionPane.showInputDialog on JButton[][] array

From: Alessandro Mizzoni (alessandro.mizzoni_at_fastwebnet.it)
Date: 08/25/04


Date: Wed, 25 Aug 2004 23:22:53 +0200

Sorry i have a problem.
I don't know the java language but i must create a grid Of button witch
random Values, and when i clicked on one button i must change the internal
values.
I try ti make a code but i don't know how to pass the value of botton to
mouse event, and change it with
String input = JOptionPane.showInputDialog("Insert value:");

for a single button there aren't any problems, but how can I change the
value of an array of button witch MouseEvent?

Thx!!!! please help me!!!!

QUADRATOFRAME.CLASS

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class QuadratoFrame extends JFrame {

 JButton pulsante = new JButton();
 int N=6;
 int MAXELEM = 50;
 int[][] mat=new int[N][N];
 JButton[][] jb = new JButton[N][N];
 private JPanel pannello2= new JPanel();
 LeftButtonListener leftListener = new LeftButtonListener();

 public QuadratoFrame() {

 Random generator=new Random();
 for (int i=0; i<N; i++)
     for (int j=0; j<N; j++)
       mat[i][j]=generator.nextInt(MAXELEM);

 for(int i = 0; i < N; i++)
     for (int j=0; j<N; j++)
        {
            jb[i][j] = new JButton(Integer.toString(mat[i][j]));
            pulsante=jb[i][j];
            pulsante.addMouseListener(leftListener);
        }

    pannello2.setLayout(new GridLayout(N,N));
    getContentPane().add(pannello2);
    pack();

       for(int i = 0; i < jb.length; i++)
          for (int j=0; j<N; j++)
           pannello2.add(jb[i][j]);

    }

     private class LeftButtonListener implements MouseListener {
     public void mouseClicked(MouseEvent event) { }
     public void mouseEntered(MouseEvent event) { }
     public void mouseExited(MouseEvent event) { }
     public void mousePressed(MouseEvent event) {
          String input = JOptionPane.showInputDialog("Insert new value:");
         }

     public void mouseReleased(MouseEvent event) { }

      }

}

QUADRATOTEST.CLASS

import javax.swing.*;

/**Una classe che rende attivo il programma Frattali
 *tramite la costruzione e la visualizzazione della finestra Frattali nel
main.
 */

public class QuadratoTest {

 public static void main(String[] args) {
  JFrame myFrame=new QuadratoFrame();
  myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  myFrame.setSize(800,600);
  myFrame.show();

 }

}