programming-examples/java/Servlets_Session_Swing_Util/Using ImageIcons in place of JCheckBox.java

29 lines
879 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
Using ImageIcons in place of JCheckBox
public class test extends JFrame implements ActionListener
{
JCheckBox check;
public test()
{
check = new JCheckBox("Test");
check.setIcon(new ImageIcon("one.gif")); //unselected
check.setSelectedIcon(new ImageIcon("two.gif")); //selected
check.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.out.println("check box state"+check.getState());
}
});
getContentPane().add(check);
}
public static void main(String args[])
{
test tes = new test();
tes.setSize(200,200);
tes.setVisible(true);
tes.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}