//Java Swing Example Program 4
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ListEvent implements ListSelectionListener{
private JFrame f;
private JList l;
private JTextField jtf;
private String c[] ={"chennai","Trichy","Kovi"};
public ListEvent(){
f = new JFrame("Button Event");
l = new JList(c);
jtf = new JTextField(20);
}
public void dispFrame(){
f.setLayout(new FlowLayout(FlowLayout.CENTER));
l.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
l.addListSelectionListener(this);
f.add(l);
f.add(jtf);
f.setVisible(true);
f.setSize(300,300);
}
public void valueChanged(ListSelectionEvent ee){
int idx = l.getSelectedIndex();
jtf.setText(c[idx]);
}
public static void main(String arg[]){
ListEvent levent = new ListEvent();
levent.dispFrame();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ListEvent implements ListSelectionListener{
private JFrame f;
private JList l;
private JTextField jtf;
private String c[] ={"chennai","Trichy","Kovi"};
public ListEvent(){
f = new JFrame("Button Event");
l = new JList(c);
jtf = new JTextField(20);
}
public void dispFrame(){
f.setLayout(new FlowLayout(FlowLayout.CENTER));
l.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
l.addListSelectionListener(this);
f.add(l);
f.add(jtf);
f.setVisible(true);
f.setSize(300,300);
}
public void valueChanged(ListSelectionEvent ee){
int idx = l.getSelectedIndex();
jtf.setText(c[idx]);
}
public static void main(String arg[]){
ListEvent levent = new ListEvent();
levent.dispFrame();
}
}
No comments:
Post a Comment