开发者

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

开发者 https://www.devze.com 2023-02-15 00:07 出处:网络
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.

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

精彩评论

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