|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Junior Member
Iscritto dal: Aug 2007
Messaggi: 9
|
[Java] Passaggio valori classe interna
Salve a tutti,
Questo è il mio codice: Codice:
public void Setta(int i, int j)
{
class Colore implements ActionListener
{
private int n=0;
public void actionPerformed(ActionEvent event)
{
if (n==0||n==3)
{
a[i][j].setBackground(Color.green);
n=0;
}
else if (n==1)
a[i][j].setBackground(Color.orange);
else if (n==2)
a[i][j].setBackground(Color.red);
n++;
}
}
ActionListener listener = new Colore();
a[i][j].addActionListener(listener);
}
Se clicco 0 volta o più di 2 volte, il pulsante deve ridiventare verde altrimenti arancione per 1 click e rosso per 2 click. Problea: non riesco a richiamare setBackground sul pulsante indicato da i e j perchè ovviamente li passo al metodo e non alla classe interna. Come posso risolvere? Forse è di una semplicità assurda, ma non ci arrivo. Grazie x l'aiuto ^^ |
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
Codice:
... JButton b= a[i][j]; ActionListener listener = new Colore(b); b.addActionListener(listener);
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 19:51.



















