The buttons labeled “North” and “South” will have the same width.
The buttons labeled “North” and “South” will have the same height.
The height of the button labeled “North” can very if the Frame is resized.
The height of the button labeled “South” can very if the Frame is resized.
The width of the button labeled “North” is constant even if the Frame is resized.
The width of the button labeled “South” is constant even if the Frame is resized.
第1题:
A.class x { .... }
B.public x extends y { .... }
C.public class x extends y { .... }
D.class x extends y implements y1 { .... }
第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:
}
第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;
第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
第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());
第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);
}
}
第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;
}
第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();
}
}
}
第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; } }
第10题:
下列类的定义中,错误的是()。
第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?()
第12题:
The buttons labeled “North” and “South” will have the same width.
The buttons labeled “North” and “South” will have the same height.
The height of the button labeled “North” can very if the Frame is resized.
The height of the button labeled “South” can very if the Frame is resized.
The width of the button labeled “North” is constant even if the Frame is resized.
The width of the button labeled “South” is constant even if the Frame is resized.
第13题:

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> {
第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.以上都不对
第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
第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)
第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 { }
第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
第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: }} }}
第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);
;
}
第21题:
Which three demonstrate an “is a” relationship?()
第22题:
What produces a compiler error?()
第23题:
public class X { } public class Y extends X { }
public interface Shape { } public interface Rectangle extends Shape{ }
public interface Color { } public class Shape { private Color color; }
public interface Species { } public class Animal { private Species species; }
public class Person { } public class Employee { public Employee(Person person) { }
interface Component { } class Container implements Component { private Component[] children; }
第24题:
class A { public A(int x) {} }
class A {} class B extends A { B() {} }
class A { A() {} } class B { public B() {} }
class Z { public Z(int) {} } class A extends Z {}