问题 问答题

请完成下列Java程序;实现JComboBox,包含3个选项,分别是java、c++、vb,以及1个文本区,用于显示选择结果。 注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。 源程序文件代码清单如下: import java.awt.event.*; import javax.swing.*; import java.awt.*; public class ex14_2 extends JFrame implements ItemListener { BorderLayout bLay = new BorderLayout(); JTextField jtf = new JTextField(27); JComboBox jcb = new JComboBox(); public ex14_2() { super ("ex14_2");//调用当前类ex14_2的父类JFrame的构造方法。 jcb.addItemListener(this); jcb.addItem("java"); jcb.addItem("c++"); jcb.addItem("vb"); jcb.setEditable(false); jtf.setHorizontalAlignment(SwingConstants.CENTER); jtf.setEditable(false); JPanel jp = new JPanel(); jp.setLayout(bLay); jp.add(jtf, "South"); jp.add(jcb, "Center"); setContentPane(jp); } public static void main(String[] args) { JFrame frame = new ex14_2(); frame.pack(); frame.setVisible(true); } public void itemStateChahged(ItemEvent ie) { Object o = if (o == job){ Object newO; ______; jtf.setText(newO.toString()+"被选中!"); } repaint(); } }

答案

参考答案:

解析:ie.getSource()newO=ie.getItem() 本题主要考查用swing进行图形用户界面开发。解题关键是熟悉JTextField和JComboBox等构件的使用方法,以及事件处理机制,掌握在swing环境下的ItemListener监听器的使用方法。本题中,第1个空,ItemEvent类的 ie对象调用getSource()方法获得发生事件的对象o:第2个空,ie调用getItem()方法获得选项的对象,并写给新的对象new()。

阅读理解

阅读下面短文, 请根据短文后的要求进行答题。(请注意问题后的字数要求)

[1]Everybody is familiar with Christmas music; its played everywhere. Whether it's the music from a grocery store or random(随机的)songs on the radio, holiday music remains to flood in the air from the day after Thanksgiving to the beginning of December. Christmas music gets extremely over- played through the Holiday season. “'I think the common seasonal Christmas music is annoying because it keeps being played over and over.”said junior Devin McFarland.

[2]The Christmas music still played today is what she heard in her childhood. Some famous Christmas songs have never been changed. The original music is played so much that in some cases people dream about or even sing Christmas music__________. She wishes that there was a wider variety of songs. She likes the newer Christmas songs that bands either re- make or write themselves. "They have a fresher sound to Christmas songs, and they add their own characteristics to them so that they are more like their own songs. ” McFarland explained.

[3]Christmas is known as a happy and homecoming festival, so the holiday season is meant to be spent happily with your family. It is recognized that the music media wants to get the point across and add to the festival atmosphere. But isn't the music being pushed to the public too much?

[4]Most grocery stores play the music non-stop ,Christmas song after Christmas song, disgusting the customers who don't like that kind of music. You can walk through stores and attempt turning off the music, but sometimes it's impossible to do so. On the other hand, almost everyone has witnessed random persons walking along happily and either singing or whistling to the tune of the song that's played throughout the store.

小题1:What is the main idea of the passage? (no more than 10 words)

小题2:Why is the common seasonal Christmas music annoying? (no more than 8 words)

小题3:What does the music media hope to tell the public?

小题4:Fill in the blank in Paragraph 2 with proper words.(no more than 3 words)

小题5:What does the word “them” (Line 6 Paragraph 2) probably refer to? (no more than 4 words)

问答题