© 2012 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies
« NS2  Projects »


Java Program To Demonstrate Awt List Control

Algorithm Steps:

Step 1: Write a html applet tag with code set to class name and comment the tag

Step 2: Import all necessary packages and classes

Step 3: Define a class that extends applet and implements action listener

Step 4: Declare two lists fruits and drinks

Step 5: Declare panel, label and string for each list

Step 6: In the init() method, do the following:

           i) Create fruits list with multiple select option set to false and add action listener to it

           ii) Populate the list with various fruit names

          iii) Create label for the fruits prompt to select a fruit

          iv) Create a panel and set the layout of the panel to flow layout then add the list to the panel

          v) Repeat the steps i) to iv) for the drinks list except that list is set with multiple select set to true and populated with various beverage names

          vi) Set the layout of the applet to grid layout with 3 rows and 1 column

         vii) Add the fruit panel and drink panel to the applet

Step 7: In the actionPerformed() method, do the following:

          i) Get the names of the selected drinks and fruits and store them in two Strings

         ii) Repaint the applet

Step 8: In the paint() method, do the following:

         i) Display the strings set in actionPerformed() method

Java Program To Demonstrate Awt List Control

import java.applet.*; import java.awt.*; public class shoplist extends Applet { List slist = new List(8,false); List thelist = new List(10,false); public void init() { fillthelist(); add(thelist); add(new Button(">>>>")); add(slist); add(new Button("Clear")); add(new Label("Select an item")); /* from the list on the left and hit >>>> to place it in the other list"));*/ } public void fillthelist() { thelist.addItem("Coffee"); thelist.addItem("Bananas"); thelist.addItem("Oranges"); thelist.addItem("Pears"); thelist.addItem("Peaches"); thelist.addItem("Tuna"); thelist.addItem("Bread"); thelist.addItem("Milk"); thelist.addItem("Eggs"); thelist.addItem("Butter"); thelist.addItem("Sugar"); thelist.addItem("Cereal"); thelist.addItem("Java Manual"); } public boolean action(Event evt, Object whatAction) { if(!(evt.target instanceof Button)) { return false; } String buttonLabel = (String) whatAction; if (buttonLabel == ">>>>") { slist.addItem(thelist.getSelectedItem()); thelist.delItem(thelist.getSelectedIndex()); return true; } else { slist.clear(); thelist.clear(); fillthelist(); return true; } } }

SAMPLE OUTPUT SCREEN:

 

 
SLogix Student Projects

⇓ Student Projects ⇓
⇑ Student Projects ⇑
bottom