Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/06/2014, 09:58
delhorno
 
Fecha de Ingreso: enero-2005
Mensajes: 85
Antigüedad: 19 años, 3 meses
Puntos: 0
Respuesta: Error JAVA swing al mostrar componentes

estoy poniendo el metodo updateUI() por todos lados, pero no me funciona, por si sirve de ayuda expongo el cógido completo:

Cita:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package interfaz;

import barcos.Barco;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.Border;
import tablero.Tablero;

/**
*
* @author Juan
*/
public class Juego extends JFrame implements ActionListener{

private int filas,columnas;
private Tablero usuario,pc;
private JPanel panelBienvenida,panelEligeSup,panelEligeCentro,pan el,sidebar,panelUsuario,panelPC;
private JButton boton;
private JButton [][] botones;
private JTextField alto, ancho;
private JComboBox posiciones;

public Juego(){


setSize(500,200);
setVisible(true);


panelBienvenida = new JPanel(new FlowLayout());
this.add(panelBienvenida);




alto = new JTextField("10");
ancho = new JTextField("10");
boton = new JButton("iniciar");
boton.addActionListener(this);

panelBienvenida.add(alto);
panelBienvenida.add(ancho);
panelBienvenida.add(boton,FlowLayout.RIGHT);


this.setLocationRelativeTo(null);
this.paintAll(this.getGraphics());

}

public void eligePosiciones(){

setLayout(new BorderLayout());
panelEligeSup = new JPanel();
this.add(panelEligeSup,BorderLayout.NORTH);

JLabel elige = new JLabel("Elige la posicion del barco");
panelEligeSup.add(elige,BorderLayout.CENTER);

String [] comboPosiciones = new String []{"Horizontal","Vertical"};
posiciones = new JComboBox(comboPosiciones);

panelEligeSup.add(posiciones,BorderLayout.SOUTH);

panelEligeCentro = new JPanel(new GridLayout(this.filas,this.columnas,10,10));
this.add(panelEligeCentro,BorderLayout.CENTER);

botones = new JButton[this.filas][this.columnas];

usuario = new Tablero(this.filas,this.columnas,0);

for (int i = 0; i < filas; i++) {
for (int j = 0; j < columnas; j++) {
botones[i][j] = new JButton(String.valueOf(i)+":"+String.valueOf(j));
botones[i][j].addActionListener(this);
panelEligeCentro.add(botones[i][j]);
}
}


this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
this.setLocationRelativeTo(null);
this.paintAll(this.getGraphics());
}


@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(boton)){

this.filas=Integer.parseInt(alto.getText());
this.columnas=Integer.parseInt(ancho.getText());
eligePosiciones();

this.panelBienvenida.removeAll();
this.paintAll(this.getGraphics());
setSize(900,600);

setVisible(true);

}

// recorro para saber que boton es seleccionado y guardo su texto
for (int i = 0; i < filas; i++) {
for (int j = 0; j < columnas; j++) {
if(e.getSource().equals(botones[i][j])){
String [] pos = botones[i][j].getText().split(":");
System.out.println("separo la fila: "+pos[0]+"y la columna"+pos[1]);
}
}
}
}


}
__________________
Videos Graciosos