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

题目内容 (请给出正确答案)

在Java语言中,一个Applet具有如下init()方法: public void init(){  setLayout(new  BorderLayout());  add(BorderLayout.EAST,  new Button(“Click ME!”));} 当该Applet载入时,用户外观将是()。

  • A、没有任何内容
  • B、居中位置有个按钮
  • C、左边有个按钮
  • D、右边有个按钮
  • E、一个按钮填充整个用户界面上

参考答案

更多 “ 在Java语言中,一个Applet具有如下init()方法: public void init(){  setLayout(new  BorderLayout());  add(BorderLayout.EAST,  new Button(“Click ME!”));} 当该Applet载入时,用户外观将是()。A、没有任何内容B、居中位置有个按钮C、左边有个按钮D、右边有个按钮E、一个按钮填充整个用户界面上” 相关考题
考题 在Java语言中,一个Applet具有如下init()方法:publicvoidinit(){setLayout(newBorderLayout());add(BorderLayout.EAST,newButton("ClickME!"));}当该Applet载入时,用户界面的外观将是()。 A.没有任何内容B.居中位置有个按钮C.左边有个按钮D.右边有个按钮E.一个按钮填充整个用户界面上

考题 下面是一个Applet程序,其功能是建立一个图形用户界面的窗口,包括一个文本显示区和一个按钮,单击按钮,可以在文本区已有的文本基础上追加显示10条“欢迎您,参加Java考试!”信息,并且文本区由滚动条控制文本的上下滚动。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。源程序文件代码清单如下;import javax.swing.*;import java.awt.*;import java.awt.event.*;<applet code="ex13_3.class" width=800 height=400></applet>public class ex13_3 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++)jtp.getText(jtp.setText()+"欢迎您,参加Java考试!");}});Container cp = getContentPane();cp.add(new JScrollPane(jtp));cp.add(BorderLayout. SOUTH, jtp);}public static void main(String args[]){ex13_3 obj13_3=new ex13_3();String str = obj13_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(0);}});frm.getContentPane ().addiex13 3);frm.setSize(300, 400);frm.setVisible(true);}}ex13_3.html<HTML><HEAD><TITLE>ex13_3</TITLE></HEAD><BODY><applet code="ex13_3.class" width=800 height=400></applet></BODY></HTML>

考题 本题中,主窗口有一个按钮、一个文本域和一个复选按钮,初始时窗口的大小是不能调整的,选中复选按钮后,窗口大小就可以进行调整,如果撤销复选按钮的选择,则窗口的大小又不能调整,单击按钮可以关闭程序。 import java.awt.*; import java.awt.event.*; class MyFrame. extends Frame {Checkbox box; TextArea text; Button button; MyFrame(String s) {super(s); box=new Checkbox("设置窗口是否可调整大 小"); text=new TextArea(12,12); button=new Button("关闭窗口"); button.addActionListener(this); box.addltemListener(this); setBounds(100,100,200,300); setVisible(true); add(text,BorderLayout.CENTER); add(box.BorderLayout.SOUTH); add(button.BorderLayout.NORTH); ; validate; } public void itemStateChanged(ItemEVent e) {if(box.getState= =true) {setResizable(true); } else { setResizable(false); } } public void actionPerformed(ActionEvent e) {dispose; } } class java2 {public static void main(String args[]) { new MyFrame("java2"); } }

