多选题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.


相似考题
参考答案和解析
正确答案: E,F
解析: 暂无解析
更多“import java.awt.*;   public class X extends Frame {   public”相关问题
  • 第1题:

    下列类头定义中,错误的是( )。

    A.class x { .... }

    B.public x extends y { .... }

    C.public class x extends y { .... }

    D.class x extends y implements y1 { .... }


    正确答案:B

  • 第2题:

    请完善程序(程序文件名: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设置标题、大小,显示一个字符串并正常关闭。

  • 第3题:

    下列代码的输出结果是( )。

    class parent

    {

    void printme()

    {

    System.out.println("parent");

    }

    }

    class child extends parent

    {

    void printme()

    {

    System. out.println("child");

    }

    void printall()

    {

    super, printme();

    this.printme();

    printme();

    }

    }

    public class test

    {

    public static void main(String args[])

    {

    child myc=new child();

    myc.printall();

    }

    }

    A.import java.awt.*;

    B.import java.applet.applet;

    C.import java.io.*;

    D.import java, awt.graphics;


    正确答案:A

  • 第4题:

    要下列Java Applet程序完整并能够正确运行,横线处应填人的内容是( )。 import java.applet.*; nmport java.awt.*0 public class HelloWorld{ public void paint(Graphics g){ drawstring("Hello World!",25,25); } }

    A.extends Thread

    B.extends Applet

    C.extends Char

    D.extends Float


    正确答案:B
    B。【解析】本题是考查继承。继承了Applet类。

  • 第5题:

    选择正确的语句填在下列程序的横线处。 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

  • 第6题:

    下面程序构造了一个Swing Applet,在下画线处填入正确的代码。

    import javax.swing.*;

    import java.awt.*;

    public class SwingApplet extends ______ {

    JLabel 1=new JLabel("This is a Swing Applet.");

    public void init() {

    Container contentPane=getContentPane();

    contentPane.add(1);

    }

    }


    正确答案:Japplet
    Japplet

  • 第7题:

    请完善程序(程序文件名: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的内容面板。

  • 第8题:

    本题的功能是获取鼠标在窗口中的位置。当鼠标移进窗口中,就会实时显示鼠标在窗口中的相对位置,比如显示为"鼠标的当前位置: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这个抽象类。

  • 第9题:

    在下列源代码文件Test.java中,哪个选项是正确的类定义? ( )

    A.public class test { public int x=0; public test(int x) { this.x=x; } }

    B.public class Test { public int x=0; public Test(int x) { this.x=x; } }

    C.public class Test extends Ti,T2 { public int x=0; public Test(int x) { this.x=x; } }

    D.protected class Test extends T2 { public int x=0; public Test(int x) { this.x=x; } }


    正确答案:B

  • 第10题:

    下列类的定义中,错误的是()。

    • A、class x{....}
    • B、public x extends y{....}
    • C、public class x extends y{....}
    • D、class x extends y implements y1{....}

    正确答案:B

  • 第11题:

    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()

    • A、 public class Circle implements Shape { private int radius; }
    • B、 public abstract class Circle extends Shape { private int radius; }
    • C、 public class Circle extends Shape { private int radius; public void draw(); }
    • D、 public abstract class Circle implements Shape { private int radius; public void draw(); }
    • E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
    • F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

    正确答案:B,E

  • 第12题:

    多选题
    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.


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

  • 第13题:

    Given:Which two, inserted at line 11, will allow the code to compile?()

    A.public class MinMax<?> {

    B.public class MinMax<? extends Number> {

    C.public class MinMax<N extends Object> {

    D.public class MinMax<N extends Number> {

    E.public class MinMax<? extends Object> {

    F.public class MinMax<N extends Integer> {


    参考答案:D, F

  • 第14题:

    下面程序的输出结果是( )。 import java.awt.*; import java.applet.*; public class HelloApplet extends Applet { public void paint(Graphics g) { g.drawstring("Hello World!", 20, 20); } }

    A.20,20

    B.Hello World!

    C.编译不能通过

    D.以上都不对


    正确答案:B
    解析:本题是考查考生对Java程序的执行过程的理解。这是一个简单的Applet(小应用程序)。程序中,首先,用import语句引入java.awt和java.applet下所有的包,使得该程序可以使用这些包中所定义的类,它类似于C中的#include语句:然后,声明一个公共类HelloApplet,用extends指明它是Applet的子类。在类中,我们重写父类Applet的paint()方法,其中,参数g为Graphics类,它表明当前作图的上下文。在paint()方法中,调用g的方法drawstring(),在坐标(20,20)处输出字符串"HelloWorld!",其中坐标是用像素点来表示的。这个程序中没有实现main()方法,这是Applet与应用程序(Application)的区别之一。为了运行该程序,也要把它放在文件HelloWorldApplet.java中,然后对它进行编译,javacHelloApplet.java得到字节码文件HelloApplet.class。由于Applet中没有main()方法作为Java解释器的入口,我们必须编写HTML文件,把该Applet嵌入其中,然后用appletviewer来运行,或在支持Java的浏览器上运行。它的HTML>文件如下。

  • 第15题:

    下列程序实现了2个监听器接口:ActionListener和W1ndowListener。 import java.awt.*; import java.awt.event.*; public class ex39______ { public static void main(String[] args) { ex39 bj = new ex39(); obj .go(); } public void go() { Frame. f = new Frame("ex39"); f.addWindowListener(this); Button b = new Button("Button"); b.addActionListener(this); f.add(b); f.pack(); f.setVisible(true); } public void actionPerformed(ActionEvent e) { System.out.println("Button pressed!"); } public void windowActivated(WindowEvent e){} public void windowDeactivated(WindowEvent e){} public void windowClosed(WindowEvent e) {} public void windowClosing(WindowEvent e){System.exit(1); public void windowIconified(WindowEvent e){} public void windowDeiconified(WindowEvent e) {} public void windowOpened(WindowEvent e){} } 请选择正确的语句填入横线处。

    A.extends ActionListener, WindowListener

    B.implements ActionListener, WindowListener

    C.implements ActionListener; WindowListener

    D.extends ActionListener; WindowListener


    正确答案:B

  • 第16题:

    下列横线处应填写的语句是( )。 import JaVa.awt.*; public class FirstFrame. extends Frame{ public static void main(String args[]){ FirstFrame. fr=new FirstFrame("First container!"); fr.setsize(240,240); fr.setBackground(Color.yellow); } public FirstFrame(String str){ super(str); } }

    A.fr.setVisible(true)

    B.fr.setVisible(false)

    C.fr.setFrame(true)

    D.fr.setmyFrame(true)


    正确答案:A
    A【解析】本题考查容器的概念。题目所给程序段的容器是一个窗口,窗口中并没有放置其他构件,由于默认为不可见,因此需要调用setVisible(true)将窗口设置为可见的。需要注意题目程序只是生成一个窗口,但是并不能响应用户的操作,即使是单击窗口右上角的“关闭”按钮,也不能关闭窗口。

  • 第17题:

    下列哪个选项的java源文件程序段是不正确的? ( )

    A.package testpackage; public class Test{ }

    B.import java.io.*; package testpackage; public class Test{ }

    C.import java.i.*; class Person{} public class Test{ }

    D.import java.io.*; import java.awt.*; public class Test { }


    正确答案:B

  • 第18题:

    下列代码的下画线处应填入的方法名是( )。 import java.awt.*; import java.applet.*; public class Hello extends Applet{ public void (Graphics g){ 9.drawstring("How are you!",l0,10); } }

    A.repaint

    B.println

    C.paint

    D.show


    正确答案:C
    C。【解析】这里使用一个继承自Applet的类来显示字符。主要方法是在paint方法中使用System.out.println显示。

  • 第19题:

    在下列源代码文件Test.java中, ( )是正确的类定义。

    A.public class test{

    B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }

    C.public class Test extends T1,T2{

    D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}


    正确答案:B

  • 第20题:

    本题中,生成一个窗口,该窗口的长、宽为屏幕长、宽的一半,并且窗口的大小不能改变。

    import java.awt.*;

    import javax.swing.*;

    public class java2

    {

    public.static void main(String[]args)

    {

    FrameSize frame=new FrameSize();

    frame.setDefaultCloseoperation(JFrame.EXIT

    ON_CLOSE);

    frame.show();

    }

    }

    class FrameSize extends JFrame

    {

    public FrameSize()

    {

    setTitle("java2");

    Toolkit tk=Toolkit.getDefaultToolkit();

    Dimension screenSize=

    int screenHeight=screenSize.height;

    int screenWidth=screenSize.width;

    setSize(screenWidth/2,sereenHeight/2);

    }


    正确答案:
    第1处:tk.getScreenSize()第2处:setResizable(false)【解析】第1处取得屏幕大小;第2处设置窗口的大小不能改变。

  • 第21题:

    Which three demonstrate an “is a” relationship?() 

    • A、 public class X {  }     public class Y extends X { }
    • B、 public interface Shape { }     public interface Rectangle extends Shape{ }
    • C、 public interface Color { }     public class Shape { private Color color; }
    • D、 public interface Species { }     public class Animal { private Species species; }
    • E、 public class Person { }    public class Employee {      public Employee(Person person) { }
    • F、 interface Component { }     class Container implements Component {   private Component[] children; }

    正确答案:A,B,F

  • 第22题:

    What produces a compiler error?()  

    • A、 class A { public A(int x) {} }
    • B、 class A {} class B extends A { B() {} }
    • C、 class A { A() {} } class B { public B() {} }
    • D、 class Z { public Z(int) {} } class A extends Z {}

    正确答案:D

  • 第23题:

    多选题
    Which three demonstrate an “is a” relationship?()
    A

    public class X {  }     public class Y extends X { }

    B

    public interface Shape { }     public interface Rectangle extends Shape{ }

    C

    public interface Color { }     public class Shape { private Color color; }

    D

    public interface Species { }     public class Animal { private Species species; }

    E

    public class Person { }    public class Employee {      public Employee(Person person) { }

    F

    interface Component { }     class Container implements Component {   private Component[] children; }


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

  • 第24题:

    单选题
    What produces a compiler error?()
    A

     class A { public A(int x) {} }

    B

     class A {} class B extends A { B() {} }

    C

     class A { A() {} } class B { public B() {} }

    D

     class Z { public Z(int) {} } class A extends Z {}


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