Passei uns tempos parados e to enferrujado…
To querendo
private String nomes[] = {"=","0","1","2","3","4","5","6","7","8","9","+","-","*","/"};
private JButton butoes[];
for ( int i = 0; i < nomes.length; i++)
{
butoes[i] = new JButton( nomes[i] );
tecladoPanel.add( butoes[i] );
}
assim mostraria os botoes com os nomes na seguinte sequencia… de = até /… to querendo fazer o contrario mostrar da / ate igual .
como teria de colocar meu codigo ae ?
agredeço
tente:
[code]private String nomes[] = {"=",“0”,“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,"+","-","*","/"};
private JButton butoes[];
for ( int i = 0; i < nomes.length; i++)
{
butoes[i] = new JButton( nomes[nomes.length-i] );
tecladoPanel.add( butoes[i] );
} [/code]
Fala Kra,
Eu faria assim…
private String nomes[] = {"=","0","1","2","3","4","5","6","7","8","9","+","-","*","/"};
private JButton butoes[];
for ( int i = (nomes.length - 1); i >= 0; i--)
{
butoes[i] = new JButton( nomes[i] );
tecladoPanel.add( butoes[i] );
}
hehe, ja tentei isso ae… mas ae vai mostrar so o ultimo ou seja so “/” em todos os locais.
EDIT: isso aqui eh valido para o post do amigo Carlos
o Outro deu certo…
Vlw ae galera…
tenta ae rato!!
aki funcionou!!!
[b]
import java.awt.event.;
import java.awt.;
import javax.swing.;
public class d
{
static private String nomes[] = {"=",“0”,“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,"+","-","","/"};
static private JButton butoes[]=new JButton[nomes.length];
public static void main(String args[])
{
JFrame f=new JFrame();
Container c=f.getContentPane();
f.setLayout(new GridLayout(1,nomes.length));
for ( int i = 0; i < nomes.length; i++)
{
butoes[i] = new JButton( nomes[i] );
c.add( butoes[i] );
}
f.setSize(800,400);
f.show();
}
}
[/b]