考题 本题中,主窗口有一个按钮“显示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在窗口中实现一个不可编辑的TextField,并且显示“ok”。在横线处填入正确的语句。import java.applet.Applet;import java.awt.t;public class Test extends Applet {TextField tf;public void init () {setLayout (new GridLayout(1,0);tf=new TextField("ok");【 】add(tf);}}

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

考题 下列Applet实现在窗口中按右对齐方式摆放三个单选按钮。选择正确的语句填入下面横线处。 import java.applet.Applet; import java.awt.*; public class ex21 extends Applet { CheckboxGroup chkG; Checkbox chk1, chk2, chk3; public void init() { ______ chkG = new CheckboxGroup(); chk1 = new Checkbox("选项1", chkG, false); add(chk1); chk2 = new Checkbox("选项2", chkG, false); add(chk2); chk3 = new Checkbox("选项3", chkG, false); add(chk3); } }A.setLayout(new BorderLayout());B.setLayout(new FlowLayout());C.setLayout(FlowLayout(FlowLayout. RIGHT));D.setLayout(new FlowLayout(FlowLayout.RIGHT));

考题 下面是一个Applet程序,其功能是建立两个文本区域,一个为编辑区,一个为只读区;建立两个按钮,一个实现将编辑区中被鼠标选定的文本内容复制到只读区中,一个实现将只读区的全部文本内容清空。请更正题中带下划线的部分。注意:不改变程序的结构,不得增行或删行。import java.awt.*;import java.applet.*;/*<applet code="exl4_3.class" width=800 height=400></applet>*/public class exl4_3 extends Applet{private Button okBtn, clearBtn;private String strMessage;private TextArea tArea1, tArea2;public void init(){strMessage="Hello! Welcome to the test! \n" +"Wish you good luck!";tArea1=new TextArea(10,25);tArea1.setText(strMessage);tArea2=new TextArea(10,25);tArea2.setEditable(true);kBtn=new Button("Copy");clearBtn=new Button("Clear");add(tArea1);add(tArea2);add(okBtn);add(clearBtn);}public boolean action(Event e,Object o){if(e.target= =okBtn)tArea1.setText(tArea2.getSelectedText());else if(e.target= =clearBtn)tArea1.setText("");return ture;}}exl4_3.html<HTML><HEAD><TITLE>exl4_3</TITLE></HEAD><BODY><applet code="exl4_3.class"width=800 height=400></applet></BODY></HTML>

考题 下面是一个Applet程序,其功能是接收用户输入的两个整数,比较它们的大小,并在用户按下“比较大小”按钮后,将 Applet中显示的“请先输入两个待比较的整数”,改为“两个整数中最大值是:x”,x是两个数中的最大值。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:import java.applet.*;import java.awt.*;import java.awt.event.*;/*<applet code=LookForMax width=800 height=400></applet>*/public class LookForMax extends Applet implements ActionListener{Label result ;TextField inl,in2;Button btn;int a=0,b=0,max=0;public void init(){result=new Label ("请先输入两个待比较得整数");in1=new TextField(5);in2=new TextField(5);btn=new Button("比较大小");add(in1);add(in2);add(btn);add(result);btn.addActionListener(supper);}public void actionPerformed(ActionEvent e){a=Integer.parseInt(in1);b=Integer.parseInt(in2);if(a>b)max=a;elsemax=b;result, setText ( "两个数中最大值是:"+max);}}LookFormax.html:<html><head><title>A Simple Program</title></head><body><applet code="LookForMax.class" width=800 height=400></applet></body></html>

考题 下面是一个Applet程序,其功能是有两个按钮,分别为First和Second,以及一个Label构件。要求单击 First时能在Label中显示出"Command:First",而单击Second时能显示出"Command:Second",要求只能重载一次 actionPerformed()方法,请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。源程序文件代码清单如下:import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code=ex04_3.class width=800 height=400></applet>*/Public class ex04_3 extends Applet implements ActionListener{private String str="ok";private Label l;private Button btn;public void init(){setLayout(null);l=new Label(str);l.reshape(10,10,100,30);add(l);btn=new Button("First");btn.reshape(10,50,60,20);l.addActionListene(this);add(btn);btn=new Button("Second");btn.reshape(10,100,60,20);btn.setActionCommand("First");btn.addActionListener(this);add(btn);}public void actionPerformed(ActionEvent ae){str="Command:"+ae.getActionCommand();btn.setText(str);}}ex04_3.html<HTML><HEAD><TITLE>ex04_3</TITLE></HEAD><BODY><applet code="ex2_3.class" width=800 height=400></applet></BODY></HTML>

考题 当Applet程序中的init方法为下列代码时,运行后用户界面会出现的情况,以下描述正确的是( )。 public void init { setlLayout(new BorderLayout); add(”North”,new TextField(10)): add(”Center”,new Button(”help”)): }A.文本框将会出现在Applet的顶上,且有l0个字符的宽度B.按钮将会出现在Applet的正中间,且尺寸为正好能够包容help的大小C.文本框将会出现在Applet的顶上,从最左边一直延伸到最右边;按钮将会出现在Applet的正中间,覆盖除文本框外的所有空间D.按钮与文本框的布局依赖于Applet的尺寸

考题 下列Applet在窗口中放置2个Button,标签分别为“东”和“西”,在窗口中的位置与它们的名字相同。选择正确的语句填入横线处。 import java.awt.*; import java.applet.*; public class ex16 extends Applet { Button e, w; public void init() { e = new Button("东"); w = new Button("西"); add("East", e); add("West", w); } }A.setLayout(new BoxLayout());B.setLayout(new FlowLayout());C.setLayout(new BorderLayout());D.setLayout(new GridLayout());

考题 以下程序中,当用户单击“移动”按钮以后,就可以使用方向键控制屏幕上句子的移动,单击“停止”按钮,则句子不再随着方向键移动。运行结果如下图所示注意:请勿改动其他已有语句内容,仅在横线处填入适当语句。import java.applet.*;import java.awt.*;import java.awt.event.*;public class Example2_8 extends Applet implements KeyListener{public void keyTyped(KeyEvent e) {}public void keyReleased(KeyEvent e) {}Button button;Button stopButton;Label out;int x,y;public void _______ (){button = new Button("移动");button.addActionListener(new AddMoveListener(this));stopButton = new Button("停止移动");stopButton.addActionListener(new RemoveListener(this));stopButton.setEnabled(false);out = new nabel("按下按钮以后我可以随方向键移动");add(button);add(stopButton);add (out);}public void start(){super, start ();}public void keyPressed(KeyEvent e){x=out.getBounds().x;y=out.getBounds().y;if(e.getKeyCode()==KeyEvent.VK_UP){y=y-2;if(y<=0) y=0;out. setLocation (x, y);}else if(e.getKeyCode()==KeyEvent.VK_DOWN){y=y+2;if (y>=300) y=300;out. setLocation (x, y);}else if(e.getKeyCode()==KeyEvent.VK_LEFT){x=x-2;if(x<=0) x=0;out. setLocation (x, y);}else if(e.getKeyCode()==KeyEvent.VK_RiGHT){

考题 本题是一个Applet,功能是监听用对于文本域中文本的选择。页面中有一个文本域、一个“复制”按钮和一个文本框,选中文本域中部分文字后,单击按钮“复制”,所选文字将显示在文本框中。 import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class java3 extends Applet implements ActionL- istener { TextArea ta=new TextArea(5,30); TextField tf=new TextField(30); Button button=new Button("复制"); String text="AWT提供基本的GUl组件,\n"+" 具有可以扩展的超类,\n"+"它们的属性是继承的。\ n": public void init { setLayout(new FlowLayout(FlowLayout.left)); ta.setText(text); ta.setEditable(true); add(ta); add(button); add(tf); ta.addActionListener(this); } public void actionPerformed(ActionEvent e) { String S; s=ta.getSelectText; if(e.getSource= =button) tf.setText(s); } }

考题 描述以下的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);}}

考题 本题是一个Applet,页面中有10个按钮,名称从“0~ 9”,用鼠标任意单击其中一个按钮后,通过键盘上的上下左右键可以控制按钮在窗口中移动。import java.applet.*;import java.awt.*;import java.awt.event.*;public class java2 extends Applet{Button b[]=new Button[10];int x,Y;public void init(){for(int i=0;i<=9;i++){b[i]=new Button(""+i);b[i].addKeyListener(this);addCb[i]);}}public void{Button button=(Button)e.getSource();x=button.getBounds().x;y—button.getBounds().y;if(e,getKeyCode()= =KeyEvent.VK_UP){y=y-2;if(y<=O)y=0;button.setLocation(x,y);}else if(e.getKeyCode()= =KeyEvent.VK_DOWN){y=y+2;if(y>=300)y=300;button,.setLocation(X,y);}else if(e.getKeyCode()= =KeyEvent.VK_LEFT){x=x-2;if(x<=0)x=0;button.setLocation(x,y);}else if(e.getKeyCode()= =KeyEvent.VK_RIGHT)(x=X+2;if(x>=300)x=300;button.setLoeation(X,y);}}public void keyTyped(KeyEvent e){}public void keyReleased(KeyEvent e){}}

