Advertisement
janevim

Radio Button

Feb 7th, 2023 (edited)
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.60 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.time.LocalDate;
  5. import java.time.LocalDateTime;
  6. import java.time.LocalTime;
  7.  
  8. public class RadioGUI extends JFrame {
  9.     ButtonGroup group = new ButtonGroup();
  10.     private JTextArea textArea1;
  11.     private JPanel panelMain;
  12.     private JCheckBox checkBox1;
  13.     private JRadioButton povinnéRadioButton;
  14.     private JRadioButton nepovinnéRadioButton;
  15.     private JButton pridejButton;
  16.  
  17.  
  18.  
  19.     public RadioGUI() {
  20.         group.add(povinnéRadioButton);
  21.         group.add(nepovinnéRadioButton);
  22.  
  23.         pridejButton.addActionListener(new ActionListener() {
  24.             @Override
  25.             public void actionPerformed(ActionEvent e) {
  26.                 textArea1.append(String.valueOf(LocalDate.now()+ " " + LocalTime.now()+" "));
  27.                 if(checkBox1.isSelected()){
  28.                     textArea1.append("Splněno");
  29.                 }
  30.                 else {
  31.                     textArea1.append("Nesplněno");
  32.                 }
  33.                 if(povinnéRadioButton.isSelected()){
  34.                     textArea1.append("(povinné)\n");
  35.                 }
  36.                 else{
  37.                     textArea1.append("(nepovinné)\n");
  38.                 }
  39.             }
  40.         });
  41.     }
  42.  
  43.     public static void main(String[] args) {
  44.         RadioGUI gui = new RadioGUI();
  45.         gui.setVisible(true);
  46.         gui.setContentPane(gui.panelMain);
  47.         gui.setTitle("úkoly");
  48.         gui.setSize(800, 450);
  49.         gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  50.  
  51.     }
  52. }
  53.  
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement