The code will not compile.
A Window will appear containing only a Button.
An IllegalArgumentException is thrown at line 6.
A Window button will appear but will not contain the Label, TextField, or Button.
A Window will appear containing a Label at the top, a TextField below the Label, and a Button below the TextField.
A Window will appear containing a Label on the left, a TextField to the right of the Label, and a button to the right of the TextField.
第1题:
关于下面的程序段,说法正确的是 import java.awt.*; import java.applet.*; public class Test extends Applet{ Canvas MyCanvas; public void init(){ MyCanvas=new Canvas(); MyCanvas.setBackground(Color.cyan); add(MyCanvas); } }
A.程序可以运行,且看到显示
B.程序编译出错
C.程序可以运行,但看不到显示
D.以上说法都不对
第2题:
下列程序构造了一个 Swing Applet ,请在下划线处填入正确的代码
Import javax.swing.*;
Import java.awt.*;
Public class SwingApplet extends 【 13 】 {
Jlabel l = new Jlabel ( “ This is a Swing Applet. ” );
Public void init(){
Container contentPane = getContentPane();
contentPane.add(1);
}
}
第3题:
下列哪个选项的java源文件代码片段是不正确的?
A.package testpackage; public class Test{ }
B.import java. io. *; package testpaekage; public class Test { }
C.import java.io.*; class Person { } public class Test { }
D.import java.io.*; import java. awt.*; public class Test{ }
第4题:
下列( )选项的java源文件代码片段是不正确的。
A.package testpackage; publicClass Test{}
B.import java.io.*; package testpackage: publicClass Test{}
C.import java.io.*; Class Person{} publicClass Test{}
D.import java.io.*; import java.awt.*; publicClass Test{}
第5题:
下列代码的输出结果是( )。
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;
第6题:
使下列程序正常运行并且输出“Hello!”,横线处应填写的内容是( )。 class Test { public static void main(string[]args){ Test t=new Test; start; } Public void run{ System.out.println("Hello!¨); )
A.extends Thread
B.extends Float
C.extends Iostream
D.extends Stdio
第7题:
选择正确的语句填在下列程序的横线处。 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());
第8题:
下列哪个选项的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 { }
第9题:
下列代码的下画线处应填入的方法名是( )。 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
第10题:
在下列源代码文件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: }} }}
第11题:
本题中,生成一个窗口,该窗口的长、宽为屏幕长、宽的一半,并且窗口的大小不能改变。
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);
;
}
第12题:
import java.awt.*; public class Test extends Frame { public Test() { add(new Label(“Hello”) ); add(new TextField(“Hello”) ); add(new Button(“Hello”) ); pack(); show(); } public static void main(String args) { new Test (); } } What is the result? ()
第13题:
下列代码的下划线处应填入的方法名是______。
import java.awt.*;
import java.applet.*;
public class Hello extends Applet{
public void______(Graphics g){
g.drawString("How are you!", 10, 10);
}
}
A) repaint
B) println
C) paint
D) show
A.
B.
C.
D.
第14题:
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 T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }
D.public class
第15题:
下面程序的输出结果是( )。 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.以上都不对
第16题:
在下列源代码文件Test.java中,正确定义类的代码是( )。
A.pblic 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 T1,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; } }
第17题:
要下列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
第18题:
下列横线处应填写的语句是( )。 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)
第19题:
在下列程序横线处填入设置窗口大小的语句,窗口长200,宽100,请选择正确的一项______。 import java.awt.*; public class ex34 extends Frame { public static void main(String[] args) { ex34 e = new ex34(); ______ e. setVisible (true); } }
A.setSize(200, 100);
B.e.setSize(200, 100);
C.setSize(100, 200);
D.e.setSize(100, 200);
第20题:
下面程序构造了一个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);
}
}
第21题:
请完善程序(程序文件名: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;
}
第22题:
本题的功能是获取鼠标在窗口中的位置。当鼠标移进窗口中,就会实时显示鼠标在窗口中的相对位置,比如显示为"鼠标的当前位置: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();
}
}
}
第23题:
在下列源代码文件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; } }
第24题:
The code will not compile.
A Window will appear containing only a Button.
An IllegalArgumentException is thrown at line 6.
A Window button will appear but will not contain the Label, TextField, or Button.
A Window will appear containing a Label at the top, a TextField below the Label, and a Button below the TextField.
A Window will appear containing a Label on the left, a TextField to the right of the Label, and a button to the right of the TextField.