问题 问答题

请完成下列Java程序:用一个边框布局来安排一个工具栏和一个卡片布局。工具栏可浮动,包括两个按钮,一个向前一个向后控制卡片的显示;卡片布局包括3张卡片,分别标识为card1、card2、card3。
注意;请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
源程序代码文件清单如下:
import jav

  • a.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.LineBorder;
    public class ex20_2

    private static CardLayout cl=new CardLayout();
    private static JPanel cp=new JPanel();
    public static void main(String args[])

    JFrame jf=new JFrame();
    jf.setTitle("ex20_2");
    Container c=jf.getContentPane();
    JToolBar jtb=new JToolBar();
    JButton btnNext=new JButton(new Imagelcon("next.gif"));
    JButton btnPre=new JButton(new ImageIcon("back.gif"));
    jt
  • b.add(btnPre);
    jtb.add(btnNext);
    cp.setLayout(c1);
    Dimension dim=new Dimension(150,80);
    cp.setPreferredSize(dim);
    cp.setBorder(new LineBorder(Color.BLACK));
    cp.add(new JLabel("card1",JLabel.CENTER),"card1");
    cp.add(new JLabel("card2",JLabel.CENTER),"card2");
    cp.add(new JLabel("card3",JLabel.CENTER),"card3");
  • c.add(jtb,BorderLayout.NORTH);c.add(cp,BorderLayout.CENTER);
    ActionListener al=new ActionResponse();
    ______;
    ______;
    if.addWindowListener(new WindowAdapter()

    public void windowClosing(WindowEvent we)

    System.exit(0);

    );
    jf.pack();
    jf.setVisible(true);

    static class ActionResponse implements ActionListener

    public void actionPerformed(ActionEvent ae)

    if(ae.getActionCommand().equals("next"))
    c1.next(cp);
    else
    c1.previous(cp);


答案

参考答案:btnNext.addActionListener(al)
btnPre.addActionListener(al)

解析: 本题主要考查工具栏和卡片布局的基本使用方法。解题关键是熟悉工具栏的设计和卡片布局的管理,熟悉事件处理机制,会制作图像按钮,会制作自己的事件监听器类。本题中,第1个空和第2个空都是需要填入注册监听器的语句,这里向前和向后两个按钮共用一个监听器,此监听器对象负责判断和处理相应的操作。

阅读理解

任务型阅读:读下面短文,完成后面的问题

Many students get ill easily. They have to go to hospital and may miss(错过)a lot of classes. What can we do to keep healthy? Here are some tips:

Healthy food. You should eat less fast food but more vegetables and fruit. You’d better drink 500 ml milk every day. Remember to eat breakfast.

Enough exercise. Doing exercise is important. It makes you more athletic. You can play some sports after class or on weekends.

Happy smiles. Smile is a good way to make you healthy. Try to find things that can make you laugh. Remember that smile is the best medicine to cure(治疗)your illness.

Good rest. If you want to get a good grade, you must have a good rest. As a famous saying goes, “Early to bed and early to rise makes a man healthy, wealthy(富有的)and wise(聪明的).

根据短文内容,完成下列任务。

任务一:将划线句子翻译成汉语。

小题1:                                      

任务二:完成下列句子。每空词数不限。

小题2:If you get ill, you have to                     and may                   .

小题3:You can play sports                    or                   .

任务三:回答下列问题。

小题4:How much milk should we drink every day?

                                

小题5:Why is smile important?

                                

判断题