【发布时间】:2012-02-09 22:40:49
【问题描述】:
我正在尝试在“GetImage”类中获取多个图像,并将它们显示在主类中。
谁能告诉我一个例子怎么做?我尝试了一堆其他示例,但由于我有两个课程,它们都不起作用。
这是我试过的一个。
主类:
import java.awt.*;
import hsa.*;
public class Test
{
static Console c;
public void Display()
{
GetImage c = new GetImage();
c.paint(g);
}
public Test()
{
c = new Console ();
}
public static void main (String[] args) throws Exception
{
Test = new Test();
a.Display();
}
}
单独的类:
import java.awt.*;
import hsa.Console;
import java.awt.event.*;
public class GetImage extends Frame
{
Image image;
String imageName = "ImageFileName.jpg";
public void paint (Graphics g)
{
Toolkit tool = Toolkit.getDefaultToolkit ();
image = tool.getImage (imageName);
g.drawImage (image, 30, 30, this); // location of the image
g.drawString (imageName, 100, 50); // location of the name
}
}
【问题讨论】: