import java.awt.*; import java.awt.event.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.*; class SmileKnapp { public static void main(String[] args) { JFrame vindu = new JFrame("Test"); vindu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); vindu.setMinimumSize(new Dimension(200, 200)); JPanel ruter = new JPanel(); ruter.setLayout(new GridLayout(2,3)); for (int i = 0; i < 6; i++) { Knapp b = new Knapp(i+""); b.initGUI();; ruter.add(b); } vindu.add(ruter); vindu.pack(); vindu.setVisible(true); } static class Knapp extends JButton { class Eventer implements ActionListener { boolean clicked = false; String old = ""; @Override public void actionPerformed(ActionEvent e) { if (clicked) { ((JButton) e.getSource()).setText(old); clicked = false; } else { old = ((JButton) e.getSource()).getText(); ((JButton) e.getSource()).setText(":)"); clicked = true; } } } Knapp(String t){ super(t); } void initGUI() { addActionListener(new Eventer()); } } }