ok im making progress now. i understand how to call methods and classes now and i understand the layout. however once i put the different cards into their own methods the buttons won’t work. buttons have to stay separate or am i doing something wrong?
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MegaShot extends Applet implements ActionListener
{
Button playButton;
Panel cardPanel, titleScreen, charSelect;
CardLayout myLayout;
public void init()
{
cardPanel = new Panel();
myLayout = new CardLayout();
cardPanel.setLayout(myLayout);
this.setLayout(new BorderLayout());
this.add(cardPanel, BorderLayout.CENTER);
createTitleScreen(titleScreen,playButton);
createCharSelect(charSelect);
}
public void createTitleScreen(Panel p, Button b)
{
p = new Panel();
b = new Button("Play!");
b.addActionListener(this);
p.add(b);
p.setBackground(Color.blue);
cardPanel.add(p,"title");
}
public void createCharSelect(Panel p)
{
p = new Panel();
p.setBackground(Color.red);
cardPanel.add(p,"select");
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == playButton)
{
myLayout.show(cardPanel,"select");
}
}
}