import javax.swing.*; import java.awt.*; import java.awt.event.*; class Hilsevindu{ public static void main(String[] args){ try{ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch(Exception e){ System.exit(1);} JFrame vindu = new JFrame("Hilsevindu"); vindu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JLabel tekstfelt = new JLabel(""); JButton knapp = new JButton("Hilseknapp"); panel.add(tekstfelt); panel.add(knapp); vindu.add(panel); knapp.addActionListener(new ActionListener(){ private boolean hilst = false; @Override public void actionPerformed (ActionEvent e){ if (!hilst) { tekstfelt.setText("Hei p? deg"); hilst = true; } else { tekstfelt.setText("Ha det bra!"); hilst = false; } } }); vindu.pack(); vindu.setLocationRelativeTo(null); vindu.setVisible(true); } }