-1
我试图在'GetImage'类中获取多个图像,并将它们显示在主类中。存储图像和显示在不同的类
任何人都可以告诉我一个例子怎么做?我尝试了其他一些样品,但他们没有工作,因为我有两个班。
这是我试过的一个。
主要CLSS:
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
}
}