这个调试通过不了,帮忙看看
import java.awt.*;import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
class MyPanel extends JPanel{
int x;JLabel label;
MyPanel(int a){
x=a;getSize();
label=new JLabel("我是第"+x+"个标签");
add(label);
}
public Dimension getPreferredSize()
{return new Dimension(200,50);}
}
public class Example extends Applet implements Actionlistener{
CardLayout mycard;MyPanel myPanel[];JPanel p;
private void addButton(JPanel pan,String butName,ActionListener listener) {
JButton aButton= new JButton(butName);
aButton.setActionCommand(butName);
aButton.addActionListener(listener);
pan.add(aButton);
}
public void init() {
setLayout(new BorderLayout());
mycard=new CardLayout();
this.setSize(400,150);
p=new JPanel();p.setLayout(mycard);
myPanel = new MyPanel[10];
for(int i=0;i<10;i++) {
myPanel[i]=new MyPanel(i+1);
p.add("A"+i,myPanel[i]);
}
JPanel p2= new JPanel();
addButton(p2,"第一个",this);
addButton(p2,"最后一个",this);
addButton(p2,"前一个",this);
addButton(p2,"后一个",this);
add(p,"Center");add(p2,"South");
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("第一个"))mycard.first(p);
else if(e.getActionCommand().equals("最后一个"))mycard.last(p);
else if(e.getActionCommand().equals("前一个"))mycard.previous(p);
else if(e.getActionCommand().equals("后一个"))mycard.next(p);
}
}