网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
单选题
下列代码中的内部类名是(  )。import java.awt.event.*; import javax.swing.*; class TalkingClock{ public void start(int interval,final boolean beep){ ActionListener listener=new ActionListener(){ public void actionPerformed(ActionEvent event){ …… } } Timer t=new Timer(interval,listener); t.start(); } }
A

Timer

B

ActionListener

C

listener

D

匿名


参考答案

参考解析
解析:
该题考查内部类的知识,Timer是类成员,ActionListener是在类TalkingClock内部声明的一个类,符合内部类的特点。因此ActionListener是内部类。
更多 “单选题下列代码中的内部类名是(  )。import java.awt.event.*; import javax.swing.*; class TalkingClock{ public void start(int interval,final boolean beep){ ActionListener listener=new ActionListener(){ public void actionPerformed(ActionEvent event){ …… } } Timer t=new Timer(interval,listener); t.start(); } }A TimerB ActionListenerC listenerD 匿名” 相关考题
考题 本题的功能是对图形进行操作,包括旋转、移位、放大和剪切。窗口中有4个单选按钮和一个图形面板,图形面板中有一个矩形和该矩形移位操作后的图形,任选其中一个单选按钮,则图形面板中将显示该操作后的图形。 import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.util.*; import javax.swing.*; public class java3 { public static void main(String[]args) { JFrame. frame=new TransformTestFrame; frame.setDefaultCloseOperation(JFrame.EXIT_ 0N_CLoSE); frame.show; } } class TransformTest extends JFrame { public TransformTestFrame { setTitle("java3"); setSize(WIDTH,HEIGHT); Container contentPane=getContentPane; canvas=new TransformPanel; contentPane.add(canvas,BorderLayout.CEN- TER); JPanel buttonPanel=new JPanel: ButtonGroup group=new ButtonGroup; JRadioButton rotateButton =new JRadioButton("旋转",true); buttonPanel.add(rotateButton); group.add(rotateButton); rotateButton.addActionListener(new ActionListener { public void actionPerformed(ActionEvent event) { canvas.setRotate; } }); JRadioButton trans|ateButton =new JRadioButton("移位",false); buttonPanel.add(translateButton); group.add(translateButton); translateButton.addActionListener(new ActionLiatener public void actionPerformed(ActionEvent event) { canvas.setTranslate; } }); JRadioButton scaleButton =new JRadioButton("放大",false); buttonPanel.add(scaleButton): group.add(scaleButton); scaleButton.addActionListener(new ActionListener { public void actionPerformed(ActionEvent event) { canvas.setScale; } }); JRadioButton shearButton =new JRadioButton("剪切",false); buttonPanel.add(shearButton): group.add(shearButton); shearButton.addActionListener(new ActionListener { public void actionPerformed(ActionEvent event) { canvas.setShear; } }); contentPane.add(buttonPanel,BorderLayout. NORTH): } private TransformPanel canvas; private static final int WIDTH=300; private static final int HEIGHT=300; } class TransformPanel extend JPanel { public TransformPanel { square=new Rectangle2D.Double(-50,-50, 100,100); t = new AffineTransform; setRotate; } public void paintComponent { super.paintComponent(g); Graphics2D g2=(Graphies2D)g; g2.translate(getWidth/2,getHeight/2): g2.setPaint(Color.gray); g2.draw(square); g2.transform(t); g2.setPaint(Color.black); g2.draw(square); } public void setRotate { t.setToRotation(Math.toRadians(30)); repaint; } public void setTranslate { t.setToTranslation(20,1 5); repaint; } public void setScale { t.setToScale(2.0,1.5): repaint; } public void setShear { t.setToShear(-0.2,O); repaint; } private Rectangle2D square; private AffineTransform. t; }

