Re: Animated Gif help
Author: noah.w
In Reply To: Animated Gif help
Mar 24, 2002 2:11 AM ?
Reply 20 of 22Try this:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
public class AnimS extends JFrame
{
Image img;
ImageIcon org = new ImageIcon("search2.gif");
JLabel jl;
JButton bt;
public AnimS()
{
super();
getContentPane().setLayout(null);
setBounds(6,6,540,440);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent ev)
{
dispose();
System.exit(0);
}}); jl = new JLabel(org);
jl.setBounds(30,30,32,32);
getContentPane().add(jl);
bt = new JButton("Click to stop");
bt.setBounds(130,30,160,24);
getContentPane().add(bt); bt.addActionListener(new ActionListener()
{ public void actionPerformed( ActionEvent e )
{
if (jl.getIcon() == org)
{
img = jl.createImage(32,32);
jl.printAll(img.getGraphics());
jl.setIcon(new ImageIcon(img));
bt.setText("Click to start");
}
else
{
bt.setText("Click to stop");
(jl.setIcon(org));
}
}
});
setVisible(true);
}
public static void main (String[] args)
{
new AnimS();
}
}
Noah
Author: noah.w
In Reply To: Animated Gif help
Mar 24, 2002 2:11 AM ?
Reply 20 of 22Try this:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
public class AnimS extends JFrame
{
Image img;
ImageIcon org = new ImageIcon("search2.gif");
JLabel jl;
JButton bt;
public AnimS()
{
super();
getContentPane().setLayout(null);
setBounds(6,6,540,440);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent ev)
{
dispose();
System.exit(0);
}}); jl = new JLabel(org);
jl.setBounds(30,30,32,32);
getContentPane().add(jl);
bt = new JButton("Click to stop");
bt.setBounds(130,30,160,24);
getContentPane().add(bt); bt.addActionListener(new ActionListener()
{ public void actionPerformed( ActionEvent e )
{
if (jl.getIcon() == org)
{
img = jl.createImage(32,32);
jl.printAll(img.getGraphics());
jl.setIcon(new ImageIcon(img));
bt.setText("Click to start");
}
else
{
bt.setText("Click to stop");
(jl.setIcon(org));
}
}
});
setVisible(true);
}
public static void main (String[] args)
{
new AnimS();
}
}
Noah
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货