package drawingUsingImageIcon; import java.awt.FlowLayout; import javax.swing.*; public class ImageIconDemo extends JFrame{ private ImageIcon icon; public ImageIconDemo() { super("Image Icon Demo"); setVisible(true); setSize(330, 260); JLabel label = new JLabel(); setLayout(new FlowLayout(FlowLayout.CENTER)); label.setSize(270, 200); add(label); setPicture(label, "bruce-lee2.jpg"); JTextField textField = new JTextField(20); textField.setVisible(true); add(textField); } private void setPicture(JLabel label, String fileName) { icon = new ImageIcon(fileName); label.setIcon(icon); } public static void main(String[] args) { ImageIconDemo frame = new ImageIconDemo(); } }
setPicture(label, "bruce-lee2.jpg");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)