开发者

How do I make an Image show up in a Java Swing Applet

How do I make an Image sho开发者_运维问答w up in a Java Swing Applet?


The simplest way is to add it as an Icon to a JLabel that you put on your GUI.

http://download.oracle.com/javase/6/docs/api/javax/swing/JLabel.html#JLabel(javax.swing.Icon)


Here's an outline of what you need

class myApplet extends JApplet {
        private BufferedImage image;

        myApplet() {
            try {
                image = ImageIO.read(new File("insert image path here"));
            } catch (IOException ex) {
                // handle exception...
            }
        }

        @Override
        public void paint(Graphics g) {
            g.drawImage(image, 0, 0, null); 

        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