import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class Video extends JFrame{
private JComboBox movieList;
private JLabel label;
private JTextField textField;
private Container container;
private final String movieName[]={"天下无贼","还猪格格","神雕侠驴","仙剑奇侠传"};
private final String moviePrice[]={"1","2","3","4"};
public Video(){
super("出租光碟");
container=getContentPane();
container.setLayout(new FlowLayout());
movieList=new JComboBox(movieName);
movieList.setMaximumRowCount(4);
movieList.addItemListener(
new ItemListener(){
public void ItemStateChanged(ItemEvent event){
if(event.getStateChange()==ItemEvent.SELECTED)
textField.setText(moviePrice[movieList.getSelectedIndex()]);
}
}
);
container.add(new JScrollPane(movieList));
label=new JLabel("Yunnan Uni Videos:");
container.add(label);
textField=new JTextField(20);
textField.setEditable(false);
container.add(textField);
setSize(350,150);
setVisible(true);
}
public static void main(String args[]){
Video test=new Video();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
//编译错误是 ItemListener类 没找到