Checkbox

2 respostas
D

Oi pessoal, gostaria de saber para q serve o Checkbox…

Obrigada… :smiley:

2 Respostas

F

checkbox eh um componente GUI q tem dois estados, marcado ou desmarcado… as checkbox sao iguais a essas caixinhas q vc pode marcar q ficam do lado as opcoes como “Desativar HTML nesta mensagem” qndo vc vai responder um topico

M

e ai segue um exemplo:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JCheckBoxTest extends JFrame {

   private JTextField field;
   private JCheckBox bold, italic;

   public JCheckBoxTest()
   {
      super( "JCheckBox Test" );

      Container box = getContentPane();
      box.setLayout( new FlowLayout() );

      field = new JTextField( "Isso eh um teste para exemplo", 20 );
      // field.setFont( new Font( "Serif", Font.PLAIN, 14 ) );
      box.add( field );

      bold = new JCheckBox( "Bold" );
      box.add( bold );

      italic = new JCheckBox( "Italic" );
      box.add( italic );

      Handler h = new Handler();
      bold.addItemListener( h );
      italic.addItemListener( h );

      setSize( 275, 100 );
      setVisible( true );
   }

   private class Handler implements ItemListener {

      private int valBold = Font.PLAIN;
      private int valItalic = Font.PLAIN;

      public void itemStateChanged( ItemEvent e )
      {
         if ( e.getSource() == bold )
            if ( e.getStateChange() == ItemEvent.SELECTED )
               valBold = Font.BOLD;
            else
               valBold = Font.PLAIN;

         else
            if ( e.getStateChange() == ItemEvent.SELECTED )
               valItalic = Font.ITALIC;
            else
               valItalic = Font.PLAIN;

         field.setFont( new Font( "", valBold + valItalic, 12 ) );
      }

   }

   public static void main( String args[] )
   {
      JCheckBoxTest win = new JCheckBoxTest();

      win.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
   }

}
Criado 17 de maio de 2004
Ultima resposta 18 de mai. de 2004
Respostas 2
Participantes 3