0% found this document useful (0 votes)
28 views2 pages

Applet

This document discusses how to create combo boxes and check boxes in Java. It shows how to: 1. Create a combo box (also called a choice control) using the Choice class constructor and adding items using the add method. 2. Create check boxes using the Checkbox class, adding them to a frame, and adding item listeners to update a label when their state changes. 3. Set the size and layout of the frame, and make it visible.

Uploaded by

s p chowdhury
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Applet

This document discusses how to create combo boxes and check boxes in Java. It shows how to: 1. Create a combo box (also called a choice control) using the Choice class constructor and adding items using the add method. 2. Create check boxes using the Checkbox class, adding them to a frame, and adding item listeners to update a label when their state changes. 3. Set the size and layout of the frame, and make it visible.

Uploaded by

s p chowdhury
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Combo Box

1.
2. import java.applet.Applet;
3. import java.awt.Choice;
4.
5. /*
6. <applet code="CreateChoiceExample" width=200 height=200>
7. </applet>
8. */
9. public class CreateChoiceExample extends Applet{
10.
11. public void init(){
12.
13. /*
14. * To create a AWT choice control or a combobox, use
15. * Choice()
16. * constructor of AWT Choice class.
17. */
18.
19. Choice language = new Choice();
20.
21. /*
22. * To add items in a choice control or a combobox, use
23. * void add(String item)
24. * method of AWT Choice class.
25. */
26. language.add("Java");
27. language.add("C++");
28. language.add("VB");
29. language.add("Perl");
30.
31. //add choice or combobox
32. add(language);
33.
34. }
35. }

Check Box
1. import java.awt.*;
2. import java.awt.event.*;
3. public class CheckboxExample
4. {
5. CheckboxExample(){
6. Frame f= new Frame("CheckBox Example");
7. final Label label = new Label();
8. label.setAlignment(Label.CENTER);
9. label.setSize(400,100);
10. Checkbox checkbox1 = new Checkbox("C++");
11. checkbox1.setBounds(100,100, 50,50);
12. Checkbox checkbox2 = new Checkbox("Java");
13. checkbox2.setBounds(100,150, 50,50);
14. f.add(checkbox1); f.add(checkbox2); f.add(label);
15. checkbox1.addItemListener(new ItemListener() {
16. public void itemStateChanged(ItemEvent e) {
17. label.setText("C++ Checkbox: "
18. + (e.getStateChange()==1?"checked":"unchecked"));
19. }
20. });
21. checkbox2.addItemListener(new ItemListener() {
22. public void itemStateChanged(ItemEvent e) {
23. label.setText("Java Checkbox: "
24. + (e.getStateChange()==1?"checked":"unchecked"));
25. }
26. });
27. f.setSize(400,400);
28. f.setLayout(null);
29. f.setVisible(true);
30. }
31. public static void main(String args[])
32. {
33. new CheckboxExample();
34. }
35. }

You might also like