Fiz umas experiencias mas continua a dar erro:…
se tenho de estudar mais, digam no problem ora
i[code]mport java.awt.;
import javax.swing.;
import javax.swing.border.*;
public class manGui extends JFrame implements ActionListener
{
// variaveis
private JPanel contentPane;
private JPanel jPanel1;
private JPanel jPanel2;
private JPanel jPanel3;
JButton[][] _botoes = null;
public manGui()
{
super();
initializeComponent();
this.setVisible(true);
}
private void initializeComponent()
{
contentPane = (JPanel)this.getContentPane();
//-----
jPanel1 = new JPanel();
//-----
jPanel2 = new JPanel();
//-----
jPanel3 = new JPanel();
//-----
// contentPane
contentPane.setLayout(null);
addComponent(contentPane, jPanel1, 28,75,319,356);
addComponent(contentPane, jPanel2, 368,75,297,356);
addComponent(contentPane, jPanel3, 30,465,636,66);
// jPanel1
jPanel1.setLayout(null);
jPanel1.setBorder(new TitledBorder("Jogador"));
//---------------
_botoes = new JButton[10][10];
for (int i = 0; i< 10; i++){
for (int j = 0; j< 10; j++){
JButton b = new JButton();
b.addActionListener(this);
_botoes[i][j] = b;
JPanel1.add(b,i,j);
}
return JPanel1;
}
//---------------
// jPanel2
jPanel2.setLayout(null);
jPanel2.setBorder(new TitledBorder("Computador"));
// jPanel3
jPanel3.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
// manGui
this.setTitle("IGui");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(722, 577));
}
// Add Componentes
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
//Main
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel(“javax.swing.plaf.metal.MetalLookAndFeel”);
}
catch (Exception ex)
{
System.out.println("Nao abre L&F: ");
System.out.println(ex);
}
new manGui();
}
public void actionPerformed(ActionEvent e) {
// OBS: o botão 0,0 (Ref) é o do cando inferior esquerdo
for (int i = 0; i< 10; i++){
for (int j = 0; j< 10; j++){
if (e.getSource() == _botoes[i][j]){
JOptionPane.showMessageDialog(this, "botão: " + i + “,” + j);
}
}
}
}
}
[/code]