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 GridLayout (2,2));   Panel p1 = new panel();    Add(p1);    Button b1= new Button (“One”);    P1.add(b1);   Panel p2 = new panel();    Add(p2);   Button b2= new Button (“Two”);    P2.add(b2);    Button b3= new Button (“Three”);   add(b3);   Button b4= new Button (“Four”);   add(b4);   )   )   Which two statements are true? ()A、 All the buttons change height if the frame height is resized.B、 All the buttons change width if the Frame width is resized.C、 The size of the button labeled “One” is constant even if the Frame is resized.D、 Both width and height of the button labeled “Three” might change if the Frame is resized.

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 GridLayout (2,2));   Panel p1 = new panel();    Add(p1);    Button b1= new Button (“One”);    P1.add(b1);   Panel p2 = new panel();    Add(p2);   Button b2= new Button (“Two”);    P2.add(b2);    Button b3= new Button (“Three”);   add(b3);   Button b4= new Button (“Four”);   add(b4);   )   )   Which two statements are true? ()

  • A、 All the buttons change height if the frame height is resized.
  • B、 All the buttons change width if the Frame width is resized.
  • C、 The size of the button labeled “One” is constant even if the Frame is resized.
  • D、 Both width and height of the button labeled “Three” might change if the Frame is resized.

相关考题:

public class X extends Frame{public static void main(String[] args){X x=new X();x.pack();x.setVisible(true);}public X(){setLayout(new GridLayout(2,2));Panel p1=new Panel(); add(p1);Button b1 A.all change height and widthB.Button One change heightC.Button Two change height and Button Three change widthD.Button Four change height and width

本题的功能是监听键盘敲击事件,并将敲击的字符显示在标签上。开始,文字标签提示“Please press your keyboard!”,当按下键盘上的字符键,文字标签就变为“*ispressed!”(*为所按字母)。 import java.awt.*; import java.awt.event*’; import javax.swing.*; public class java2 extends Frame { Dublic 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); lab=new Label("Please press your keyboard!"); add(lab); addKeyListener(this); setVisible(true); } public void keyTyped(KeyEVent e){ lab.setText("\"+ +"\ is pressed!"); repaint; } public void keyPressed(KeyEVent e){ ) public void keyReleased(KeyEvent e){ } private Label lab; }

本题中,主窗口有一个按钮“显示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; }

本程序的功能是读取用户输入的整数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);}}