考题 下面程序是一个计时器,从1000秒开始倒计时,直到为0结束。在界面上有两个按钮,一个可以暂停计时,另一个可以继续已经暂停的计时。请更正题中带下划线的部分。注意:不改动程序的结构,不得增行或删行import java.awt.*;import java.awt.event.*;import java.applet.Applet;public class Example3_4 extends Applet{public Color color = Color.red;private int num= 1000;public Counter theCounter;private Button stop;private Button start;public void init(){stop = new Button("暂停");start = new Button ("继续");theCounter = new Counter(this);stop.addActionListener(new Lst() implements ActionListener{public void actionPerformed(ActionEvent e){theCounter.sus();}});start.addActionListener(new SuspenListener());add(start);add(stop);theCounter.start();}public void paint(Graphics g){g.setCotor(color);g.drawString(String.valueOf(num),50,50);}public void setInt(int i){num=i;}class SuspenListener implements ActionListener{public void actionPerformed(ActionEvent e){theCounter.conti ();}}}public class Counter extends Thread{Example3_4 example;boolean isHold;Counter (Example3_4 ex){this.example = ex;isHold = false;}public void sus(){isHold = true;}public synchronized void conti(){isHold = false;notify();}public void run(){for (int i = 1000; i>0; i--){if (i%2 == 1)example.color = Color.red;elseexample.color = Color.blue;example.setInt(i);example.repaint();try{sleep(1000);synchronized {while(isHold)wait ( );}}catch (InterruptedException ie){}}}}<HTML><HEAD><TITLE>Example3_4</TITLE></HEAD><BO

考题 下列代码中的内部类名是______。import java.awt.event.*;import javax.swing.*;class Talkingclock{public void start (int interval, final boolean beep){ActionListener listener=newActionListener(){public void actionPerformed (ActionEvent event) {......}}Timer t=new Timer(interval, listener);t. start();]}A) TimerB) ActionListenerC) listenerD) 匿名A.B.C.D.

考题 本题中,主窗口有一个按钮“显示Dial09”,单击该按钮后显示一个对话框,对话框的标题是“Dial09”,其上有一个文字标签“欢迎学习Java.”,此时仍允许对原来窗口进行操作,当关闭新生成的对话框时退出程序。 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class java2 extends Frame. implements ActionLis- tener{ public static void main(String args[]){ java2 f=new java2("java2"); Panel pan=new Panel; f.init; } public java2(String str){ super(str); } public void init{ addWindowListener(new WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); } }); setSize(200,200); setLayout(new FlowLayout); but=new Button("显示Dialog"); add(but); but.addActionListener(this); dig=new Dialog(this,"Dialog", ); dig.setSize(100,50); dig.addWindowListener(new WindowAdapter{ public void windowClosing(WindowEvent e){ ; } }); dig.add("Center",new Label("欢迎学习Ja- va.")); setVisible(true); } public void actionPerformed(ActionEvent e){ dig.setVisible(true); } private Dialog dig; private Button but; }

考题 下面是一个Applet程序,其功能是实现一个计数器,每隔0.15秒计数器数值加1,数值动态变化,并且能够控制计数器的暂停和继续。要求通过使用Swing的构件建立图形用户界面。主要包括一个文本区域,用于显示计数器结果:两个按钮,一个使计数器暂停,一个使计数器继续工作。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。源程序文件代码清单如下。import javax.swing.*;import java.awt.*;import java.awt.event.*;/*<applet code="ex19_3.class" width=800 height=400></applet>*/public class ex19_3 extends JApplet{private JTextField jtf=new JTextField(15);private JButton Hold=new JButton("Hold");private JButton resume=new JButton("Resume");private ex19_3th obj19_3th=new ex19_3th();class ex19_3th extends Thread{private int cnt=0;private boolean bIsHold=false;public ex19_3th() {start();}public void hold(){bIsHold=true;}public synchronized void fauxResume(){bIsHold=false;wait ();}public void run(){while (true){try {sleep(150);synchronized(this){while(bIsHold)notify();}}catch(InterruptedException ie){System.err.println("Interrupted");}jtf.setText(cnt);}}}public void init(){Container cp=getContentPane();cp.setLayout(new FlowLayout());cp.add(jtf);Hold.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ae){obj19_3th.hold ( );}});cp.add(Hold);resume.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){obj19_3th.fauxResume();}&n

