checkBox
Hola
Me gustarÃa saber como puedo capturar un evento para un checkBox, vamos si tengo que usar un actionListener como para los botones o algo asi.
Un saludo
Me gustarÃa saber como puedo capturar un evento para un checkBox, vamos si tengo que usar un actionListener como para los botones o algo asi.
Un saludo
asà es, si agregas un ActionListener al JComboBox, cuando éste cambie se dispara la acción. Aqui va un pequeño ejemplo:
import javax.swing.*;
import java.awt.event.*;
public class Prueba extends JFrame
{
JTextArea t = new JTextArea();
JCkeckBox c = new JCheckBox("Check me");
public Prueba()
{
super("Prueba");
setDefaultCloseIOperation(EXIT_ON_CLOSE);
getContentPane().add(t, BorderLayout.CENTER);
getContentPane().add(c, BorderLayout.SOUTH);
c.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
t.append(c.isSelected() ? "Checkbox selectedn" : "Checkbox unselectedn");
}
});
setSize(400, 300);
setVisible(true);
}
public static void main(String[] args)
{
new Prueba();
}
}
import javax.swing.*;
import java.awt.event.*;
public class Prueba extends JFrame
{
JTextArea t = new JTextArea();
JCkeckBox c = new JCheckBox("Check me");
public Prueba()
{
super("Prueba");
setDefaultCloseIOperation(EXIT_ON_CLOSE);
getContentPane().add(t, BorderLayout.CENTER);
getContentPane().add(c, BorderLayout.SOUTH);
c.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
t.append(c.isSelected() ? "Checkbox selectedn" : "Checkbox unselectedn");
}
});
setSize(400, 300);
setVisible(true);
}
public static void main(String[] args)
{
new Prueba();
}
}
