java 图片浏览器

来源:互联网 发布:淘宝手机壳进货渠道 编辑:程序博客网 时间:2024/05/16 08:42

代码:

packageday526;

importjava.awt.BorderLayout;

importjava.awt.CardLayout;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjavax.swing.Icon;

importjavax.swing.ImageIcon;

importjavax.swing.JButton;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

importjavax.swing.JPanel;

importjavax.swing.Timer;

classTestCardLayout

implementsActionListener{

JPaneljp2=new JPanel();

CardLayoutc1=new CardLayout();

Timert=new Timer(800,this);

publicvoid actionPerformed(ActionEvent ae) {   //此处public 在宿舍用OK  在机房用出现问题 应该去掉 public 则可以用!

Stringcomm =ae.getActionCommand();

if("first".equals(comm)){

c1.first(jp2);

}

elseif("next".equals(comm)){

c1.next(jp2);

}

elseif("previous".equals(comm)){

c1.previous(jp2);

}

elseif("last".equals(comm)){

c1.last(jp2);

}

elseif("play".equals(comm)){

t.start();

}

elseif("stop".equals(comm)){

t.stop();

}

else{//timer

c1.next(jp2);

} }

publicTestCardLayout(){

JFramejf=new JFrame("TestCardLayout");

String []blabel={"first","next","previous","last","play","stop"};

JPaneljp1=new JPanel();

jp2.setLayout(c1);

for(inti=0;i<blabel.length;i++){

JButtonjb=new JButton(blabel[i]);

jp1.add(jb);

jb.addActionListener(this);

}

for(inti=0;i<3;i++){

Iconic=new ImageIcon("f:/图片/"+(i+1)+".jpg");

JLabeljl= new JLabel(ic);

jp2.add(jl,""+i);

}

jf.add(jp2);

jf.add(jp1,BorderLayout.SOUTH);

jf.setSize(800,600);

jf.setLocation(100,80);//

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

publicstatic void main(String[] args) {

TestCardLayoutren=new  TestCardLayout();

}

}

这个Java图片浏览器主要的功能有:

浏览的图片、可以查看选定图片目录下的所有图片、及可选择上一张,下一张、可以自动播放和停止。

......随时修改增加功能, 

原创粉丝点击