考题 本程序的功能是读取用户输入的整数a、b,单击按钮“计算”,则计算出a和b数的和,并显示计算的结果。请将程序补充完整。注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。import java.awt.*;import java.awt.event.*;import javax.swing.*;public class simple{public static void main{String[] args){ExampleFrame. frame=new ExampleFrame();frame.______(JFrame.EXIT_ON_CLOSE);frame.show();}}class ExampleFrame. extends JFrame{private JPanel panel;public static final int DEFAULT_WIDTH=250;public static final int DEFAULT_HEIGHT=250;public ExampleFrame(){Init();setTitle("welcome");setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);Container contentPane=getContentPane();contentPane.add(panel);}private void init(){JLabel la1=new JLabel("输入整数a:");JLabel la2=new JLabel ("输入整数b:");final JTextField num1=new JTextField(10);final JTextField num2=new JTextField(10);JButton but=new JButton("计算");final JLabel res=new JLabel("结果:");but.addActionListener(______{public void actionPerformed(ActionEvent event){String str=new String();String s1=num1.getText();String s2=num2.getText();try{int a=Integer.parseInt(s1);int b=Integer.parseInt(s2);str=String.valueOf(a +b);}catch(Exception e){str=e.getMessage();}res.setText ("结果:"+str);}});panel=new JPanel();panel.setLayout(new FlowLayout(FlowLayout.LEFT));panel.add(la1);panel.add(num1);panel.add(la2);panel.add(hum2);panel.add(but);panel.add(res);}}

考题 请完成下列Java程序。程序的执行结果是生成一个具有一个按钮的窗体,并且按钮的标签是“欢迎参加全国计算机等级考试—Java部分!”字样。注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。import java.awt.*;import java.awt.event.*;public class TestActionEvent{public static void main(String args[]){Frame. f=new Frame("Test");Button b=new Button("欢迎参加Java考试!");TestListener testmonitor=new TestListener();Monitor bh=new Monitor();b.addActionListener(bh);f.addwindowListener(testmonitor);f.add(b);f.setSize(150,100);f.setVisible(true);}}class Monitor ___________ ActionListener{public void actionPerformed(ActionEvent e){System.out.println("a button has been pressed");}}class TestListener__________WindowAdapter{public void windowClosing(WindowEvent e){System.exit(1);}}

考题 请完成下列Java程序:创建一个进度条,可以控制其开始和暂停。要求进度条与线程关联,由线程控制,点击开始按钮开始进度条的滚动,点击停止按钮,暂停,继续点击开始按钮则继续进行。注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;public class ex15_2 extends JPanel {ThreadProg thProgress;JProgressBar jPb;//声明一个进程条对象static JFrame. jf;public ex15_2(){setLayout(new BorderLayout());jPb=new JProgressBar();add(jpb,"Center");JPanel btnPanel=new JPanel();JButton btnStart=new JButton("开始");btnPanel.add(btnStart);btnStart.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ae){__________;}});JButton btnStop=new JButton("停止");btnPanel.add(btnStop);btnStop.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ae){__________;}});add(btnPanel,BorderLayout.SOUTH);}public void startProgress(){if(thProgress==null||!thProgress.isAlive()){thProgress=new ThreadProg(jpb);thProgress.start();}}public void stopProgress(){thProgress.setStop(true);}pubUc static VOid main(String args[]){jf=new JPrame("ex15_2");ex15_2 obj15_2=new ex15_2();jf.getContentPane().add("Center",obj15_2);jf.setSize(250,80);jf.addWindowListener(new WindowAdapter(){pubhc void windowClosing(WindowEvent we){System.exit(0);}});jf.setVisible(true);}}class ThreadProg extends Thread{private JProgressBar jpb;private boolean bStop=false;private boolean bAlive=false;pubhc ThreadProg(JProgressBar jpb){this.jpb=jpb;}public VOid setStop(boolean b){bStop=b;}public void run(){int min=0;int max=60;jpb.setMinimum(min);jpb.setMaximum(max);jpb.setValue(min);for(int x=min;x<=max;x++){if(bStop){break;}else{jpb.setValue(x);try{Thread.sleep(150);} catch(InterruptedException e){}}}bAlive=false;}}

考题 下列JApplet实现了一个多行文本输入区和一个按钮,单击按钮则清空文本区内容,文本区使用带标题的边框。选择正确的语句填入横线处。 import javax,Swing.*; import java.awt.event.*; import java,awt.*; public class ex26 extends Japplet { public void init() { Container cp = getContentPane(); Jbutton jb = new Jbutton("清空"); final JTextArea jta = new JTextArea(); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jta. setText (""); } }); cp.add("South", jb); cp.add("Center", jta); } } { jtA.setBorder(BorderFactory, createTitledBorder("文本区"));B.cp.setBorder(BorderFactory, createTitledBorder("文本区"));C.jta.setBorder(BorderFactory, createTitledBorder("文本区"));D.jta.setBorder(Border, createTitledBorder("文本区"));

考题 选择正确的语句填在下列程序的横线处,使程序正常运行。 package ch1; import java. io. *; import j ava. util. *; class C45 implements Seritizable ______Public Thread t = new Thread(new T45(), "t"); public intcnt = 0; public C45() { t. start ( ) class T45 implements Runnable public int[] a = new int[4]; public void run() { for(int i - 0; i < 4; i++) { a[i] - i +4; } } } public class ex45 { static String fileName = "ch1\\file45.txt"; public static void main(String[] args) throws Exception { C45 bj = new C45 (); FileOutputStream fos = new FileOutputStream(fileName); ObjectOutputStream os = new ObjectOutputStream(fos); oos. writeObject (obj); oos.clese (); fos.close (); System. out, println (obj . toString ( ) ); } }A.transientB.protectedC.packageD.final

考题 在程序中,使用适当的布局管理器,在Frame框的North位置添加一句提示信息,在South位置添加一个单行文本框,在这个文本框中输入的内容将会显示在Center位置。运行结果如下图所示。注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。import java.awt.*;import java.awt.event.*;public class simple extends Frame{public static void main(String[] args){simple frame=new simple("simple");frame.init();frame.setSize(300,300);frame.show();}public simple(String name){super(name);addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){______;}} );}public void init(){setLayout(new______);Label labelTitle=new Label("在本文框中输入字符串, 可以早Frame中间显示");Label showTextLabel=new Label();TextField textField=new TextField("请在这里输入字符串");textField.addActionListener(new AddStringListener(showTextLabel,textField));add("North", labelTitle);add("Center", showTextLabel);add("South", textField);}}class AddStringListener implements ActionListener{Label label;TextField textField;public AddStringListener(Label label, TextField textField){this.label=label;this.textField=textField;}public void actionperformed(ActionEvent e){label.setText(textField.getText());}}