选择正确的叙述. class Happy extends Frame. { Happy() { SetLayout(new GridLayout(2,2)); Panel p1 = new Panel(); add(p1); p 1.add( new Button("One")); Panel p2 = new Panel(); add(p2); p 2.add( new Button("Two")); add( new Button("Three")); add( new Button("Four")); s()A.当frame调整大小时,按钮Three和Four 的大小也将调整。B.当frame调整大小时,所有按钮的大小都将调整。C.当frame调整大小时,按钮Two和Four 的大小也将调整。D.当frame调整大小时,按钮One和Two 的大小也将调整。

下列程序使用CardLayout管理了2张卡片,每张都是一个Panel,每个Panel有一个Button,单击按钮,显示下一张卡片中的内容。请将程序补充完整。注意:不改动程序结构,不得增行或删行。import java.awt.*;import java.awt.event.*;public class ex3 implements______{private Panel p1,p2;private Button btn1,btn2;private Frame. frm;private CardLayout cl;public static void main(String[] args){ex3 tt=new ex3();tt.method();}public void method(){Frm=new Frame("CardLayout");Cl=new CardLayout();btn1=new Button("Card1");btn2=new Button("Card2");pl=new Panel();p2=new Panel();p1.add(btn1);btn1.addActionListener(this);p2.add(btn2);______frm.SetLayout(cl);frm.add(pl,"Layer1");frm.add(pl,"Layer1");frm.SetSize{200,200);frm.SetVisible(true);}public void actionPerformed(ActionEvent ae){______}}

下列程序用GridLayout布局管理器将Frame分为1行3列,并放入Button构件,横线处应填入的语句是( )。 import java.awt.*; public class Test { public static void main (String[] args) { Frame. frm=new Frame. ("GridLayout"); ____________ frm.add (new Button("Button1")); frm.add (new Button("Button2")); frm.add (new Button("Button3")); frm.setSize (300,300); frm.setVisible (true); } }A.frm.setLayout (GridLayout (1,3));B.setLayout (new GridLayout(1,3));C.frm.setLayout (new GridLayout(3,1));D.frm.setLayout (new GridLayout(1,3));

阅读下面代码:import java.awt.*;public class Exam11_1{private Frame. f;private Button b1,b2,b3,b4;public static void main(String args[]{Exam11_1 that = new Exam11 1 ();that.go();}public void go(){______;f.setLayout(new FlowLayout()) ;;b1 = new Button ("Button 1");b2 = new Button ("Button 2");b3 = new Button ("Button 3");b4 = new Button ("Button 4");f.add (b1);f.add (b2);f.add (b3);f.add (b4);f.pack ();f.setVisible (true);}}请在程序中画线处填写正确的语句【 】,以便编译运行程序后得到正确的结果。

下列程序在Frame中设定BorderLayout布局管理器,选择正确的语句填入程序的横线处。 import java.awt.*; public class ex43 extends Frame { public static void main(String[] args) { ex43 bj = new ex43("BorderLayout"); ______ obj.add("North", new Button("North")); obj.add("South", new Button("Sourth")); obj.add("East", new Button ("East")); obj.add("West", new Button ("West")); obj. add ("Center", new Button ( "Center" ) ); obj.pack(); obj. setVisible (true); } public ex43(String str) { super (str); } }A.obj.setLayout(new BorderLayout());B.setLayout(new Borderkayout());C.setLayout(BorderLayout());D.obj.setLayout(BorderLayout());

interface A{int x = 0;}class B{int x =1;}class C extends B implements A {public void pX(){System.out.println(x);}public static void main(String[] args) {new C().pX();}}

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

下列程序采用BorderLayout布局管理,选择正确的语句填入横线处,实现在North区域显示一个名字为“北方”的Button构件。 import java.awt.*; public class ex48 { public static void main(String[] args) { frame. frm = new Frame. ("北方"); frm.setLayout(new BorderLayout()); frm.setSize(200, 200); frm.setVisible(true); } }A.add("Nouth", new Button("北方"));B.frm.add("South", new Button("北方"));C.frm.add("Nouth", new Button("北方"));D.Frm.add("South", Button("北方"));

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

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

本题使用下拉菜单来控制字体,窗口中有一个标签和一个下拉菜单,当选中下拉菜单中的任一项字体时,标签上字符串的字体就随之改变。import java.awt.*;import java.awt.event.*;import javax.swing.*;class ComboBoxFrame. extends JFrame. {public ComboBoxFrame(){setTitle("java2");setSize(300,200);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});style=new JComboBox():style.setEditable(true);style.addhem("Serif");style.addItem("SansSerif");style.addhem("Monospaced");style.addhem("Dialog");style.addhem("Dialoglnput");style.addActionListener(this);JPanel p=new JPanel();P.add(style);getContentPane().add(p,"South");panel=new ComboBoxTestPanel();getContentPane().add(panel,"Center");}public void actionPerformed(ActionEvent evt){JComboBox source=(JComboBox) ;String item=(String)source.getSelectedhem():panel.setStyle(item);}private ComboBoxTestPanel panel;private JComboBox style;}class ComboBoxTestPanel extends JPanel{public ComboBoxTestPanel(){setStyle("Serif");}public void setStyle(String s){setFont(new Font(S,Font.PLAIN,12));repaint();}public void paintComponent(Graphics g){super.paintComponent(g);9.drawString("Welcome to China!",0,50);}}public class java2{public static void main(String[]args){JFrame. frame=new ComboBoxFrame();frame.show();}}

以下程序调试结果为:public class Test {int m=5;public void some(int x) {m=x;}public static void main(String args []) {new Demo().some(7);}}class Demo extends Test {int m=8;public void some(int x) {super.some(x);System.out.println(m);}}A.5B.8C.7D.无任何输出E.编译错误

现有:  class Top  {     static int X=l;  public Top()  {  x*=3; }     }  class Middle extends Top  {      public  Middle()    {x+=l;  }  public static void main(String  []  args)  {     Middle m=new Middle();    System.out.println (x);    }     }  结果是什么?()    A、  2B、  3C、  4D、编译失败

Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?()   class A {}   class B extends A {}   class C extends A {}   public class Q3ae4 {   public static void main(String args[]) {   A x = new A();   B y = new B();   C z = new C();   // insert statement here   }   } A、x = y;B、z = x;C、y = (B) x;D、z = (C) y;E、y = (A) y;

public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()  A、 A doneB、 B doneC、 A done B doneD、 B done A doneE、 There is no exception that the application will print anything.F、 The application outputs “A done” and “B done”, in no guaranteed order.

Given the following code, which code fragments, when inserted at the indicated location, will succeed in making the program display a button spanning the whole window area?()   import java.awt.*;   public class Q1e65 {   public static void main(String args[]) {   Window win = new Frame();   Button but = new Button("button");   // insert code fragment here  win.setSize(200, 200);   win.setVisible(true);   }   }  A、win.setLayout(new BorderLayout()); win.add(but);B、win.setLayout(new GridLayout(1, 1)); win.add(but);C、win.setLayout(new BorderLayout()); win.add(but, BorderLayout.CENTER);D、win.add(but);E、win.setLayout(new FlowLayout()); win.add(but);

class Top {  static int x = 1;  public Top(int y) { x *= 3; }  }  class Middle extends Top {  public Middle() { x += 1; }  public static void main(String [] args) {  Middle m = new Middle();  System.out.println(x);  }  }  结果为:() A、1B、2C、3D、编译失败

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.

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? () A、 The code will not compile.B、 A Window will appear containing only a Button.C、 An IllegalArgumentException is thrown at line 6.D、 A Window button will appear but will not contain the Label, TextField, or Button.E、 A Window will appear containing a Label at the top, a TextField below the Label, and a Button  below the TextField.F、 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.

单选题public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()A A doneB B doneC A done B doneD B done A doneE There is no exception that the application will print anything.F The application outputs “A done” and “B done”, in no guaranteed order.

单选题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? ()A The code will not compile.B A Window will appear containing only a Button.C An IllegalArgumentException is thrown at line 6.D A Window button will appear but will not contain the Label, TextField, or Button.E A Window will appear containing a Label at the top, a TextField below the Label, and a Button  below the TextField.F 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.

单选题Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?()   class A {}   class B extends A {}   class C extends A {}   public class Q3ae4 {   public static void main(String args[]) {   A x = new A();   B y = new B();   C z = new C();   // insert statement here   }   }Ax = y;Bz = x;Cy = (B) x;Dz = (C) y;Ey = (A) y;

单选题现有:  class Top  {     static int X=l;  public Top()  {  x*=3; }     }  class Middle extends Top  {      public  Middle()    {x+=l;  }  public static void main(String  []  args)  {     Middle m=new Middle();    System.out.println (x);    }     }  结果是什么?()A  2B  3C  4D编译失败