Java AWT List example program: This simple source code is to create a list which is used to perform an usual functions. This program can be designed with the use of list and button class functions. This project is used by various degree students like engineering, MCA & all kind of IT professionals. A tutorial code is given below.
LISTS IN JAVA AWT
This Java AWT tutorial is used to list all the ordered values make the user to find the list of values by indexed as a list position. And it will order the values by sort using date or name. We can Add and remove the list items.
Java AWT List Tutorial:
Q: How to use List in Java AWT? Explain with an example.
//Import statements import java.awt.*; import java.awt.event.*; //Class definition class Lists extends Frame implements ActionListener { List la1,la2; Button bu1, bu2, bu3, bu4; public Lists(String title) { super(title); // © http://students3k.com – Karthikh Venkat setLayout(new FlowLayout()); la1=new List(5); la2=new List(5); bu1=new Button("Add"); bu2=new Button("Add All"); bu3=new Button("Remove"); bu4=new Button("Remove All"); bu1.addActionListener(this); bu2.addActionListener(this); bu3.addActionListener(this); bu4.addActionListener(this); add(la1); add(la2); add(bu1); add(bu2); add(bu3); add(bu4); la1.addItem("Apple"); la1.addItem("Orange"); la1.addItem("Grapes"); la1.addItem("Pine Apple"); la1.addItem("Banana"); validate(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==bu1){ la2.addItem(la1.getSelectedItem()); la1.delItem(la1.getSelectedIndex()); } else if(e.getSource()==bu3) { la1.addItem(la2.getSelectedItem()); la2.delItem(la2.getSelectedIndex()); // © http://students3k.com – Karthikh Venkat } else if(e.getSource()==b2) { for(int i=0;i<l1.getItemCount();i++) { la1.select(i); la2.addItem(la1.getSelectedItem()); } la1.clear(); } else if(e.getSource()==b4) { for(int i=0;i<l2.getItemCount();i++) { la2.select(i); la1.addItem(la2.getSelectedItem()); } la2.clear(); } // © http://students3k.com – Karthikh Venkat } public static void main(String args[]) { Lists s=new Lists("List Manipulation"); s.setSize(300,200); s.setVisible(true); } }
[Useful: Learn English Quickly] & [Career Guidance for All]