document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.awt.FlowLayout;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. import javax.swing.JApplet;
  6. import javax.swing.JButton;
  7. import javax.swing.JCheckBox;
  8. import javax.swing.JLabel;
  9. import javax.swing.JRadioButton;
  10.  
  11. public class Applet2017a extends JApplet implements ActionListener {
  12.     // поля = глобальные переменные
  13.     JButton ok;
  14.     JButton cancel;
  15.     JCheckBox[] checkBox;
  16.     JRadioButton radioButton;
  17.     JLabel label;
  18.    
  19.     {
  20.         // инициализация
  21.         // ключевое слово this - наш апплет
  22.         //this.setLayout(new FlowLayout()); // конкретный способ расположения
  23.         this.setLayout(null); // мы сами будем всё располагать
  24.         ok = new JButton("OK");
  25.         ok.setBounds(10, 10, 90, 40);
  26.         this.add(ok);
  27.         cancel = new JButton("Cancel");
  28.         this.add(cancel);
  29.         checkBox = new JCheckBox[5];
  30.         for (int i = 0; i < checkBox.length; i++) {
  31.             checkBox[i] = new JCheckBox("" + i);
  32.             this.add(checkBox[i]);
  33.             checkBox[i].setBounds(30 * i, 60, 20, 20);
  34.         }
  35.         radioButton = new JRadioButton("radiobutton");
  36.         label = new JLabel("Some text");
  37.         this.add(radioButton);
  38.         this.add(label);
  39.         ok.addActionListener(this);
  40.         cancel.addActionListener(this);
  41.     }
  42.  
  43.     @Override
  44.     public void actionPerformed(ActionEvent e) {
  45.         // работаем с e.getSource()
  46.         if (e.getSource() == ok) {
  47.             label.setText("OK was pressed");
  48.             checkBox[0].setSelected(!checkBox[0].isSelected());
  49.         }
  50.         if (e.getSource() == cancel) {
  51.             label.setText("Cancel was pressed");
  52.         }
  53.     }
  54. }
');