多选题import java.awt.*;   public class X extends Frame {   public static void main (String args) {   X x = new X();   x.pack();   x.setVisible(true);   }  public X() {   setLayout (new BordrLayout());   Panel p = new Panel ();   add(p, BorderLayout.NORTH); 

题目
多选题
import java.awt.*;   public class X extends Frame {   public static void main (String args) {   X x = new X();   x.pack();   x.setVisible(true);   }  public X() {   setLayout (new BordrLayout());   Panel p = new Panel ();   add(p, BorderLayout.NORTH);   Button b = new Button (“North”);   p.add(b):   Button b = new Button (“South”);   add(b1, BorderLayout.SOUTH):   }   }   Which two statements are true?()
A

The buttons labeled “North” and “South” will have the same width.

B

The buttons labeled “North” and “South” will have the same height.

C

The height of the button labeled “North” can very if the Frame is resized.

D

The height of the button labeled “South” can very if the Frame is resized.

E

The width of the button labeled “North” is constant even if the Frame is resized.

F

The width of the button labeled “South” is constant even if the Frame is resized.


相似考题
更多“多选题import java.awt.*;   public class X extends Frame {   public static void main (String args) {   X x = new X();   x.pack();   x.setVisible(true);   }  public X() {   setLayout (new BordrLayout());   Panel p = new Panel ();   add(p, BorderLayout.NORTH); ”相关问题
  • 第1题:

    下列程序使用CardLayout管理了2张卡片,每张都是一个Panel,每个Panel有一个Button,单击按钮,显示下一张卡片中的内容。请将程序补充完整。

    注意:不改动程序结构,不得增行或删行。

    import java.awt.*;

    import java.awt.event.*;

    public class ex3 implements______

    {

    private Panel p1,p2;

    private Button btn1,btn2;

    private Frame. frm;

    private CardLayout cl;

    public static void main(String[] args)

    {

    ex3 tt=new ex3();

    tt.method();

    }

    public void method()

    {

    Frm=new Frame("CardLayout");

    Cl=new CardLayout();

    btn1=new Button("Card1");

    btn2=new Button("Card2");

    pl=new Panel();

    p2=new Panel();

    p1.add(btn1);

    btn1.addActionListener(this);

    p2.add(btn2);

    ______

    frm.SetLayout(cl);

    frm.add(pl,"Layer1");

    frm.add(pl,"Layer1");

    frm.SetSize{200,200);

    frm.SetVisible(true);

    }

    public void actionPerformed(ActionEvent ae)

    {

    ______

    }

    }


    正确答案:ActionListener btn2.addActionListener(this); cl.previous(frm);
    ActionListener btn2.addActionListener(this); cl.previous(frm); 解析:本题综合考查了对图形用户界面和事件处理的掌握。按钮可以引发动作事件,当用户单击一个按钮时就引发了一个动作事件,希望相应按钮引发的动作事件的程序必须把按钮注册给实现了ActionListener接口的动作事件监听者。因此,第1空应填入的是ActionListener。第2空的功能是将btn2注册给当前的监听者。因此,第2空应填入的是btn2.addActionListener(this);。第3空需要填入的是响应鼠标事件的处理代码,当单击鼠标时,要显示下一张卡片中的内容,则需要调用next(Container parent)或者previous(Container parent)方法。因此,第3空应填入的是cl.next(frm);或cl.previous(frm);。

  • 第2题:

    下列程序在Frame中设定BorderLayout布局管理器,选择正确的语句填入程序的横线处。 import java.awt.*; public class ex43 extends Frame { public static void main(String[] args) { ex43 bj = new ex43("BorderLayout"); ______ obj.add("North", new Button("North")); obj.add("South", new Button("Sourth")); obj.add("East", new Button ("East")); obj.add("West", new Button ("West")); obj. add ("Center", new Button ( "Center" ) ); obj.pack(); obj. setVisible (true); } public ex43(String str) { super (str); } }

    A.obj.setLayout(new BorderLayout());

    B.setLayout(new Borderkayout());

    C.setLayout(BorderLayout());

    D.obj.setLayout(BorderLayout());


    正确答案:A

  • 第3题:

    选择正确的语句填在下列程序的横线处。 import java.awt.*; import java.awt.event.*; public class ex30 { Frame. f; public static void main(String[] args) { ex30 e = new ex30(); e. te st ( ); } public void test() { f = new Frame("ex30"); ______ f.paok(); f.setVisible(true); } class MyWindowListener extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(1); } } }

    A.f.addWindowListener(new MyWindowtistener());

    B.f.addWindowListener(MyWindowListener());

    C.f.addWindowAdapter(new MyWindowListener());

    D.addWindowListener(new MyWindowListener());


    正确答案:A

  • 第4题:

    本题的功能是获取鼠标在窗口中的位置。当鼠标移进窗口中,就会实时显示鼠标在窗口中的相对位置,比如显示为"鼠标的当前位置:X:Y"(其中,X为横坐标,Y为纵坐标)。

    import java.awt.*;

    import java.awt.event.*;

    import java.util.*;

    import javax.swing.*;

    public class java2

    {

    public static void main(String[]args)

    {

    MouseFrame. frame=new MouseFrame();

    frame.setDefaultCloseoperation(JFrame.EXIT_

    0N CLOSE);

    frame.show();

    }

    }

    class MouseFrame. extends JFrame

    {

    public MouseFrame()

    {

    setTitle("java2");

    setSize(WIDTH,HEIGHT);

    MousePanel panel=new MousePanel();

    Container contentPane=getContentPane();

    contentPane.add(panel);

    }

    public static final int WIDTH = 300;

    public static final int HEIGHT=200;

    }

    class MousePanel extends JPanel

    {

    public MousePanel()

    {

    addMouseListener(new MouseHandler());

    addMouseMotionListener(new MouseMotionHan-

    dler());

    }

    public void paintComponent(Graphics g)

    super.paintComponent(g);

    String text="鼠标指针位置:"+mousex+":"

    +mousey;

    g.drawString(text,10,10);

    }

    private int mousex,mousey;

    private class MouseMotionHandler {

    public void mouseMoved(MouseEvent event)

    {

    mousex=event.getX();

    mousey=event.getY();

    repaint();

    }

    public void mouseDragged(MouseEvent event)

    {

    mousex=event.getX();

    mousey=event.getY();

    repaint();

    }

    }

    private class MouseHandler

    {

    public void mousePressed(MouseEvent eveat)

    {mousex=event.getX();

    mousey=event.getY();

    }

    }

    }


    正确答案:
    第1处:implementsMouseMotionListener第2处:extendsMouseAdapter【解析】第1处实现了MouseMotionListener接口鼠标移动事件的监听;第2处是继承MouseAdapter这个抽象类。

  • 第5题:

    以下程序调试结果为:

    public class Test {

    int m=5;

    public void some(int x) {

    m=x;

    }

    public static void main(String args []) {

    new Demo().some(7);

    }

    }

    class Demo extends Test {

    int m=8;

    public void some(int x) {

    super.some(x);

    System.out.println(m);

    }

    }

    A.5

    B.8

    C.7

    D.无任何输出

    E.编译错误


    正确答案:B

  • 第6题:

    现有:  class Top  {     static int X=l;  public Top()  {  x*=3; }     }  class Middle extends Top  {      public  Middle()    {x+=l;  }  public static void main(String  []  args)  {     Middle m=new Middle();    System.out.println (x);    }     }  结果是什么?()    

    • A、  2
    • B、  3
    • C、  4
    • D、编译失败

    正确答案:C

  • 第7题:

    public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()  

    • A、 A done
    • B、 B done
    • C、 A done B done
    • D、 B done A done
    • E、 There is no exception that the application will print anything.
    • F、 The application outputs “A done” and “B done”, in no guaranteed order.

    正确答案:B

  • 第8题:

    class Top {  static int x = 1;  public Top(int y) { x *= 3; }  }  class Middle extends Top {  public Middle() { x += 1; }  public static void main(String [] args) {  Middle m = new Middle();  System.out.println(x);  }  }  结果为:() 

    • A、1
    • B、2
    • C、3
    • D、编译失败

    正确答案:D

  • 第9题:

    public class Starter extends Thread {  private int x= 2;  public static void main(String[] args) throws Exception {  new Starter().makeItSo();  }  public Starter() {  x=5;  start();  }  public void makeItSo() throws Exception {  join();  x=x- 1;  System.out.println(x);  }  public void run() { x *= 2; }  }  What is the output if the main() method is rum?() 

    • A、 4
    • B、 5
    • C、 8
    • D、 9
    • E、 Compilation fails.
    • F、 An exception is thrown at runtime.
    • G、 It is impossible to determine for certain.

    正确答案:D

  • 第10题:

    多选题
    Which are syntactically valid statement at// point x?()     class Person {     private int a;  public int change(int m){  return m;  }     }  public class Teacher extends Person {     public int b;  public static void main(String arg[]){     Person p = new Person();     Teacher t = new Teacher();    int i;  // point x     }    }
    A

    i = m;

    B

    i = b;

    C

    i = p.a;

    D

    i = p.change(30);

    E

    i = t.b.


    正确答案: C,D
    解析: A:m没有被申明过,不能使用。 
    B:虽然b是类Teacher的public成员变量,但是在静态方法中不能使用类中的非静态成员。 
    C://a是类Person的private成员,在类外不能直接引用。 
    D://change(int m)方法是public方法,并且返回一个int型值,可以通过类的实例变量p引用并赋值给一个int型变量。 
    E://b是类Teacher的public成员变量,且是int型,可以通过类的实例变量t引用并赋值给一个int型变量

  • 第11题:

    多选题
    Given the following code, which code fragments, when inserted at the indicated location, will succeed in making the program display a button spanning the whole window area?()   import java.awt.*;   public class Q1e65 {   public static void main(String args[]) {   Window win = new Frame();   Button but = new Button("button");   // insert code fragment here  win.setSize(200, 200);   win.setVisible(true);   }   }
    A

    win.setLayout(new BorderLayout()); win.add(but);

    B

    win.setLayout(new GridLayout(1, 1)); win.add(but);

    C

    win.setLayout(new BorderLayout()); win.add(but, BorderLayout.CENTER);

    D

    win.add(but);

    E

    win.setLayout(new FlowLayout()); win.add(but);


    正确答案: B,D
    解析: 暂无解析

  • 第12题:

    单选题
    Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?()   class A {}   class B extends A {}   class C extends A {}   public class Q3ae4 {   public static void main(String args[]) {   A x = new A();   B y = new B();   C z = new C();   // insert statement here   }   }
    A

    x = y;

    B

    z = x;

    C

    y = (B) x;

    D

    z = (C) y;

    E

    y = (A) y;


    正确答案: E
    解析: 暂无解析

  • 第13题:

    请完善程序(程序文件名:Java_2.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。

    [题目要求]

    在JFrame窗口中,显示一个字符串并保证窗口正常关闭和退出,使程序运行结果如下图所示。

    源程序:

    import javax.swing.*:

    import java.awt.*;

    public class Java_2 {

    public static void main(String[] args) {

    WelcomFrame. frame=new WelcomFrame();

    frame.setDefaultCloseOperation(JFrame. (1) );

    frame.show();

    }

    }

    class WelcomFrame. extends (2) {

    public WelcomFrame() {

    setTitle("Java等级考试");

    (3) (DEFAULT_WIDTH,DEFAULT_HEIGHT);

    WelcomPanel panel=new WelcomPanel();

    Container contentPane=getContentPane();

    contentPane.add(panel);

    }

    public static final int DEFAULT_WIDTH=250;

    public static final int DEFAULT_HEIGHT=100;

    }

    class WelcomPanel extends (4) {

    public void paintComponent(Graphics g) {

    super.paintComponent(g);

    g.drawString("欢迎参加Java等级考试!",MESSAGE_X,MESSAGE_Y);

    }

    public static final int MESSAGE_X=60:

    public static final int MESSAGE_Y=50:

    }


    正确答案:(1)EXIT_ON_CLOSE (2)JFrame (3)setSize (4)Jpanel
    (1)EXIT_ON_CLOSE (2)JFrame. (3)setSize (4)Jpanel 解析:JFrame类的方法public void setDefaultCloseOperation(int operation)——设置用户在此窗体上发起“close”时默认执行的操作。必须指定以下选项之一:
    ?DO_NOTHING_ON_CLOSE(在WindowConstants中定义):不执行任何操作;要求程序在已注册的WindowListener对象的windowClosing方法中处理该操作。
    ?HIDE_ON_CLOSE(在WindowConstants中定义):调用任意已注册的WindowListener对象后自动隐藏该窗体。
    ?DISPOSE_ON_CLOSE(在WindowConstants中定义):调用任意已注册WindowListener的对象后自动隐藏并释放该窗体。
    ?EXIT_ON_CLOSE(在JFrame中定义):使用System exit方法退出应用程序。仅在应用程序中使用。
    由程序以及题目要求可以看出,程序是要创建一个JFrame类的对象,所以WelcomFrame应该是JFrame类的子类。
    通过参数可以看出是JFrame对象的大小,所以应该使用方法setSize。
    由程序以及题目要求可以看出,程序是要创建一个JPanel类的对象,所以WelcomPanel应该是JPanel类的子类。
    [程序解析] 本程序考查JFrame和JPanel的使用。对JFrame设置标题、大小,显示一个字符串并正常关闭。

  • 第14题:

    interface A{

    int x = 0;

    }

    class B{

    int x =1;

    }

    class C extends B implements A {

    public void pX(){

    System.out.println(x);

    }

    public static void main(String[] args) {

    new C().pX();

    }

    }


    正确答案:

     

    错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的

    x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。

    对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可

    以通过A.x 来明确。

  • 第15题:

    请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。

    [题目要求]

    生成下面左边图形界面,单击图中的New按钮,弹出如右图所示的对话框。

    源程序:

    import java.awt.*;

    import java.awt.event.*;

    import javax.swing.*;

    public class Java_3 {

    public static void main(String[] args) {

    MulticastFrame. frame=new MulticastFrame();

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.show();

    }

    }

    class MulticastFrame. extends JFrame. {

    public MulticastFrame() {

    setTitle("MulticastTest");

    setSize(WIDTH,HEIGHT);

    MulticastPanel panel=new MulticastPanel();

    Container contentPane=getContentPane();

    contentPane.add( (1) );

    }

    public static final int WIDTH=300;

    public static final int HEIGHT=200;

    }

    class MulticastPanel extends JPanel }

    public MulticastPanel() {

    JButton newButton=new JButton("New");

    add(newButton);

    ActionListener newListener=new ActionListener() {

    public void actionPerformed(ActionEvent event) {

    makeNewFrame();

    }

    };

    newButton.addActionListener(newListener);

    closeAllButton=new JButton("Close all");

    add(closeAllButton);

    }

    private void makeNewFrame() {

    final BlankFrame. frame=new BlankFrame();

    frame.show();

    ActionListener closeAllListener=new ActionListener() {

    public void actionPerformed(ActionEvent event) {

    frame. (2) (); //使窗口隐藏或消除

    }

    };

    closeAllButton.addActionListener( (3) );

    }

    private JButton closeAllButton;

    }

    Class BlankFrame. extends JFrame. {

    public BlankFrame() {

    (4) ++;

    setTitle("Frame"+counter);

    setSize(WIDTH,HEIGHT);

    setLocation(SPACING*counter,SPACING*counter);

    }

    public static final int WIDTH=200;

    public static final int HEIGHT=150;

    public static final int SPACING=30;

    private static int counter=0;

    }


    正确答案:panel hide closeAllListener counter
    panel hide closeAllListener counter 解析: 通过下面的程序可以看出新的窗口的标题为Frame和数字,数字是自增的,所以自增的变量名称为counter。
    [程序解析] 程序在窗口中用按钮新建窗口,并且可以通过按钮关闭窗口。本程序采用的是swing类,Swing构件和AWT构件不同,Swing构件不能直接添加到顶层容器中,它必须添加到一个Swing顶层容器相关联的内容面板上。对JFrame添加构件有两种方式:①用getContentPane()方法获得JFrame的内容面板,再对其加入构件,Java上机考试中经常采用这种方式,而且也是一个考点。本程序就是采用的这种方法。②建立一个JPanel或JDesktopPane之类的中间容器,把构件添加到容器中,再用setContentPane()方法把该容器置为JFrame的内容面板。

  • 第16题:

    本题使用下拉菜单来控制字体,窗口中有一个标签和一个下拉菜单,当选中下拉菜单中的任一项字体时,标签上字符串的字体就随之改变。

    import java.awt.*;

    import java.awt.event.*;

    import javax.swing.*;

    class ComboBoxFrame. extends JFrame. {

    public ComboBoxFrame(){

    setTitle("java2");

    setSize(300,200);

    addWindowListener(new WindowAdapter(){

    public void windowClosing(WindowEvent e){

    System.exit(0);

    }

    });

    style=new JComboBox():

    style.setEditable(true);

    style.addhem("Serif");

    style.addItem("SansSerif");

    style.addhem("Monospaced");

    style.addhem("Dialog");

    style.addhem("Dialoglnput");

    style.addActionListener(this);

    JPanel p=new JPanel();

    P.add(style);

    getContentPane().add(p,"South");

    panel=new ComboBoxTestPanel();

    getContentPane().add(panel,"Center");

    }

    public void actionPerformed(ActionEvent evt){

    JComboBox source=(JComboBox) ;

    String item=(String)source.getSelectedhem():

    panel.setStyle(item);

    }

    private ComboBoxTestPanel panel;

    private JComboBox style;

    }

    class ComboBoxTestPanel extends JPanel{

    public ComboBoxTestPanel(){

    setStyle("Serif");

    }

    public void setStyle(String s){

    setFont(new Font(S,Font.PLAIN,12));

    repaint();

    }

    public void paintComponent(Graphics g){

    super.paintComponent(g);

    9.drawString("Welcome to China!",0,50);

    }

    }

    public class java2{

    public static void main(String[]args){

    JFrame. frame=new ComboBoxFrame();

    frame.show();

    }

    }


    正确答案:
    第1处:implementsActionListener第2处:evt.getSource()【解析】第1处是实现ActionListener接口,程序中有窗口监听器的注册;第2处返回ActionEvent动作事件的最初发生对象。

  • 第17题:

    Which are syntactically valid statement at// point x?()     class Person {     private int a;  public int change(int m){  return m;  }     }  public class Teacher extends Person {     public int b;  public static void main(String arg[]){     Person p = new Person();     Teacher t = new Teacher();    int i;  // point x     }    } 

    • A、 i = m;
    • B、 i = b;
    • C、 i = p.a;
    • D、 i = p.change(30);
    • E、 i = t.b.

    正确答案:D,E

  • 第18题:

    Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?()   class A {}   class B extends A {}   class C extends A {}   public class Q3ae4 {   public static void main(String args[]) {   A x = new A();   B y = new B();   C z = new C();   // insert statement here   }   } 

    • A、x = y;
    • B、z = x;
    • C、y = (B) x;
    • D、z = (C) y;
    • E、y = (A) y;

    正确答案:C

  • 第19题:

    Given the following code, which code fragments, when inserted at the indicated location, will succeed in making the program display a button spanning the whole window area?()   import java.awt.*;   public class Q1e65 {   public static void main(String args[]) {   Window win = new Frame();   Button but = new Button("button");   // insert code fragment here  win.setSize(200, 200);   win.setVisible(true);   }   }  

    • A、win.setLayout(new BorderLayout()); win.add(but);
    • B、win.setLayout(new GridLayout(1, 1)); win.add(but);
    • C、win.setLayout(new BorderLayout()); win.add(but, BorderLayout.CENTER);
    • D、win.add(but);
    • E、win.setLayout(new FlowLayout()); win.add(but);

    正确答案:A,B,C,D

  • 第20题:

    import java.awt.*;   public class X extends Frame {   public static void main (String args) {   X x = new X();   x.pack();   x.setVisible(true);   }  public X() {   setLayout (new BordrLayout());   Panel p = new Panel ();   add(p, BorderLayout.NORTH);   Button b = new Button (“North”);   p.add(b):   Button b = new Button (“South”);   add(b1, BorderLayout.SOUTH):   }   }   Which two statements are true?()

    • A、 The buttons labeled “North” and “South” will have the same width.
    • B、 The buttons labeled “North” and “South” will have the same height.
    • C、 The height of the button labeled “North” can very if the Frame is resized.
    • D、 The height of the button labeled “South” can very if the Frame is resized.
    • E、 The width of the button labeled “North” is constant even if the Frame is resized.
    • F、 The width of the button labeled “South” is constant even if the Frame is resized.

    正确答案:B,E

  • 第21题:

    import java.awt*;   public class X extends Frame (   public static void main(string args) (  X x = new X ();   X.pack();   x.setVisible(true);  )  public X () (   setlayout (new GridLayout (2,2));   Panel p1 = new panel();    Add(p1);    Button b1= new Button (“One”);    P1.add(b1);   Panel p2 = new panel();    Add(p2);   Button b2= new Button (“Two”);    P2.add(b2);    Button b3= new Button (“Three”);   add(b3);   Button b4= new Button (“Four”);   add(b4);   )   )   Which two statements are true? ()

    • A、 All the buttons change height if the frame height is resized.
    • B、 All the buttons change width if the Frame width is resized.
    • C、 The size of the button labeled “One” is constant even if the Frame is resized.
    • D、 Both width and height of the button labeled “Three” might change if the Frame is resized.

    正确答案:C,D

  • 第22题:

    多选题
    import java.awt.*;   public class X extends Frame {   public static void main (String args) {   X x = new X();   x.pack();   x.setVisible(true);   }  public X() {   setLayout (new BordrLayout());   Panel p = new Panel ();   add(p, BorderLayout.NORTH);   Button b = new Button (“North”);   p.add(b):   Button b = new Button (“South”);   add(b1, BorderLayout.SOUTH):   }   }   Which two statements are true?()
    A

    The buttons labeled “North” and “South” will have the same width.

    B

    The buttons labeled “North” and “South” will have the same height.

    C

    The height of the button labeled “North” can very if the Frame is resized.

    D

    The height of the button labeled “South” can very if the Frame is resized.

    E

    The width of the button labeled “North” is constant even if the Frame is resized.

    F

    The width of the button labeled “South” is constant even if the Frame is resized.


    正确答案: E,F
    解析: 暂无解析

  • 第23题:

    多选题
    import java.awt*;   public class X extends Frame (   public static void main(string args) (  X x = new X ();   X.pack();   x.setVisible(true);  )  public X () (   setlayout (new GridLayout (2,2));   Panel p1 = new panel();    Add(p1);    Button b1= new Button (“One”);    P1.add(b1);   Panel p2 = new panel();    Add(p2);   Button b2= new Button (“Two”);    P2.add(b2);    Button b3= new Button (“Three”);   add(b3);   Button b4= new Button (“Four”);   add(b4);   )   )   Which two statements are true? ()
    A

    All the buttons change height if the frame height is resized.

    B

    All the buttons change width if the Frame width is resized.

    C

    The size of the button labeled “One” is constant even if the Frame is resized.

    D

    Both width and height of the button labeled “Three” might change if the Frame is resized.


    正确答案: A,C
    解析: 暂无解析

  • 第24题:

    单选题
    现有:  class Top  {     static int X=l;  public Top()  {  x*=3; }     }  class Middle extends Top  {      public  Middle()    {x+=l;  }  public static void main(String  []  args)  {     Middle m=new Middle();    System.out.println (x);    }     }  结果是什么?()
    A

      2

    B

      3

    C

      4

    D

    编译失败


    正确答案: B
    解析: 暂无解析