Advertisement
fabioceep

JAVA: Exemplo JCheckBox (PG 293)

Feb 23rd, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package textarea1;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. public class TextArea1 implements ActionListener{
  8.     JCheckBox checagem;
  9.    
  10.     public static void main(String[] args) {
  11.         TextArea1 sistema = new TextArea1();
  12.         sistema.iniciar();
  13.     }
  14.     public void iniciar(){
  15.         JFrame janela = new JFrame();
  16.        
  17.         checagem = new JCheckBox("Sim");
  18.         checagem.addActionListener(this);
  19.  
  20.         janela.getContentPane().add(BorderLayout.CENTER, checagem);
  21.         janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22.        
  23.         janela.setSize(350,300);
  24.         janela.setVisible(true);
  25.     }
  26.  
  27.     @Override
  28.     public void actionPerformed(ActionEvent e) {
  29.         String onOuOff = "Não";
  30.         if(checagem.isSelected()) onOuOff = "Sim";
  31.         System.out.println("Você selecionou o " + onOuOff);
  32.     }
  33.    
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement