网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
(GUI容器)jframe是JFrame类的对象,调用jframe.getContentPane().add(jbutton)能实现向jframe中添加jbutton(JButton的对象)。
参考答案和解析
正确
更多 “(GUI容器)jframe是JFrame类的对象,调用jframe.getContentPane().add(jbutton)能实现向jframe中添加jbutton(JButton的对象)。” 相关考题
考题
( 30 )下列叙述中错误的是A ) JButton 类和标签类叫湿勿丈图标和又本B ) Button 类和标签类可显示图标和文本C ) AWT 构件能直接添加到顶层容器中D ) Swing 构件不能接添加到顶层容器中
考题
下列代码的功能是把按钮save添加到窗口myFrame的中间,在空白处应填入的代码是______。import Javax.swing.*;public calss MyFrame{public static void main(String args[]){JFrame. myFrame=new JFrame();JButton save=new JButton("Save");myFrame.getContentPane()add(save,"______");myFrame.setSize(200,200);myFrame.setVisible(true);}}
考题
请完成下列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);}}
考题
现有:packagemypack;importjava.awt.Color;importjava.awt.FlowLayout;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JPanel;publicclassButtListextendsJFrame{publicstaticvoidmain(String[]args){ButtListbl=newButtList();}ButtList(){JPanelpl=newJPanel();pl.setBackground(Color.pink);p1.add(newJButton(one));p1.add(newJButton(Two));p1.add(newJButton(Three));add(South,p1);setLayout(newFl.wLayout());setSize(200,200);setVisible(true);}}上述代码运行后的显示效果是哪项?()
考题
现有:packagemypack;importjavax.swing.JButton;importjavax.swing.JFrame;publicclassButtextendsJFrame{publicstaticv.idmain(string[]args){//TODOAuto-generatedmethodstubButtbutt=newButt();}Butt(){JButtonjbl=newJButton(Hello);JButtonjb2=newJButton(World);add(jbl);add(jb2);setSize(300,300);setVisible(true);}}下列关于代码运行效果的叙述正确的是哪项?()A.2个按钮紧靠着排列,Hello在World的左侧B.Hello占据Frame的整个区域C.World占据Frame的整个区域D.2个按钮都在Frame的顶部
考题
请完成下列Java程序:用一个边框布局来安排一个工具栏和一个卡片布局。工具栏可浮动,包括2个按钮,一个向前一个向后控制卡片的显示;卡片布局包括3张卡片,分别标识为card1,card2,card3。注意;请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border. LineBorder;public class ex24_2{private static CardLayout cl=new CardLayout();private static JPanel cp=new JPanel();public static void main(String[] args){JFrame. if=new JFrame();jf.setTitle("ex24_2");Container c=jf.getContentPane();JToolBar jtb=new JToolBar();JButton btnNext=new JButton(new ImageIcon("next.gif"));JButton btnPre=new JButton(new ImageIcon("back.gif"));jtb.add(btnPre);jtb.add(btnNext);cp.setLayout(cl);Dimension dim=new Dimension(150,80);cp.setPreferredSize(dim);cp.setBorder(new LineBorder(Color. BLACK));cp.add(new JLabel("cardl",JLabel.CENTER),"card1");cp.add(new JLabel("card2",JLabel.CENTER),"card2");cp.add(new JLabel("card3",JLabel.CENTER),"card3");c.add(jtb,BorderLayout.NORTH);c.add(cp,BorderLayout.CENTER);ActionListener al=new ActionResponse();____________________________________;____________________________________;jf.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent we){System.exit(0);}});jf.pack();jf.setVisible(true);}static class ActionResponse implements ActionListener{public void actionPerformed(ActionEvent ae){if(ae.getActionCommand().equals("next"))cl.next(cp);elsecl.previous(cp);}}}
考题
本题的功能是用按钮来控制文字的颜色。窗口中有三个按钮“Yellow”、“Blue”和“Red”,它们分别对应文字标签中文本的颜色为黄色、蓝色和红色,单击任意一个按钮,文字标签中的文本就变成按钮对应的颜色。 import java.awt.*; import java.awt.event.*; import javflx.swing.*; class ButtonPanel extends JPanel implements ActionL- istener{ public ButtonPanel{ yellowButton=new J Button("Yellow"); blueButton=new JButton("Blue"); redButton=new JButton("Red"); j1=new JLabel("I am from China!"); add(yellowButton); add(blueButton); add(redButton); add(j1); yellowButtofl.addActionListener(this); blueButton.addActionListener(this); redButton.addActionListener(this); } public void actionPerformed(ActionEvent evt){ 0bject source=evt.getSource; Color color=getForeground; if(source= =yellowButton)color=Color. yellow; else if(source= =blueButton)color=Color. blue; else if(source= =redButton)color= Color.red; ; ; } private JButton yellowButton; private JButton blueButton; private JButton redButton; private JLabel jl; } class ButtonFrame. extends JFrame{ public ButtonFrame{ setTitle("exam l6"); setSize(300,200); addWindowListener(new WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(O); } }); Container contentPane=getContentPane; contentPane.add(new ButtonPanel); } } public class java2{ public static void main(String[]args){ JFrame. frame=new ButtonFrame; frame.show; } }
考题
请完善程序(程序文件名: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;}
考题
本题的功能是展示4种不同的对话框。窗口中有4个按钮:“消息”、“输入”、“确定”和“选择”,单击任意一个按钮,就能弹出一个对应的对话框。其中,消息对话框只有一个提示信息和一个“确定’’按钮,输入对话框有一个供输入的文本框及“确定”和“撤销”两个按钮;确定对话框中有一个提示信息和三个按钮“是”、“否”和“撤销”;而选择对话框中有一个提示信息和两个按钮“确定,,和“取消”。import javax.swin9.*:import java.awt.event.*;import java.awt.*;Public class java3 extends JFrame. implements ButtonSelecte ActionListener{JButton btnMessage=new JButton("消息");JButton btnlnput=new JButton("输入");JButton btnConfirm=new JButton("确认");JButton btnOption=new JButton("选择");public java3(){super("java3");btnMessage.addActionListener(this);btnlnput.addActionListener(this);btnConfirm.addActionListener(this);btnOption.addActionListener(this);getContentPane().setLayout( new FIowLavout()):getContentPane().add(btnMessage);getContentPane().add(btnlnput):getContentPane().add(btnConfirm):getContentPane().add(btnOption);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});}public static void main(String args[]){java3 fr=new java3();fr.pack();fr.setVisible(true);}Public void actionperformed(ActionEvent e){Object[]opt={"确认","取消");JButton instance:(JButton)e.getObject();if(instance= =btnMessage)JOptionPane.showMessageDialog(this,"消息对话框");else if(instance= =btnInput、JOptionPane.showInputDialog(this,"输入对话框");else if(instance= =btnConfirm、JOptionPane.showConfirmDialog(this,"确认对话框");elseJOptionPane.showOptionDialog(this,"选择对话框","选择",JOptionPane.YES_OPTION,JOptionPane.QUESTION_MESSAGE,null,opt,opt[1]);}}
考题
以下的代码是如何实现事件处理过程的?() class HelllWordFrame_jButton4_actionAdapter implements ActionListener { HelloWorldFrame adaptee; HelloworldFrame_jButton4_actionAdapter(HelloWorldFrame adaptee){ this.adaptee=adaptee;} public void actionPerformed(ActionEvent e){ adaptee,jButton4_actionPerfomed(e);} }A、在事件处理类的actionPerformed函数中,调用主框架的对应函数进行处理B、事件处理类实现了ActionListener接口C、主框架作为事件处理类的一部分,包括在事件处理类中D、在事件处理类的构造函数中将主框架的引用变量传递给事件处理类E、在事件处理类的构构造函数中,创建一个主框架对象,并显示该对象
考题
以下关于GUI容器缺省布局管理器的叙述,哪项正确?() A、JPanel容器的缺省布局管理器是FlowLayoutB、JPanel容器的缺省布局管理器是BorderLayoutC、JFrame容器的缺省布局管理器是FlowLayoutD、JFrame容器的缺省布局管理器是GridLayout
考题
下列说法哪个是正确的?()A、JFrame,JPanel,JApplet和JButton四种组件都属于容器组件B、JButton和JTextField都可用ActionListener接口实现事件处理C、一个面板(JPanel) 不能被加入到另一个面板(JPanel)中D、在BorderLayout中,添加到NORTH区的两个按钮将并排显示
考题
在Swing GUI编程中,setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE)语句的作用是:() A、当执行关闭窗口操作时,不做任何操作。B、当执行关闭窗口操作时,调用WindowsListener对象并将隐藏JFrameC、当执行关闭窗口操作时,退出应用程序D、当执行关闭窗口操作时,调用WincowsListener对象并隐藏和销毁Jframe
考题
单选题现有: package mypack; import javax.swing.JButton; import javax.swing.JFrame; public class Butt extends JFrame { public static v.id main(string[] args) { // TODO Auto-generated method stub Butt butt=new Butt(); } Butt(){ JButton jbl=new JButton("Hello"); JButton jb2=new JButton("World"); add(jbl); add(jb2); setSize(300,300); setVisible(true); } } 下列关于代码运行效果的叙述正确的是哪项? ()A
2个按钮紧靠着排列,Hello在World的左侧B
Hello占据Frame的整个区域C
World占据Frame的整个区域D
2个按钮都在Frame的顶部
考题
多选题以下的代码是如何实现事件处理过程的?() class HelllWordFrame_jButton4_actionAdapter implements ActionListener { HelloWorldFrame adaptee; HelloworldFrame_jButton4_actionAdapter(HelloWorldFrame adaptee){ this.adaptee=adaptee;} public void actionPerformed(ActionEvent e){ adaptee,jButton4_actionPerfomed(e);} }A在事件处理类的actionPerformed函数中,调用主框架的对应函数进行处理B事件处理类实现了ActionListener接口C主框架作为事件处理类的一部分,包括在事件处理类中D在事件处理类的构造函数中将主框架的引用变量传递给事件处理类E在事件处理类的构构造函数中,创建一个主框架对象,并显示该对象
考题
单选题现有: package mypack; import java.awt.Color; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class ButtList extends JFrame { public static void main(String[] args) { ButtList bl =new ButtList(); } ButtList(){ JPanel pl=new JPanel(); pl.setBackground (Color.pink); p1.add(new JButton("one")); p1.add(new JButton("Two")); p1.add(new JButton("Three")); add("South",p1); setLayout(new Fl.wLayout()); setSize(200,200); setVisible(true); } } 上述代码运行后的显示效果是哪项?()A
3个按钮从左到右排列在Frame的底部B
3个按钮从左到右排列在Frame的顶部C
按钮无法显示D
只有按钮Three显示出来并占据Frame整个区域
考题
单选题在Swing GUI编程中,setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE)语句的作用是:()A
当执行关闭窗口操作时,不做任何操作。B
当执行关闭窗口操作时,调用WindowsListener对象并将隐藏JFrameC
当执行关闭窗口操作时,退出应用程序D
当执行关闭窗口操作时,调用WincowsListener对象并隐藏和销毁Jframe
考题
单选题在Swingensp;GUI编程中, setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) 语句的作用是()A
当执行关闭窗口操作时,不做任何操作。B
当执行关闭窗口操作时,调用WindowsListener对象并将隐藏JFrameC
当执行关闭窗口操作时,调用WindowsListener对象并隐藏和销毁JFrameD
当执行关闭窗口操作时,退出应用程序。
考题
判断题JFrame,JPanel,JApplet和JButton四种组件都属于容器组件。A
对B
错
热门标签
最新试卷