import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class oppgave1 { public static void main(String[] args){ try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { System.exit(1); } JFrame vindu = new JFrame(); JPanel panel = new JPanel(); vindu.add(panel); vindu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(new GridLayout(2,3)); for (int i = 0; i<6; i++){ panel.add(new GridKnapp(""+i)); } vindu.setSize(500, 500); vindu.setLocationRelativeTo(null); vindu.setVisible(true); } private static class GridKnapp extends JButton { private String tall; public GridKnapp(String tall){ super(tall); this.tall = tall; addActionListener(new EndreKnappTekst()); } class EndreKnappTekst implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if(getText().equals(tall)){ setText(":)"); } else { setText(tall); } } } } }