import java.awt.*;
import javax.swing.*;
public class mymemory extends JFrame
{
private ImageIcon image1;
private ImageIcon image2;
private ImageIcon image3;
private ImageIcon image4;
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JLabel label4;
mymemory() {
setLayout(new FlowLayout());
image1 = new ImageIcon(getClass().getResource("b1.png"));
label1 = new JLabel(image1);
add(label1);
image2 = new ImageIcon(getClass().getResource("b2.png"));
label2 = new JLabel(image2);
add(label2);
image3 = new ImageIcon(getClass().getResource("b3.png"));
label3 = new JLabel(image3);
add(label3);
image4 = new ImageIcon(getClass().getResource("b4.png"));
label4 = new JLabel(image4);
add(label4);
}
public static void main(String args[]) {
mymemory memory = new mymemory();
memory.setTitle("Test Window");
memory.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
memory.setVisible(true);
memory.pack();
}
}
Neben dem FlowLayout hab ich ja auch noch das GridLayout erwähnt, damit kannst du ein 3x3 Grid erzeugen in dem deine Bilder dann angezeigt werden.