Nęste |
|
Swing'it! serie, Planche nr. 18 |
![]() |
Ex.: Knap og etiket |
Initialiser knappen:
Initialiser etikette:JButton button = new JButton("I'm a Swing button!"); button.setMnemonic('i'); button.addActionListener(this);
...//where instance variables are declared: private JLabel label; private static String labelPrefix = "Number of button clicks: "; private int numClicks = 0; ...//in GUI initialization code: label = new JLabel(labelPrefix + "0 "); label.setLabelFor(button); ...//in the event handler for button clicks: label.setText(labelPrefix + numClicks);