黑马程序员技术交流社区
标题:
写程序写的很累的兄弟进来休息一下
[打印本页]
作者:
吴亨
时间:
2011-12-22 22:42
标题:
写程序写的很累的兄弟进来休息一下
本帖最后由 吴亨 于 2011-12-23 11:22 编辑
这是我编的一个美女写真集的小程序,不是什么了不去的东西,就是给大家枯燥的编程日子一点趣味。
import java.awt.*;
import java.awt.event.*;
class photoAlbum extends Frame
{
Panel panelPicture = new Panel();
Panel panelControl = new Panel();
CardLayout ca = new CardLayout();
public photoAlbum()
{
setSize(1000,700);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
}
}
);
class MyActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("privew"))
ca.previous(panelPicture);
else if(e.getActionCommand().equals("next"))
ca.next(panelPicture);
else if(e.getActionCommand().equals("First"))
ca.show(panelPicture,"1");
else
ca.show(panelPicture,"5");
}
}
class MyCanvas extends Canvas
{
Image img;
public void paint(Graphics g)
{
if(img == null)
System.out.println("hi");
else
{
g.drawImage(this.img,110,110,this);
}
}
public MyCanvas(Image img)
{
this.img = img;
}
}
add(panelPicture,"Center");
add(panelControl,"South");
panelPicture.setLayout(ca);
MyCanvas mc1 = new MyCanvas(this.getToolkit().getImage("Material\\photoAlbum\\001_jpg_Thumbnail1.jpg"));
//mc1.setImage(mc1.getToolkit().getImage("Thumbnail.jpg"));
MyCanvas mc2 = new MyCanvas(this.getToolkit().getImage("Material\\photoAlbum\\005_jpg_Thumbnail1.jpg"));
//mc1.setImage(mc2.getToolkit().getImage("Thumbnail.jpg"));
MyCanvas mc3 = new MyCanvas(this.getToolkit().getImage("Material\\photoAlbum\\008_jpg_Thumbnail1.jpg"));
// mc1.setImage(mc3.getToolkit().getImage("Thumbnail.jpg"));
MyCanvas mc4 = new MyCanvas(this.getToolkit().getImage("Material\\photoAlbum\\019_jpg_Thumbnail1.jpg"));
//mc1.setImage(mc4.getToolkit().getImage("Thumbnail.jpg"));
MyCanvas mc5 = new MyCanvas(this.getToolkit().getImage("Material\\photoAlbum\\020_jpg_Thumbnail1.jpg"));
// mc1.setImage(mc5.getToolkit().getImage("picture.jpg"));
panelPicture.add(mc1,"1");
panelPicture.add(mc2,"2");
panelPicture.add(mc3,"3");
panelPicture.add(mc4,"4");
panelPicture.add(mc5,"5");
panelControl.setLayout(new GridLayout(1,4));
Button btnPrivew = new Button("privew");
Button btnNext = new Button("next");
Button btnFirst = new Button("First");
Button btnLast = new Button("Last");
btnPrivew.addActionListener(new MyActionListener());
btnNext.addActionListener(new MyActionListener());
btnFirst.addActionListener(new MyActionListener());
btnLast.addActionListener(new MyActionListener());
panelControl.add(btnPrivew);
panelControl.add(btnNext);
panelControl.add(btnFirst);
panelControl.add(btnLast);
}
public static void main(String[] args) {
photoAlbum mw = new photoAlbum();
}
}
还有附件,里面有图片源文件,大家可以在自己的电脑上运行,感觉编程也挺有意思啊。
photoAlbum.rar
(748.27 KB, 下载次数: 223)
2011-12-22 22:45 上传
点击文件名下载附件
源文件
作者:
许庭洲
时间:
2012-8-30 14:21
本帖最后由 许庭洲 于 2012-8-30 14:23 编辑
{:soso__15304029185317794188_2:}{:soso__15304029185317794188_2:}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2