Choice Component:
Choice হল পুল-ডাউন উইন্ডো ,যেখানে বিভিন্ন আইটেম যুক্ত করা থাকে । তার মাঝে থেকে যে কোন একটি Select করা যায়।
Choice component এর Choice class এর Choice() constructor এর মাধ্যমে চয়েস ব্যাবহার করা হয়ে থাকে।
এরকম একটি প্রোগ্রাম দেওয়া হলঃ
import java.awt.Choice;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class c8 extends JFrame implements ItemListener{
Choice ch;
c8(){
ch=new Choice();
setLayout(new FlowLayout());
ch.add(“c”);
ch.add(“c++”);
ch.add(“java”);
ch.add(“python”);
ch.add(“Php”);
ch.add(“Ruby”);
add(ch);
ch.addItemListener(this);
}
@Override
public void itemStateChanged(ItemEvent event) {
String msg = “You most Like “;
msg+=ch.getSelectedItem();
JOptionPane.showMessageDialog(c8.this,msg);
}
public static void main(String arg[]){
c8 c=new c8();
c.setVisible(true);
c.setSize(400,400);
c.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}