java程序运行之后,不能显示图片,图片已经放在src中了。
importjava.applet.*;importjava.awt.*;importjava.awt.event.*;publicclassTestextendsApp...
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends Applet{
Image upImage;
final int WIDTH = 17;
private static final long serialVersionUID = 1L;
public void inint(){
upImage = getImage(getDocumentBase(), "img/up.gif");
MediaTracker mediaTracker = new MediaTracker(this);
mediaTracker.addImage(upImage, 0);
try
{
mediaTracker.waitForID(0);
}
catch(Exception e)
{
System.out.println("m_ImgUp is not loaded right");
}
}
public void paint(Graphics g) {
for(int i = 0; i < 14; i++) {
g.drawImage(upImage,i * WIDTH, 0, this);
}
}
public static void main(String[] args) {
Frame frame=new Frame();
Test test=new Test();
frame.add(test);
Dimension dimension=new Dimension(40,200);
frame.setSize(dimension);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.setVisible(true);
frame.repaint();
}
} 展开
import java.awt.*;
import java.awt.event.*;
public class Test extends Applet{
Image upImage;
final int WIDTH = 17;
private static final long serialVersionUID = 1L;
public void inint(){
upImage = getImage(getDocumentBase(), "img/up.gif");
MediaTracker mediaTracker = new MediaTracker(this);
mediaTracker.addImage(upImage, 0);
try
{
mediaTracker.waitForID(0);
}
catch(Exception e)
{
System.out.println("m_ImgUp is not loaded right");
}
}
public void paint(Graphics g) {
for(int i = 0; i < 14; i++) {
g.drawImage(upImage,i * WIDTH, 0, this);
}
}
public static void main(String[] args) {
Frame frame=new Frame();
Test test=new Test();
frame.add(test);
Dimension dimension=new Dimension(40,200);
frame.setSize(dimension);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.setVisible(true);
frame.repaint();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询