考题 本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“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");}}

考题 本题的功能是对下拉菜单项的操作,包括添加和删除。页面包括一个下拉菜单、一个文本框和两个按钮“删除”和“添加”,选中下拉菜单的一项后,可以通过“删除”按钮从下拉菜单中删除该项,在文本框中填入字符串后,单击“添加”按钮就可以将该项添加到下拉菜单中,所有信息都将显示在右侧的文本域中。import java.awt.*;import java.awt.event.*;public class java2 extends java.applet.Applet imple-ments hemListener,ActionListener{Choice choice;TextField text;TextArea area;Button add,del;public void init() .{choice:new Choice();text=new TextField(8);area:new TextArea(6,15);choice.add("音乐天地");choice.add("武术天地");choice.add("象棋乐园");choice.add("交友聊天");add=new Button("添加");del=new Button("删除");add.addActionListener(this);del.addActionListener(this);choice.addItemListener(this);add(choice);add(del);add(text);add(add);add(area);}public void itemStateChanged(hemEvent e){String name= ;int index=choice.getSelectedIndex();area.setText("\n"+index+":"+name);}public void actionPerformed(ActionEvent e){if(e.getSource()= =add||e.getSource()= =text){String name=text.getText();if(name.length()>0){choice.add(name);choice.select(name);area.append("\n添加"+name);}}else if(e.getSource()= =del){choice.remove( );area.append("\n删除"+choice.getSelectedItem());}}}

