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

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

请完成下列Java程序:用JFrame建立一个窗口,再用网格布局管理器,对窗口布局进行控制,上面有2行2列4个按钮,要求对按钮的大小进行设定,宽度为150,高度为80。

注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。

程序运行结果如下:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class ex9_2{

public static void main(String[]args) {

JFrame. frm:new JFrame();

frm.setTitle("ex9_2");

Container cont = frm.getContentPane();

_____________;

cont.add(new JButton("button1"));

cont.add(new JButton("button2"));

Dimension dimen=____________;

JButton btn1 = new JButton("button3");

btn1.setPreferredSize(dimen);

cont.add(btn1);

cont.add(new JButton("button4"));

frm.addWindowListener(new WindowAdapter() {

public void winowClosing(WindowEvent we){

System.exit(0);

}

});

frm.pack();

frm.setVisible(true);

}

}


参考答案

更多 “ 请完成下列Java程序:用JFrame建立一个窗口,再用网格布局管理器,对窗口布局进行控制,上面有2行2列4个按钮,要求对按钮的大小进行设定,宽度为150,高度为80。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:import java.awt.*;import java.awt.event.*;import javax.swing.*;public class ex9_2{public static void main(String[]args) {JFrame. frm:new JFrame();frm.setTitle("ex9_2");Container cont = frm.getContentPane();_____________;cont.add(new JButton("button1"));cont.add(new JButton("button2"));Dimension dimen=____________;JButton btn1 = new JButton("button3");btn1.setPreferredSize(dimen);cont.add(btn1);cont.add(new JButton("button4"));frm.addWindowListener(new WindowAdapter() {public void winowClosing(WindowEvent we){System.exit(0);}});frm.pack();frm.setVisible(true);}} ” 相关考题
考题 当JFrame的大小被改变时JFrame中的按钮的位置可能被改变,使用的哪一个布局管理器() A.BorderLayoutB.FlowLayoutC.CardLayoutD.GridLayout

考题 请完成下列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程序:用JFrame建立—个窗口,再用网格布局管理器,对窗口布局进行控制,上面有2行2列4个按钮,要求对按钮的大小进行设定,宽度为150,高度为80。注意:请勿改动main主方法和其他已有语句内容,仅在下划线处填入适当的语句。源程序文件代码清单如下import java.awt.*;import java.awt.event.*;import javax.swing.*;public class ex19_2{public static void main(String args[])}JFrame. frm=new JFrame();frm.setTitle("ex19_2");Container cont=frm.getContentPane();______;cont.add(new JButton("button1"));cont.add(new JButton("button2 "));Dimension dimen=______;JButton btn1=new JButton("button3");btn1.setPreferredSize(dimen);cont.add(btn1);cont.add(new JButton("button4"));frm.addWindowListener(new WindowAdapter(){public void winowClosing(WindowEvent we){System.exit(0);}});frm.pack();frm.setVisible(true);}}

考题 请完成下列Java程序:记录鼠标在窗口中的信息,包括鼠标的移动事件以及鼠标在窗口中的位置坐标,要求在窗口下方显示鼠标的事件和位置信息,在窗口上方有按钮控制程序的正常退出。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。源程序文件代码清单如下:import java.awt.*;import java.awt.event.*;public class ex12_2extends Frame. implements MouseMotionListener, ActionListenerprivate Label 1;private String str=" ";public static void main(String args[]){new ex12_2();}ex12_2( ){______;setSize(200,200);Button btn=new Button("exit");btn.addActionListener (this);add (btn, "North" );l=new Label(str);add (l, "South" );show ();}public void mouseMoved(MouseEvent event){str="Move: "+l. setText (str);}public void mouseDragged(MouseEvent event){}public void actionPerformed(ActionEvent event){if(event.getActionCommand().equals("exit")){System.exit(0);}}}

考题 请完成下列Java程序。实例listener是监听器,frm是事件源,fr上发生的事件委托tat进行处理。程序的执行结果是显示一个蓝色的窗口,单击关闭按钮,可关闭窗口。注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。源程序文件代码清单如下:import java.awt.*;import java.awt.event.*;public class BlueWindow{public static void main(String args[]){Frame. frm=new Frame. ("欢迎参加Java考试!");TheAdapterTest listener=new TheAdapterTest();frm. ______;frm.setSize(200,200);frm.setBackground(Color.blue);frm. ______;}}class TheAdapterTest extends WindowAdapter{public void windowClosing(WindowEvent e){System.exit(1);}}

考题 下列哪个布局管理器中的按钮位置有可能会根据JFrame的大小改变而改变( )。 A、FlowLayoutB、GridLayoutC、CardLayoutD、BorderLayout

考题 请完成下列Java程序。程序的输出结果:a=6,b=5。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:public class ex38_2{public static void main(String args[]){int a=5,b=6;a=_________;b=a-b;a=_________;System.out.println("a="+a+"\tb="+b);}}

考题 设计一个用户登录界面,无须设置事件处理过程(仅做界面设计)。要求主窗口为边界布局,北区放置欢迎语,中区放置两个标签和两个文本框,南区放置两个按钮。

考题 设计一个用户登录界面,无须设置事件处理过程(仅做界面设计)。要求主窗口为边界布局,北区放置欢迎语,中区放置两个标签和两个文本框,南区放置两个按钮。 评分指导:每有一个按钮放错位置可扣3分