2022年计算机二级考试JAVA练习试题及答案3.docx

上传人:夏** 文档编号:542944260 上传时间:2023-06-10 格式:DOCX 页数:4 大小:12.58KB
返回 下载 相关 举报
2022年计算机二级考试JAVA练习试题及答案3.docx_第1页
第1页 / 共4页
2022年计算机二级考试JAVA练习试题及答案3.docx_第2页
第2页 / 共4页
2022年计算机二级考试JAVA练习试题及答案3.docx_第3页
第3页 / 共4页
2022年计算机二级考试JAVA练习试题及答案3.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《2022年计算机二级考试JAVA练习试题及答案3.docx》由会员分享,可在线阅读,更多相关《2022年计算机二级考试JAVA练习试题及答案3.docx(4页珍藏版)》请在金锄头文库上搜索。

1、 2022年计算机二级考试JAVA练习试题及答案3三、简洁应用题(共24分)此题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif”和“Windows”,单击任何一个按钮,就能将窗口的风格转变为按钮名称所对应的风格。import javaawt*;import javaawtevent.*;import javaxswing*;class PlafPanel extends JPanel implements ActionLis-tenerpublic ()metaIButton=new JButton(“Metal“);motifButtOn=new J B

2、utton(“Motif“);windowsButton=new JButton(“Windows“);add(metalButton);add(motifButton);add(windowsButton);metalButtonaddActionListener(this);motifButtonaddActionListener(this);windowsButtonaddActionListener(this);Dublic void actionPerformed(ActionEvent evt)Object source=evtgetSource();String plaf=“:i

3、f(source= =metalButton)plaf=“javaxswingplafmetalMetalLookAnd-Feel“;else if(source= =motifButton)plaf=“comsunjavaswingplafmotifMoti-fLookAndFeel“;else if(source= =windowsButton)Dlaf=“comsunjavaswingplafwindowsWin-dowsLookAndFeel“;tryUIManagersetLookAndFeel( );SwingUtilitiesupdateComponentTreeUI(this)

4、;catch(Exception e)private JButton metalButton;private JButton motifButton;private JButton windowsButton;class PlafFrame extends JFramepublic PlafFrame() setTitle(“simple“);setSize(300,200);addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)Systemexit(O););Container contentPane=getContentPane();contentPaneadd(new PlafPanel();public class java2public static void main(Stringargs)f JFrame frame=new PlafFrame();frameshow(); 三、简洁应用题第1处:PlafPanel第2处:plaf【解析】第一处由题意可知,类PlafPanel缺少构造函数,所以填PlafPanel。其次处是通过String类型的对象plaf,和UIManagersetLookAndFeel()方法实现显示风格的切换。

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号