import java.awt.*; import java.awt.event.*; import java.io.*; public class ChoiceFrame extends Frame implements ActionListener, ItemListener { private Button load; private Choice list; Label lbl; public ChoiceFrame(String text) { super(text); addWindowListener(new MyWindowAdapter(this)); setSize(500, 300); load = new Button("Load text File"); list = new Choice(); list.addItemListener(this); lbl = new Label(" "); setLayout(new GridLayout(1, 3)); add(load); add(list); add(lbl); load.addActionListener(this); setVisible(true); } public void actionPerformed(ActionEvent eve) { if(eve.getActionCommand().equals("Load text File")) { try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("new1.txt"))); String str = ""; do { str = br.readLine(); if(!(str == null || str.equals(""))) list.add(str); }while(!(str == null || str.equals(""))); } catch(IOException ioe) { System.out.println("I/O error: " + ioe.getMessage()); } } } public void itemStateChanged(ItemEvent eve) { Choice c = (Choice)eve.getSource(); lbl.setText(c.getSelectedItem()); } public static void main(String args[]) { ChoiceFrame cf = new ChoiceFrame("Form1"); } } class MyWindowAdapter extends WindowAdapter { Frame f; public MyWindowAdapter(Frame f) { this.f = f; } public void windowClosing(WindowEvent e) { f.setVisible(false); } }