求大神指导这个程序怎么调出图片,我是按照书上代码打的
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//使用CardLayout
public class CardJButton extends JFrame{
private CardLayout cl = new CardLayout();
private Container container = getContentPane();
public CardJButton(){
JButton button;
ActionListener listener = new ActionListener(){
public void actionPerformed(ActionEvent e){
cl.next(container); //container必须是内容窗格
}
};
setLayout(cl); // 指定布局管理器
for(int index = 0; index < 12; index++){
button = new JButton(new ImageIcon("images/T.gif" + index));
add(button,Integer.toString(index));
button.addActionListener(listener);
}
}
public static void main(String[] args){
CardJButton frame = new CardJButton();
frame.setTitle("测试 CardLayout");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
坐等大神出现