自考

各地资讯
当前位置:考试网 >> 自学考试 >> 模拟试题 >> 工学类 >> Java 语言程序设计(一) >> 文章内容

排行热点

全国2013年10月自考《Java语言程序设计(一)》真题_第5页

来源:考试网 [ 2014年3月24日 ] 【大 中 小】
34.阅读下列程序,请写出该程序的功能。
 import javax.swing.*;  import java.awt.*; import java.awt.event.*;
 public class Test34 {
     public static void main(String[]args){
         ComboBoxDemo myComboBoxGUI = newComboBoxDemo();
     }
 }
 Class ComboBoxDemo extends JFrame implemems ItemListener{
      String CountryList[]={"美国","中国","英国","俄罗斯","韩国","德国"};
      im GoldMedalNumber[]={46,38,29,24,13,11};
      JLabel label;JComboBox Combobox;
      Public ComboBoxDemo(){
          setSize(350,150);
          setTitle("第三十届伦敦奥运会金牌查询");
          Comainer conPane = getContentPane();
          conPane.setLayout(new FlowLayout());
          combobox=new JComboBox(CountryList);
          combobox.addItemListener(this);
          conPane.add(combobox);
          label=new JLabel();   conPane.add(1abel);   this.setVisible(true);
      }
      public void itemStateChanged(ItemEvem e){
          if(e.getS ource()==combobox)
             label.setText(
               String.valueOf(GoldMedalNumber[combobox.getSelectedIndex()]));
     }
 }
35.阅读下列程序,请回答下面的问题:
 (1)两个文本区内分别每次追加何种字符?有多少个?
 (2)两个文本区里面内容的显示速度有何区别?
 import iava.awt.*;import java.applet.*;import javax.swing.*;
 public class Test35 extends Applet{
     JTextArea 1Text,rText;
     public void init() {
         setSize(600,500); setLayout(null);
         1Text=new JTextArea();  rText=new JTextArea();
         lText.setFont(new Font ("Times New Roman",1,40));
         rText.setFont(new Font("Modern",1,40));
         JScrollPane jsp1=new JScrollPane(1Text);
         JScrollPane jsp2=new JScrollPane(rText);
         add(jsp1);      add(jsp2);
         jspl.setBounds(20,20,250,450);    jsp2.setBounds(310,20,200,450);
         (new threadl(1Text,"1")).start();    (new threadl(rText,"2")).start();
     }
 }
 class threadl extends Thread{
     protected JTextArea t;
     String text="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
     public thread1(JTextArea text,String m){      super(m);  t=text; }
     public void run()  {
         while(true){
             String S=" ";
             for(int i=0;i<6;i++){
                 int k;
                 if(getName().equals("1"))
                     k=((int)(Math.random()*100)%26);
                 else
                     k=((int)(Math.random()*100)%10)+26;
                 s+=text.charAt(k); //获取k位置字符
             }
             t.append(s+"\n");
             t.setCaretPosition(t.getText().1ength());//最近输出的内容在文本区中显示
             try{sleep(getName().equals("1")?400:700);}
             catch (InterruptedException e){}
         }
    }
 }
责编:abcwuli1234