当前位置: 代码迷 >> Java相关 >> 图形编程的问题
  详细解决方案

图形编程的问题

热度:274   发布时间:2006-03-25 14:44:00.0
图形编程的问题

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类 没找到

搜索更多相关的解决方案: 图形  

----------------解决方案--------------------------------------------------------

加一个import java.awt.event.*;
就可以了


----------------解决方案--------------------------------------------------------

斑竹 ,说的 我试过了
但仍然有个错误


----------------解决方案--------------------------------------------------------

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.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);
}
}

你的i是大写的,小写就对了。


----------------解决方案--------------------------------------------------------

谢谢班竹, 已经改对了, 就是你说的问题


----------------解决方案--------------------------------------------------------
  相关解决方案