考题 下面Applet程序,其功能是实现一个计数器,每隔0.15秒计数器数值加1,数值动态变化,并且能够控制计数器的暂停和继续。要求通过使用swing的构件建立图形用户界面,主要包括一个文本区域,用于显示计数器结果;两个按钮,一个使计数器暂停,一个使计数器继续工作。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:import javax.swing.*;import java.awt.*;import java.awt.event.*;/*<applet code="ex7_3.class" width=800 height=400 ></applet>*/public class ex7_3 extends JApplet {private JTextField jtf = new JTextField(15);private JButton Hold = new JButton("Hold"),resume = new JButton("Resume");private ex7_3th obj7_3th = new ex7_3th();class ex7_3th extends Thread {private int cnt = 0;private boolean bIsHold = false;public ex7_3th() { start(); }public void hold() {bIsHold = true;}public synchronized void fauxResume() {bIsHold = false;wait();}public void run() {while (true) {try {sleep(150);synchronized(this) {while (bIsHold)not i fy ( );}} catch(InterruptedException ie) {System.err.println("Interrupted");}jtf.setText(cnt);}}public void init() {Container cp = getContentPane();cp.setLayout(new FlowLayout());cp.add(jtf);Hold.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent ae) {obj7_3th.hold();}});cp.add(Hold);resume.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e){obj7_3th.fauxResume();}});cp.add(resume);public static void main(String[] args) {ex7_3 obj7_3=new ex7_3();String str= obi7_3.getClass().toString();if(str.indexOf("class") != -1)str= str.substring(6);JFrame. frm = new JFrame(str);frm.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent we) {System.exit(O);}});frm.getContentPane().add(obj7_3);frm.setSize(300, 200);obj7_3.init();

考题 下列程序实现了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, WindowListenerB.implements ActionListener, WindowListenerC.implements ActionListener; WindowListenerD.extends ActionListener; WindowListener

考题 请在下列程序的横线处填入正确的语句。 import java.awt.*; import java.awt,event.*; public class ex16 { Frame. f; TextArea ta; Button btn; public static void main(String[] args) { ex16 e = new ex16(); e.m(); } public void m() { f = new Frame("ex16"); ta = new TextArea(); btn = new Button("ok"); btn.addActionListener(new MyAction()); f.add(ta, "Center"); f.add(btn, "South"); f.setSize(100, 100); f.setVisible (true); } class MyAction implements ActionListener { ______ { System. out.println (ta. getText ()); } } }A.static void actionPcrformcd(AcfionEvent e)B.public void action(ActionEwent e)C.public actionPerformed(ActionEvent e)D.public void actionPerformed(ActionEvent e)

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

考题 下面程序代码,让用户输入想显示的.gif文件名,之后将这个图像文件加载到内存并显示。请勿改动原有代码,在下画线处填人适当浯句,将程序补充完整。import java.applet.*;import java.awt.*;import java.awt.event.*;public class test20_2 extends Applet implements ActionListener {Label promptLbl=new Label(“请输入欲显示的图像文件名:”);TextField inputTfd=new TextField20( );Button getlmageBtn=new Button(“显示图像”);Image mylmage;public void init( ) {add(promptLbl);add(inputTfd);add(getlmageBtn);inputTfd.setText(””);getlmageBtn.addActionListener(this);}public void paint(Graphics g) {if(mylmage!=null)g.______(mylmage,10,100,this);}public void actionPerformed(ActionEvent ae) {if(ae.getSource( )==_______) {String str=inputTfd.getText( ).trim( );if(!(str.substring(Math.max(0,str.length( )-4)).equals(".gif")))str=str.trim( )+".gif";mylmage=getlmage(getDocumentBase( ),str);repaint( );}}}

考题 本题的功能是监听鼠标的操作。鼠标置于窗口中单击时(左键或右键),在单击的地方会画一个小矩形,如果将鼠标置于小矩形上,则鼠标光标状态改为小十字,按下鼠标左键可拖曳,双击鼠标左键(或右键)时,小矩形消失。 import java.awt.*; import java.awt.event.*; import java.util.*; import java.awt.geom.*; import javax.swing.*; public class java3 { public static void main(String[]args) { MouseFrame. frame=new MouseFrame: frame.setDefaultCloseOperation(JFrame.EXIT_ oN_CLOSE); frame.show; } } class MouseFrame. extends JFrame { public MouseFrame { setTitle("java3"); setSize(DEFAULT WIDTH, DEFAULT HEIGHT): MousePanel panel=new MousePanel; Container contentPane=getContentPane; contentPane.add(panel); } public static final int DEFAULT_WIDTH=300; public static final int DEFAULT_HEIGHT=200; } class MousePanel extends JPanel { public MousePanel { squares=new ArrayList; current=null: addMouseListener(new MouseHandler); addMouseMotionListener(new MouseMotionHan- dler); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2=(Graphics2D)g; for(int i=0;isquares.size;i++) g2.draw((Rectangle2D)squares.get(i)); } public void find(Point2D p) { for(int i=0;isquares.size;i++) { Rectangle2D r=(Rectangle2D)squares.get(i); if(r.contains(p))return r; } return null: } public void add(Point2D p) { double x=P.getX; double Y=P.getY: current=new Rectangle2D.Double( x-SIDELENGTH/2. y-SlDELENGTH/2. S1DELENGTH, SIDELENGTH); squares.add(current); repaint; } public void remove(Rectangle2D s) { if(S= =null)return: if(S= =current)current=null; squares.remove(s): repaint; } private static final int SIDELENGTH=10: private ArrayList squares; private Rectangle2D current; private class MouseHandter extends MouseAction- Listener { public void mousePressed(MouseEvent event) { current=find(event.getPoint); if(current= =null) add(event.getPoint); } public void mouseClicked(MouseEvent event) { current=find(event.getPoint); if(current!=nullevent.getClickCount =2) remove(current); } } private class MouseMotionHandler implements Mouse- MotionListener { public void mouseMoved(MouseEvent event) { if(find(event.getPoint)= =null) setCursor(Cursor.getDefaultCursor); else setCursor(Cursor.getPredefinedCursor (Cursor.CROSSHAIR_CURSOR)); } public void mouseDragged(MouseEvent event) { if(current!=null) { int x=event.getX: int Y=event.getY; 、 current.setFrame( x-SIDELENGTH/2, Y-SlDELENGTH/2. SIDELENGTH, SIDELENGTH); repaint; } } } }

考题 描述以下的applet: import java.applet.Applet; import java.awt.event.*; import java.awt.*; public class MyApplet extends Applet { Button b1, b2; public void init() { ActionListener a = new ActionListener() { public void actionPerformed(ActionEvent evt) { if(evt.getSource() == bl) { b1.setEnabled(false); b2.setEnabled(true); } else { b1.setEnabled(true); b2.setEnabled(false); } } } b1 = new Button("1"); b1.addActionListener(a); add(b1); b2 = new Button("2"); b2.addActionListener(a); add(b2); } } 选择所有正确的答案______。A.applet上只有一个按钮,但它什么都不做B.applet上什么也没有C.applet上有两个按钮,当用户单击一个按钮时,它将成为disabled:当用户单击另一个按钮时,另一个将成为enabledD.当用户单击按钮时,什么都不会发生

考题 下面程序构造了一个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);}}

考题 下列代码中的内部类名是( )。 import java.awt.event.*; lapoct javax.swin9.*; class TalkingClock( public void start(int interval,final boolean beep){ ActionListener listener=new ActionListener{ public void actionPerformed(ActionEvent e- vent){ … } } Timer t=new Timer(interval,listener); start; } }A.TimerB.ActionListenerC.1istenerD.匿名

考题 请完善程序(程序文件名: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;}

考题 下列Applet用于显示提供它的主机的IP地址。请选择正确的语句填入横线处。 import java.awt.*; import java. awt. event.*; import java.applet.Applet; import java.net. *; public class ex23 extends Applet { public void init() { setLayout(new GridLayout(2, 1); Button btm = new Button("显示IP"); final Label 1 = new Label(" "); btn. addActionListener (new ActionListener ( ) { public void actionPerformed(ActionEvent ae) { try { URL ur1 = getCodeBase(); String strName = ur1.getHost(); ______ 1.setText (ia.toString()); } catch (Exception e) { e.printStackTrace (); } } }); add (btn); } }A.InetAddress ia = URL.getByName(strName);B.InetAddress ia = InetAddress.getByName(strName);C.InetAddress ia = new InetAddress.getByName(strName);D.InetAddress ia = InetAddress.getByName(ur1);

考题 请选择正确的语句填入下列程序的横线处。 import javax. Swing.*; import java.awt.*; import java.awt.event.*; public class ex46 { static String str= "单击次数:"; static intcnt = 0; public static void main(String[] args) { try{ UIManager.setLookAndFeel(UIManager. getCrossPlatformLookAndFeelClassName()); } catch(Exception e) {} JFrame. jf = new JFame("ex46"); JButton jb = new JButton("Button"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { cnt ++; j1.setText(str +cnt); } }); j1. setLabelFor (jb); jPanel jp = new JPanel(); jp.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25); jp.setLayout(new GridLayout(0, 1)); jp.add(jb); jp.add (j1); jf.getContenPanel() .add(jp, "Center"); jf.pack(); jf.setVisible (true); } }A.Labelj1 = new JLabel(str + "0");B.final JLabel j1 = new JLabel(str + "0");C.final JLabelj1 = JLabel(str + "0");D.JLabelj1 = new JLabel(str + "0");

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

考题 本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“Yes"和“N0”,单击对话框上的“Yes”和“N0”按 钮后返回主窗口,并在右侧文本域中显示刚才所单击的按钮信息。import java.awt.event.*;import java.awt.*;class MyDialog implements ActionListener{static final int YES=1,N0=0;int message=-1;Button yes,no;MyDialog(Frame. f.String S,boolean b){super(f,S,b);ves=new Button("Yes");yes.addActionListener(this);no=new Button("No"); no.addActionListener(this)osetLayout(new FlowLayout());add(yes);add(no);setBounds(60,60,100,100);addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){message=-1;setVisible(false);)});}public void actionPerformed(ActionEvent e){if(e.getSource()= =yes){message=YES;setVisible(false);}else if(e.getSource()= = no){message=NO;setVisible(false);}}public int getMessage(){return message;}}class Dwindow extends Frame. implements ActionLis-tener{TextArea text;Button button;MyDialog dialog;Dwindow(String s){super(s);text=new TextArea(5,22);button=new Button("打开对话框");button.addActionListener(this);setLayout(new FlowLayout());add(button);add(text);dialog=new MyDialog(this,"Dialog",true);setBounds(60,60,300,300);setVisible(true);validate();addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});}public void actionPerformed(ActionEvent e){if(e.getSource()= =button){if(dialog.getMessage()= =MyDialog.YES){text.append("\n你单击了对话框的yes按钮");}else if(dialog.getMessage()= =MyDialog.NO){text.append("\n你单击了对话框的N0按钮");}}}}public class java2{public static void main(String args[]){new Dwindow("java2");}}

