小子向大哥请教!
import java.awt.*;
import java.awt.event.*;
public class testLayout extends Frame{
Panel b1=new Panel();
Panel b2=new Panel();
CardLayout da=new CardLayout();
public testLayout()
{
b1.setLayout(new GridLayout(3,1));
Button c1=new Button("上一张");
Button c2=new Button("下一张");
Button c3=new Button("最后一张");
b1.add(c1);
b1.add(c2);
b1.add(c3);
this.add(b1,BorderLayout.WEST);
b2.setLayout(da);
b2.add(new Button("one"),"1");
b2.add(new Button("two"),"2");
b2.add(new Button("three"),"3");
b2.add(new Button("four"),"4");
b2.add(new Button("five"),"5");
this.add(b2);
this.setLocation(50,50);
this.setSize(500,500);
this.setVisible(true);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
class MY implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("下一张"))
{
da.next(b2);
}
else if(e.getActionCommand().equals("上一张"))
{
da.previous(b2);
}
else
{
da.last(b2);
}
}
}
MY ma=new MY();
c1.addActionListener(ma);
c2.addActionListener(ma);
c3.addActionListener(ma);
}
public static void main(String[] args) {
// TODO, add your application code
new testLayout();
System.out.println("Hello World!");
}
}
/////////////////////////////////////////////////
现在我想将按钮“ONe”、“two”、“three”、“four”、“fine”换成为五张照片,使之成为一简单的“相册”,请问一下该怎么做?
其中我加载图片的代码为:
Image image=this.getToolkit().getImage("H:\\图片\\001.jpg");
Image image2=this.getToolkit().getImage("H:\\图片\\006.jpg");
。。
public void paint(Graphics g)
{
g.drawImage(image,505,10,this);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货