考题 当Applet程序中的init()方法为下列代码时,运行后用户界面会出现什么样的情况。 public void init() { setLayout(new BorderLayout()); add("North", new TextField(10)); add("Center", new Button("help")); } 下面各选项中描述正确的是( )。A.文本框将会出现在Applet的顶上,且有10个字符的宽度B.按钮将会出现在Applet的正中间,且尺寸为正好能够包容help的大小C.文本框将会出现在Applet的顶上,从最左边一直延伸到最右边;按钮将会出现在Applet的正中央,覆盖除文本框外的所有空间D.按钮与文本框的布局依赖于Applet的尺寸

考题 ●试题六【说明】下面是一个Applet程序,其功能是建立2个文本区域,一个为编辑区,一个为只读区;建立2个按钮,一个实现将编辑区中被鼠标选定的文本内容拷贝到只读区中,一个实现将只读区的全部文本内容清空。程序运行结果如图3所示。图3import javA.awt.*;import javA.applet.*;/*applet code="ex3_6.class" width=800 height=400 /applet*/public class ex3_6 extends Applet{private Button okBtn, clearBtn;private String strMessage;private TextArea tArea1, tArea2;public void init(){strMessage = "Hello! Welcome to the test! \n" +"Wish you good luck!";tArea1 = new TextArea( 10, 25 );(1) ;tArea2 = new TextArea( 10, 25 );(2) ;okBtn = new Button( "Copy" );clearBtn = (3) ;add( tArea1 );add( tArea2 );add( okBtn );add( clearBtn );}public boolean action( Event e, Object o ){if( e.target == okBtn )tArea2.setText( (4) );else if( e.target == clearBtn )(5) ;return true;}}ex3_6.htmlHTMLHEADTITLEex3_6/TITLE/HEADBODYapplet code="ex3_6.class" width=800 height=400 /applet/BODY/HTML

考题 ●试题七【说明】下面是一个Applet程序,其功能是通过一个按钮控制一个窗口的创建,显示与隐藏,并且以按钮文字作为提示,可以随着窗口的状态改变,即如果窗口出现,则按钮文字为"Hide myFrm",提示用户点击按钮,则隐藏窗口,反之亦然。请将横线处语句补充完整。程序运行结果如图5所示:图5import javA.awt.*;import javA.applet.*;/*applet code="ex8_7.class" width=800 height=400 /applet*/public class ex8_7 extends Applet{private Frame. frm;private Button showBtn;public void init(){showBtn = new Button( "Show Frame" );(1) ;}public boolean action( Event e, Object o ){if( e.target == showBtn ){if( (2) ){(3) ;frm.dispose();(4) ;showBtn.setLabel("Show myFrm");}else{frm = new Frame( "myFrm" );frm.resize( 200, 150 );frm.setBackground( Color.gray );(5) ;showBtn.setLabel("Hide myFrm");}}return true;}}ex8_7.htmlHTMLHEADTITLEex8_7/TITLE/HEADBODYapplet code="ex8_7.class" width=800 height=400 /applet/BODY/HTML

考题 import java.awt.*;  import java.applet.*;  public class ButtonDemo extends Applet{   public void init()  {    Button pushBotton=new Button(“ok”);    Button downBotton=new Button(“Yes”);     add(pushBotton);     add(downBotton);   } }  根据以上代码,下列结束正确的是()A、该代码画了一个按钮B、Button(“ok”)创建一个有显示”ok”的按钮C、Button()是构造函数D、按钮属于容器

考题 What will be the appearance of an applet with the following init() method?   public void init() {   add(new Button("hello"));  }  A、Nothing appears in the applet.B、A button will cover the whole area of the applet.C、A button will appear in the top left corner of the applet.D、A button will appear, centered in the top region of the applet.E、A button will appear in the center of the applet.

考题 多选题import java.awt.*;    import java.applet.*;    public class ButtonDemo extends Applet{    public void init(){  Button pushButton=new Button(“ok”);  Button downButton=new Button(“Yess”);  add(pushButton);  add(downButton);  }  }  根据以上代码,下列解释正确的是()A该代码画了一个按钮BButton(“ok”)创建了一个有显示“ok”的按钮CButton()是构造函数D按钮属于容器

考题 单选题What will be the appearance of an applet with the following init() method?   public void init() {   add(new Button("hello"));  }A Nothing appears in the applet.B A button will cover the whole area of the applet.C A button will appear in the top left corner of the applet.D A button will appear, centered in the top region of the applet.E A button will appear in the center of the applet.

考题 单选题在Java语言中,一个Applet具有如下init()方法: public void init(){  setLayout(new  BorderLayout());  add(BorderLayout.EAST,  new Button(“Click ME!”));} 当该Applet载入时,用户外观将是()。A 没有任何内容B 居中位置有个按钮C 左边有个按钮D 右边有个按钮E 一个按钮填充整个用户界面上