Java Check Boxes
A check box is a way to allow your users to select and deselect items. They can be a little fiddly, though, so it's a good idea to add them to a panel. That way, you can move them all at once just by moving the panel.
So add a panel to your form, which can be found under Swing Containers in the NetBeans palette. Now locate the check box control. Drag a check box onto your panel.
Now that you have added one check box to your panel, add three more. Change the text of the three to: Java, PHP, and Visual Basic. Your check boxes will then look like this:
So add a button to your form. Change the variable name to btnCheckBoxes. Change the text on the button to Selected Items.
Locate the Text Area control in the NetBeans palette, and drag one onto your form. Change the variable name to taOne.
When you've aligned your new controls, your form should look something like this:
Java checkboxes have a property called isSelected. We can use this in a series of IF Statements to see if each box is selected or not. If they are, we can build up a string, adding the text from each check box.
Double click your new button to create a code stub. Add the following code:
When you've finished typing the code, run your programme. Select a few check boxes and then click the button. You should find that the items you checked appear in the text area:
Deselect a box or two and try again. Only the boxes selected should appear in the text area.
Comments
Post a Comment