网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
下列说法哪个是正确的?()
- A、JFrame,JPanel,JApplet和JButton四种组件都属于容器组件
- B、JButton和JTextField都可用ActionListener接口实现事件处理
- C、一个面板(JPanel) 不能被加入到另一个面板(JPanel)中
- D、在BorderLayout中,添加到NORTH区的两个按钮将并排显示
参考答案
更多 “下列说法哪个是正确的?()A、JFrame,JPanel,JApplet和JButton四种组件都属于容器组件B、JButton和JTextField都可用ActionListener接口实现事件处理C、一个面板(JPanel) 不能被加入到另一个面板(JPanel)中D、在BorderLayout中,添加到NORTH区的两个按钮将并排显示” 相关考题
考题
请完成下列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);}}}
考题
本题的功能是用按钮来控制文本框中文本的颜色。窗口中有两个带有文字标题的面板“Sample text”和“Text color control”,窗口的底部还有一个复选按钮“Disable changes”。在“Sample text”面板中有一个带有字符串的文本框,而在“Text color control”面板中有三个按钮:“Black”、“Red”和“Green”,并且每个按钮上都有一个对应颜色的圆。单击任意按钮,文本框中的文本变成对应的颜色,如果选中“Disable changes”复选项,则三个颜色按钮变为不可用,如果取消选中复选项,则三个按钮变为可用。import javax.swing.*;import java.awt.*;import java.awt.event.*;public class java3 extends JFrame{private JPanel upper,middle,lower;private JTextField text;private JButton black,red,green;private JCheckBox disable;public java3(String titleText){super(titleText);addWindowListener(new WindowAdapter(){public voidwindowClosing(WindowEvent e){System.exit(0);}});upper=new JPanel();upper.setBorder(BorderFactory.ereateTitledBor-der("Sample text"));upper.setlayout(new BorderLayout());text=new JTextField("Change the color of thistext"):upper.add(text,BorderLayout.CENTER);middle=new JPanel();middle.setBorder(BorderFactory.createTitledBor-der("Text color control"));middle.setLayout(new FlowLayout(FlowLayout.CENTER)):black=new JButton("Black",new ColorIcon(Color.black));black.addActionListener( new ButtonListener(Color.black));middle.add(black);red=new JButton("Red",new ColorIcon(Col-or.red));red.addActionListener(new ButtonListener(Col-or.red));middle.add(red);green=new JButton("Green",new ColorIcon(Color.green));green.addActionListener(new ButtonListener(Color.green));middle.add(green);lower=new JPanel();lower.setLayout(new FlowLayout(FlowLayout.RIGHT));disable=new JCheckBox("Disable changes"):disable.addItemListener(new ItemListener()(public void itemStateChanged(ItemEvent e){boolean enabled=(e.getStateChange()= =ItemEvent.DESELECTED):black.setEnabled(enabled);red.setEnabled(enabled);green.setEnabled(enabled);}});lower.add(disable);Container cp=getContentPane();cp.add(upper,BorderLayout.NORTH);cp.add(middle,BorderLayout.CENTER);cp.add(10wer,BorderLayout.SoUTH);pack();setVisible(true);}class ButtonListener extends ActionListener{private Color c;public ButtonListener(Color c){this.c=c;}public void actionPerformed(ActionEvent e){text.setForeground(c);}}class ColorIcon implements Icon{private Color c;private static final int DIAMETER=10;public ColorIcon(Color c){c=c;}public void paintlcon(Component cp,Graphics g,int x,int y){g.setColor(c);g.fillOval(X,y,DIAMETER,DIAMETER);g.setColor(Color.black);g.drawOval(x,y,DIAMETER,DIAMETER);}public int getlconHeight(){return DIAMETER;}public int getlconWidth(){return DIAMETER;}}public static void main(String[]args){new java3("advance");}}
考题
下列哪个选项是创建一个标识有"关闭"按钮的语句?()A、JTextField b = new JtextField("关闭");B、JTextArea b = new JTextArea("关闭");C、JButton b = new Jbutton("关闭");D、JCheckbox b = new Jcheckbox("关闭");
考题
以下的代码是如何实现事件处理过程的?() 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
考题
现有: 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整个区域
考题
编写JButton组件的事件处理器类时,需实现哪个接口?() A、ItemListenerB、ActionListenerC、ButtonListenerD、WindowListener
考题
多选题以下的代码是如何实现事件处理过程的?() 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在事件处理类的构构造函数中,创建一个主框架对象,并显示该对象
考题
单选题下列关于程序运行结果的描述中,错误的是( )。import javax.swing.*;
import java.awt.*;
public class Test{
public static void main(String[]args){
JFrame f = new JFrame();
JPanel P=new JPanel();
f.setLayout(new BorderLayout());
f.getContentPane().add(p,"Center");
P.setBackground(Color.blue);
f.setVisible(true);
f.setSize(200,200);
}
}A
程序不能运行B
显示一个窗口C
窗口大小是200×200D
窗口背景为蓝色
考题
单选题下列说法哪个是正确的?()A
JFrame,JPanel,JApplet和JButton四种组件都属于容器组件B
JButton和JTextField都可用ActionListener接口实现事件处理C
一个面板(JPanel) 不能被加入到另一个面板(JPanel)中D
在BorderLayout中,添加到NORTH区的两个按钮将并排显示
考题
判断题JFrame,JPanel,JApplet和JButton四种组件都属于容器组件。A
对B
错
热门标签
最新试卷