Also habe ich dieses Spiel, das ich gerade angefangen habe zu machen und das erste Problem, das ich während der Herstellung des Spiels ist beim Ändern der Panels durch Karte Layout, wenn ich den Prozess es tun zeigt mir, dass es das Objekt instanziiert und es auch macht das Panel zu zeigen, aber auf visuelle gibt es keinen Effekt.Kartenlayout ändert nicht das Panel nach der Verarbeitung
Der Code ist wie folgt:
Original-Klasse
public class Parking_Mania {
public static void main(String []args)throws Exception
{
new GameFrame("Paking Mania");
}
}
Das Spiel Rahmenklasse
public class GameFrame extends JFrame{
public GameFrame(String name)
{
this.setTitle(name);
this.setSize(640,510);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
Frames frame=new Frames();
this.add(frame);
frame.panel.show(frame, "opening");
}
}
Platte, die Frames
public class Frames extends JPanel{
CardLayout panel= new CardLayout();
public Frames()
{
this.setLayout(panel);
System.out.println("hello");
Opening op=new Opening();
nxtframe nf= new nxtframe();
this.add(op, "opening");
this.add(nf, "nt");
}
public void nxtf()
{
panel.show(this, "nt");
}
}
erste Platte ändert
public class Opening extends JPanel{
JButton but=new JButton();
public Opening(){
this.setLayout(null);
this.setBackground(Color.BLACK);
add(but);
but.setText("next frame");
but.setBounds(0, 0, 110, 120);
but.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Frames f=new Frames();
f.nxtf();
}
});
}
public void paint(Graphics g)
{
g.fillRect(110, 120, 110, 120);
}
}
Second-Panel
public class nxtframe extends JPanel{
JButton but=new JButton();
public nxtframe(){
System.out.println("hello");
this.setLayout(null);
add(but);
but.setText("next frame");
but.setBounds(0, 0, 110, 120);
but.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
}
});
}
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
g.fillOval(110, 120, 110, 120);
}
}
PS: Ich habe nicht die Mühe das Hinzufügen von Kommentaren, wie ich es nehme selbsterklärend ist. Seien Sie versichert, wenn Sie mich brauchen, um die Kommentare hinzuzufügen, werde ich sie sofort hinzufügen.
Bitte lesen Sie die Antworten zu beantworten. Fragen Sie nach irgendwelchen Fragen. –
funktioniert ganz gut und gut Vielen Dank für Ihre Hilfe. –