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