国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
全國2010年1月自考Java語言程序設計試題(續(xù))

28.以下程序創(chuàng)建了一個窗口,然后在窗口內(nèi)顯示Hello,World! 。

 import javax.swing.*; import javaawt*;

 public class HelloWorld {

     public static void main(String[ ]ares) {

        TextFrame frame=new TextFrame();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

       frame. ________;

     }

 }

 class TextFrame extends JFrame  {

     public TextFrame()  {

         setTitle(HelloWorld);

         setSize(WIDTH,HEIGHT);

         TextPanel panel=new TextPanel()

         Container contentPane=getContentPane();

         contentPaneadd(panel)

     }

     public static final int WIDTH=300;

     public static final int HEIGHT= 200;

 }

 class TextPanel extends JPanel {

    public void paintComponent(Graphics g)  {

         super. ________;

         g.drawString(HelloWorld! ″,x,y);

    }

    public int x=100  public int y=100;

 }

29.以下是子窗口中設置一個菜單條類的定義。類的構(gòu)造方法根據(jù)指定的窗口名稱和菜單表設置菜單條,菜單和菜單項,當選中某個菜單項時,在文本框中顯示相應菜單項被選中的信息。

 class MenuWindow extends JFrame implements ActionListener {

     public static JTextField text;

     public MenuWindow(String sString menuList[][]) {

          setTitle(s);

          Container con=this.getContentPane();

          con.setLayout(new BorderLayout());

          this.setLocation(100100); this.setSize(300100);

          JMenuBar menubar=new JMenuBar();

          for(int i=0; i<menuList.length;i++) {

              JMenu menu=new JMenu(menuList[i][0]);

              for(int j=1;j<menuList[i]1ength;j++){

                  JMenultem anltem=new JMenultem(menuList[i][j]);

                  anltemsetActionCommand(menuList[i][j]);

                  anltem________menu.add(anltem);

              }

              menubar__________

          }

         text=new JTextField();setJMenuBar(menubar)

        con.add(text,BorderLayoutSOUTH);

    }

    public void actionPerformed(ActionEvent e){

         textsetText(egetActionCommand()+″菜單項被選中! )

    }

 }

 public class Test29 extends Applet  {

     MenuWindow window;

     String menuList[][]={{″體育″,″跑步″,″打藍球″,″打乒乓″}

                                  {″娛樂″,″唱歌″,″跳舞″}};

     public void init() {

          window=new MenuWindow(″體育娛樂之窗″,menuList)

          window.setVisible(true);

     }

 }

30.以下是一個用鼠標自由作畫的小應用程序。最簡單的方法是根據(jù)鼠標所在位置畫點,跟隨鼠標的移動,不斷畫圓點,就能實現(xiàn)用鼠標作畫。

 import javaawt.*

 import javaawt.event.*;

 public class Test30 extends javaappletApplet implements MouseMotionListener {

     Color color;int lineSize=2

     int x=-1,y=-l;

     public void init(){

         setLocation(30,20);     setSize(300,300);

         setBackground(Color.green);addMouseMotionListener(this)

     }

     public void paint(Graphics g){

         if(x!=-1&&y!=-1) {

           g.setColor(color);g.fillOval(x,y,1ineSize,lineSize);

         }

     }

     public void mouseMoved(MouseEvent e){}

     public void mouseDragged(MouseEvent e){

         x=e.getX();y=egetY();_________

     }

     public void ________ (Graphics g){     paint(g);}

 }

31.以下定義的類ShareData用于管理多個線程共享數(shù)據(jù)data。一個線程生成data,另一個線程使用data。約定,新生成的data只有被另一個線程使用后,才能生成下一個data。反之,一個data被使用后,也不能再繼續(xù)使用。所以,生成和使用data的線程之間需要互斥和同步。以下是管理上述使用方式的類,類內(nèi)有要管理的共享數(shù)據(jù),以及對共享數(shù)據(jù)的存操作putData()和取操作getData()。

 class ShareData{

 int data;共享數(shù)據(jù)

 boolean newData=false;有最近新生成data的標志

 synchronized int getData(){

     while(!newData){

 try{ _________;

 } catch(InterruptedExceptipn e){

       System.out.println(″因錯誤,而中斷!);

 }

 }

       newData=false; notify()return data;

 }

 synchronized void putData(int n){

 while(newData){

 try{wait()

 }catch(InterruptedException e){

       System.out.println(″因錯誤,而中斷! )

 }

 }

 data=n;    __________;

 notify()   return;

 }

 }

五、程序分析題(本大題共5小題,每小題4分,共20)

32.閱讀下列程序,請寫出該程序的輸出結(jié)果。

 class Parent{

   private void method 1 () {  System.out.println(Parents method 1());}

   public void method 2 () {  System.out.println(Parents method 2());method 1()}

 }

 class Child extends Parent {

   public void method l (){  System.out.println(Childs method 1 ());}

   public static void main(String args[]){  Parent p = new Child()p.method2();}

 }

33.閱讀下列程序,請寫出該程序的功能。

 import java.util.*;import javax.swing.*

 public class Test33{

    public static void main(String args[]){

String str=(String)JOptionPaneshowInputDialog(null,″請輸入信息″,

″輸入對話框″,JOptionPanePLAIN_MESSAGE,nullnull,null)

StringTokenizer pas=new StringTokenizer(str, ″,″)

int n=pas.countTokens();

System.out.println(″輸入的信息有單詞:+n+″個,全部單詞如下:″);

while(pashasMoreTokens()){

String s=pas.nextToken()

System.out.println(s);

}

    }

 )

34.閱讀下列程序,請用示意圖畫出程序運行時呈現(xiàn)的界面。

 import java.applet.*;import java.awt.*import javax.swing.*;

 class MyPanel extends JPanel{

    JTextField textltext2;

    MyPanel(String sl,String s2) {

       textl=new JTextFieId(s1); text2=new JTextField(s2)

       add(text 1);                 add(text2);

    }

 }

 class MySubPanel extends MyPanel {

     JTextField text

     MySubPanel(String sl,String s2,String s3) {

        super(s1s2);text = new JTextField(s3);add(text)

     }

 }

 public class Test34 {

     public static void main(String args[]) {

 JFrame mw=new JFrame(″一個示意窗口″)

 mw.setSize(350,150);

 Container con = mw.getContentPane();

 con.setLayout(new BorderLayout())

 MyPanel pl=new MyPanel(″文本框l″,″文本框2);

 MySubPanel p2=new MySubPanel(″文本框3″,″文本框4″,″文本框5);

 JTextArea text=new JTextArea(″這里是一個文本區(qū)″);

 con.add(pl,″North) con.add(p2,″South)

 con.add(text,″Center)mwsetVisible(true);

    }

 }

本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
最全的Java筆試題庫之選擇題篇-總共234道【1~60】
《Java 程序設計》模擬試題
java學習代碼,分享史上java最牛逼,最簡短的代碼
位運算符
Java第一次作業(yè)
java第一次作業(yè)
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服