RE:como dibujar en 2 JPanels?
disculpa, no lo comprendo. Intento y no me funciona. Aca te mando parte del codigo de la clase principal. donde deberia escribir "la tarea gemela"?
gracias, yamil
class PanelA extends JPanel {
PanelA() {
JPanel panelA = new JPanel();
...
}
}
class PanelB extends JPanel {
PanelB() {
JPanel panelB = new JPanel();
...
}
}
public class Principal2 extends Canvas implements Stage {
public BufferStrategy strategy;
private SpriteCache spriteCache;
private ArrayList actors;
public JFrame ventana = new JFrame();
PanelA panelA = new PanelA();
PanelB panelB = new PanelB();
public Principal2() {
spriteCache = new SpriteCache();
setBounds(0,0,Stage.WIDTH,Stage.HEIGHT);
Container contentPane = ventana.getContentPane();
contentPane.add(panelA, BorderLayout.CENTER);
contentPane.add(panelB, BorderLayout.EAST);
ventana.add(this);
ventana.setBounds(0,0,Stage.WIDTH,Stage.HEIGHT);
ventana.pack();
ventana.setVisible(true);
ventana.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
ventana.setResizable(false);
createBufferStrategy(2);
strategy = getBufferStrategy();
}
public void inicioWorld() {
actors = new ArrayList();
for (int i = 0; i < 7; i++){
Cartas c = new Cartas(this);
...
actors.add(c);
}
}
...
public void paintWorld() {
Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0,0,getWidth(),getHeight());
for (int i = 0; i < actors.size(); i++) {
Actor c = (Actor)actors.get(i);
c.paint(g);
}
strategy.show();
}
public SpriteCache getSpriteCache() {
return spriteCache;
}
public void game() {
inicioWorld();
while (isVisible()) {
...
paintWorld();
}
}
public static void main(String[] args) {
Principal2 inv = new Principal2();
inv.game();
}
}