2021年计算机二级《JAVA》考前非选择题练习 修订

上传人:黯然****空 文档编号:149335383 上传时间:2020-10-26 格式:PDF 页数:6 大小:7.68KB
返回 下载 相关 举报
2021年计算机二级《JAVA》考前非选择题练习 修订_第1页
第1页 / 共6页
2021年计算机二级《JAVA》考前非选择题练习 修订_第2页
第2页 / 共6页
亲,该文档总共6页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《2021年计算机二级《JAVA》考前非选择题练习 修订》由会员分享,可在线阅读,更多相关《2021年计算机二级《JAVA》考前非选择题练习 修订(6页珍藏版)》请在金锄头文库上搜索。

1、2020 年计算机二级 JAVA 考前非选择题练习 二、基本操作题 本题提示输入年份,然后判断该年份是否为闰年。 importjava.io.*; public class javal public static void main(Stringargs) InputStreamReader ir; BufferedReader in; ir=new InputStreamReader(System.in); in=new BufferedReader(ir); int year=1900; System.out.print(请输入年份: ); try String s=in.readLine

2、(); ; (Exception e) if( ) System.OUt.println(year+是闰年 ); else System.out.println(year+不是闰年 ); 三、简单应用题 本题使用下拉菜单来控制字体,窗口中有一个标签和一个下拉菜 单,当选中下拉菜单中的任一项字体时,标签上字符串的字体就随之 改变。 import java.awt.*; import java.awt.event.*; import javax.swing.*; class ComboBoxFrame extends JFrame public ComboBoxFrame() setTitle(j

3、ava2); 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

4、.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(ite

5、m); 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(W

6、elcome to China!,0,50); public class java2 public static void main(Stringargs) JFrame frame=new ComboBoxFrame(); frame.show(); 四、综合应用题 本题是一个 Applet ,功能是监听用对于文本域中文本的选择。页 面中有一个文本域、一个“复制”按钮和一个文本框,选中文本域中 部分文字后,单击按钮“复制”,所选文字将显示在文本框中。 import java.applet.Applet; import java.awt.*; import java.awt.event.*;

7、public class java3 extends Applet implements ActionL- istener TextArea ta=new TextArea(5,30); TextField tf=new TextField(30); Button button=new Button(复制); String text=AWT提供基本的 GUl组件,n+ 具有能够扩展的超类, n+ 它们的属性是继承的。 n: public void init() setLayout(new FlowLayout(FlowLayout.left); ta.setText(text); ta.setEditable(true); add(ta); add(button); add(tf); ta.addActionListener(this); public void actionPerformed(ActionEvent e) String S; s=ta.getSelectText(); if(e.getSource()= =button) tf.setText(s);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > PPT模板库 > 总结/计划/报告

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