import javax.swing.*;
import java.awt.*;
import java.awt.event.*;class MyFrame extends JFrame implements ActionListener{
JLabel label;JButton button;
Icon andian,liangdian;
MyFrame(){
setSize(400,300);
getContentPane().setLayout(new FlowLayout());
andian=new ImageIcon("andian.jpg");
liangdian=new ImageIcon("liangdian.jpg");
label=new JLabel(andian);
button=new JButton("确定");
getContentPane().add(label);
getContentPane().add(button);
button.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button){
for(int i=1;i<=10;i++){
try{
label.setIcon(liangdian);
Thread.sleep(50);
label.setIcon(andian);
Thread.sleep(50);
}
catch(InterruptedException e1){}
}
}
}
}public class Cc{
public static void main(String args[]){
new MyFrame();
}
}//JLabel不能像Label那样循环中运行一次就显示一次结果,一定要全部运行完只显示最后结果的吗?
//如何才能在JLabel中显示出闪的效果?
import java.awt.*;
import java.awt.event.*;class MyFrame extends JFrame implements ActionListener{
JLabel label;JButton button;
Icon andian,liangdian;
MyFrame(){
setSize(400,300);
getContentPane().setLayout(new FlowLayout());
andian=new ImageIcon("andian.jpg");
liangdian=new ImageIcon("liangdian.jpg");
label=new JLabel(andian);
button=new JButton("确定");
getContentPane().add(label);
getContentPane().add(button);
button.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button){
for(int i=1;i<=10;i++){
try{
label.setIcon(liangdian);
Thread.sleep(50);
label.setIcon(andian);
Thread.sleep(50);
}
catch(InterruptedException e1){}
}
}
}
}public class Cc{
public static void main(String args[]){
new MyFrame();
}
}//JLabel不能像Label那样循环中运行一次就显示一次结果,一定要全部运行完只显示最后结果的吗?
//如何才能在JLabel中显示出闪的效果?
public void run(){
for(int i=1;i<=10;i++){
try{
label.setIcon(liangdian);
Thread.sleep(50);
label.setIcon(andian);
Thread.sleep(50);
}
catch(InterruptedException e1){}
}
}
}.start();
能不能写下完整的例子程序?我是新手!
你这样写我有点看不大懂!!!不知道如何去完成你写的其他部分.
先谢谢了!!!
import java.awt.*;
import java.awt.event.*;class MyFrame extends JFrame implements ActionListener{
JLabel label;JButton button;
Icon andian,liangdian;
MyFrame(){
setSize(400,300);
getContentPane().setLayout(new FlowLayout());
andian=new ImageIcon("andian.jpg");
liangdian=new ImageIcon("liangdian.jpg");
label=new JLabel(andian);
button=new JButton("确定");
getContentPane().add(label);
getContentPane().add(button);
button.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button){
new Thread(){
public void run(){
for(int i=1;i<=10;i++){
try{
label.setIcon(liangdian);
Thread.sleep(50);
label.setIcon(andian);
Thread.sleep(50);
}
catch(InterruptedException e1){}
}
}
}.start();
}
}public class Cc{
public static void main(String args[]){
new MyFrame();
}
}