标题:这是CardLayout使用的例子,可是图片怎么弄呢?需要添加路径的么
只看楼主
hu9134
Rank: 1
等 级:新手上路
帖 子:4
专家分:2
注 册:2012-3-25
 问题点数:0 回复次数:0 
这是CardLayout使用的例子,可是图片怎么弄呢?需要添加路径的么
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class CardJButton extends JFrame{
    private CardLayout cl = new CardLayout();
    private Container container = getContentPane();
   
    public CardJButton(){
        JButton button ;
        ActionListener listener = new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                cl.next(container);
               
            }
        };
        setLayout(cl);
        for(int index = 0 ; index < 12 ;index ++){
            button = new JButton(new ImageIcon("image/T"+index+".gif"));
            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, 150);
        frame.setVisible(true);
   
    }

}
搜索更多相关主题的帖子: public 图片 private listener void 
2012-05-14 11:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-367482-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.676095 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved