【发布时间】:2014-03-25 15:54:03
【问题描述】:
我曾尝试用 Java 编写程序,其中包含图像的标签每秒都在移动,但不幸的是,尽管它包含零错误,但代码并未运行。任何人都可以弄清楚发生了什么。代码如下:
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
public class what extends JFrame {
private JPanel panel;
private Random r= new Random();
private JLabel image;
private Random s = new Random();
public what (){
super("Catch him!");
panel = new JPanel();
Icon b = new ImageIcon(getClass().getResource("img.JPG"));
image = new JLabel(b);
panel.add(image);
add(panel,BorderLayout.CENTER);
panel.setBackground(Color.yellow);
panel.add(image);
while(true){
int x = s.nextInt(1000);
int y = s.nextInt(900);
try{
Thread.sleep(1000);
}catch(Exception e){
}
image.setBounds(x, y,200, 200);
}
}
public static void main(String[] args){
what c = new what();
c.setVisible(true);
c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
c.setSize(1920,1080);
}
}
拜托,谁能帮帮我。
【问题讨论】:
-
你得到的输出是什么?
-
程序不会执行任何操作