考题 本题的功能是求两个交叉图形的并、减、交和异或。窗口中有4个单选按钮和一个图形面板,面板中有两个交叉的图形,选中其中一个单选按钮,图形面板中以黑色填充的方式显示运算结果。import java.awt.*;import java.awt.event*+;import java.awt.geom.*;import java.util.*;import javax.swing.*;public class java3{public static void main(String[]args){JFrame. frame=new AreaTestFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.show();}}class AreaTestFrame. extends JFrame{public AreaTestFrame(){setTitle("java3");setSize(WIDTH,HEIGHT);areal=new Area(new Ellipse2D.Double(100,100,150,100));area2=new Area(new Rectangle2D.Double(150,150,150,100));Container confentPane=getContentpane();panel=newJPanel(){public void paintComponent(Graphics g){super.paintComponent(g);Graphics2D g2=(Graphics2D)g;g2.draw(areal);g2.draw(area2);if(area!=null)g2.fill(area);}};contentPane. add(panel,BorderLayout. CEN-TER);JPanel buttonPanel=new JPanel();ButtonGroup group=new ButtonGroup();JRadioButton addButton=new JRadioButton("并",false);buttonPanel.add(addButton);group.add(addButton);addButton.addActionListener(newActionListener(){public void actionPerformed(ActionEvent event){area=new Area();area.add(areal);area.add(area2);panel.repaint();}});JRadioButton subtractButton=new JRadioButton("减",false);buttonPanel.add(subtractButton);group.add(subtractButton);subtractButton.addActionListener(newActionListener(){public void actionPerformed(ActionEvent event){area=new Area();area.add(areal);area.subTract(area2);panel.repaint();}});JRadioButton intersectButton=new JRadioButton("交",false);buttonPanel.add(intersectButton);group.add(intersectButton);intersectButton.addActionListener(newActionListener(){public void actionPerformed(ActionEvent event){area=new Area():area.add(areal);area.intersect(area2);panel.repaint();}});JRadioButton exclusiveCIrButton=new JRadioButton(“异或”,false);buttonPanel.add(exelusiveOrButton);group.add(exclusiveOrButton);exclusiveOrButton.addActionListener(newActionListener(){public void actionPerformed(ActionEvent event){area=new Area();area.add(areal);area.exclusiveor(area2);panel.repaint();}});contentPane.add(buttonPanel,BorderLayout.NORTH);}private JPanel panel;private Area area;private Area areal;private Area area2;private static final int WIDTH=400;private static final int HEIGHT=400;}

考题 ●试题六【说明】下面是一个Applet程序,其功能是建立一个图形用户界面的窗口,包括一个文本显示区和一个按钮,点击按钮,可以在文本区已有的文本基础上追加显示10条"Welcome to China"信息,并且文本区由滚动条控制文本的上下滚动。程序运行结果如图4所示。import javax.swing.*;import javA.awt.*;import javA.awt.event.*;/*applet code="ex5_6.class" width=800 height=400 /applet图4*/public class ex5_6 extends JApplet {JButton jb = new JButton("Add Text");JTextPane jtp = new JTextPane();public void init() {jb.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e){for(int i = 1; i 10; i++)(1) + "Welcome to China!\n");}});Container cp = (2) ;cp.add(new JScrollPane(jtp));cp.add( (3) );}public static void main(String[] args) {ex5_6 obj5_6=new ex5_6();String str = obj5_6.getClass().toString();if(str.indexOf("class") !=-1)str = str.substring (6) ;JFrame. frm = new JFrame(str);frm.addWindowListener(new (4) {public void windowClosing(WindowEvent we) {System.exit(0);}});(5) .add(ex5_6);frm.setSize(300, 400);frm.setVisible(true);}}ex5_6.htmlHTMLHEADTITLEex5_6/TITLE/HEADBODYapplet code="ex5_6.class" width=800 height=400 /applet/BODY/HTML