import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class GUIEksempel {
static int count = 0;
public static void main(String[] args) {
JFrame vindu = new JFrame("Vindu-tekst");
vindu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
vindu.setPreferredSize(new Dimension(500, 300));
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName()
);
} catch (Exception e) {
System.exit(1);
}
JPanel panel = new JPanel();
JLabel tekst = new JLabel("Telling: " + count);
JButton knapp = new JButton("?k teller");
knapp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
count++;
tekst.setText("Telling: " + count);
}
});
panel.add(tekst);
panel.add(knapp);
vindu.add(panel);
vindu.pack();
vindu.setLocationRelativeTo(null);
vindu.setVisible(true);
}
}