我的这个Java程序为什么不能读取图片
importjava.awt.*;importjavax.swing.*;publicclassBalloonextendsJLabelimplementsRunnabl...
import java.awt.*;
import javax.swing.*;
public class Balloon extends JLabel implements Runnable{
private boolean running=true;
private int i;
private int height;
public Balloon(){
super();
this.height=30;
}
public Balloon(int height) {
super();
this.height=height;
}
public void run(){
while(running){
for(i=height-getHeight();i>0;i-=3){
EventQueue.invokeLater(new Runnable(){
public void run(){
setLocation(getLocation().x,i);
}});
try{
Thread.sleep(getLocation().x%100);}
catch(InterruptedException e){
e.printStackTrace();
} } }}}
import java.awt.*;
import javax.swing.*;
public class MoveLabelDemo extends JFrame{
private Balloon[] ballons;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run(){
try{
MoveLabelDemo frame=new MoveLabelDemo();
frame.setVisible(true);
}
catch(Exception e){
e.printStackTrace();
}}});}
public MoveLabelDemo(){
this.setBounds(100,100,550,600);
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ballons=new Balloon[3];
for(int i=0;i<3;i++){
ballons[i]=new Balloon(getHeight());
this.add(ballons[i]);
ImageIcon icon=new ImageIcon(getClass().getResource("ballon"+(i+1)+".png"));
ballons[i].setIcon(icon);
ballons[i].setLocation(icon.getIconWidth()/3*(i+1)-150,getHeight()-100);
ballons[i].setLocation(icon.getIconWidth(),icon.getIconHeight());
new Thread(ballons[i]).start();}
ImageIcon backIcon=new ImageIcon(getClass().getResource("background.jpg"));
JLabel backLabel=new JLabel(backIcon);
backLabel.setSize(backIcon.getIconWidth(),backIcon.getIconHeight());
backLabel.setLocation(0, 0);
this.add(backLabel);
this.setVisible(true);
}
}
图片路径如下, 展开
import javax.swing.*;
public class Balloon extends JLabel implements Runnable{
private boolean running=true;
private int i;
private int height;
public Balloon(){
super();
this.height=30;
}
public Balloon(int height) {
super();
this.height=height;
}
public void run(){
while(running){
for(i=height-getHeight();i>0;i-=3){
EventQueue.invokeLater(new Runnable(){
public void run(){
setLocation(getLocation().x,i);
}});
try{
Thread.sleep(getLocation().x%100);}
catch(InterruptedException e){
e.printStackTrace();
} } }}}
import java.awt.*;
import javax.swing.*;
public class MoveLabelDemo extends JFrame{
private Balloon[] ballons;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run(){
try{
MoveLabelDemo frame=new MoveLabelDemo();
frame.setVisible(true);
}
catch(Exception e){
e.printStackTrace();
}}});}
public MoveLabelDemo(){
this.setBounds(100,100,550,600);
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ballons=new Balloon[3];
for(int i=0;i<3;i++){
ballons[i]=new Balloon(getHeight());
this.add(ballons[i]);
ImageIcon icon=new ImageIcon(getClass().getResource("ballon"+(i+1)+".png"));
ballons[i].setIcon(icon);
ballons[i].setLocation(icon.getIconWidth()/3*(i+1)-150,getHeight()-100);
ballons[i].setLocation(icon.getIconWidth(),icon.getIconHeight());
new Thread(ballons[i]).start();}
ImageIcon backIcon=new ImageIcon(getClass().getResource("background.jpg"));
JLabel backLabel=new JLabel(backIcon);
backLabel.setSize(backIcon.getIconWidth(),backIcon.getIconHeight());
backLabel.setLocation(0, 0);
this.add(backLabel);
this.setVisible(true);
}
}
图片路径如下, 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询