请看这个Java程序及图片存放途径都在这里,看看有没有错,类是中间那个,图片是最后一张
importjava.awt.*;importjavax.swing.*;publicclassddextendsJFrameimplementsRunnable{pri...
import java.awt.*;
import javax.swing.*;
public class dd extends JFrame implements Runnable{
private JLabel car;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run() {
try{
dd frame=new dd();
frame.setVisible(true);
new Thread(frame).start();
}
catch(Exception e){
e.printStackTrace();
}}});}
public dd(){
super();
setResizable(false);
this.setLayout(null);
this.setBounds(100,100,300,78);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon icon=new ImageIcon(getClass().getResource("zixingche.png"));
car.setIcon(icon);
car.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
this.add(car);
}
public void run() {
int width=getWidth();
while(true){
for(int i=0;i<width;i+=3){
try{
Thread.sleep(30);
}
catch(InterruptedException e){
e.printStackTrace();
}
car.setLocation(i, car.getLocation().y);
}
}
}
} 展开
import javax.swing.*;
public class dd extends JFrame implements Runnable{
private JLabel car;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run() {
try{
dd frame=new dd();
frame.setVisible(true);
new Thread(frame).start();
}
catch(Exception e){
e.printStackTrace();
}}});}
public dd(){
super();
setResizable(false);
this.setLayout(null);
this.setBounds(100,100,300,78);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon icon=new ImageIcon(getClass().getResource("zixingche.png"));
car.setIcon(icon);
car.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
this.add(car);
}
public void run() {
int width=getWidth();
while(true){
for(int i=0;i<width;i+=3){
try{
Thread.sleep(30);
}
catch(InterruptedException e){
e.printStackTrace();
}
car.setLocation(i, car.getLocation().y);
}
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询