【计算机类职业资格】计算机二级JAVA-145及答案解析.doc
《【计算机类职业资格】计算机二级JAVA-145及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】计算机二级JAVA-145及答案解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、计算机二级 JAVA-145及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.本题程序的功能是计算 110(包括 1和 10)中除 5以外各个自然数的和。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。 public class basic public static void main (String args) int i = 1; int sum = 0; while(i = 10) if(i = 5) _; _; _; i+; System.out.println (“sum=“+sum); (分数:30.00)
2、_二、2简单应用题(总题数:1,分数:40.00)2.本题程序的功能是通过滑动条修改颜色的 RGB值,从而控制颜色。程序中有一个面板、3 个标签和 3个滑动条,标签和滑动条一一对应,分别对应三原色红、绿、蓝,任意拖动其中的一个滑动条,所对应的颜色值就会发生变化,面板的颜色也会对应地发生变化。滑动条值的范围是 0255。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class simple extends JFrame imple
3、ments AdjustmentListener public simple() setTitle(“simple“); setSize(300,200); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit (0); ); Container contentPane =_; JPanel p = new JPane1(); p.setLayout(new GridLayout(3,2); p.add(redLabel = new JLabel(“Red 0“);
4、p.add(red = new JScrollBar(Adjustable.HORIZONTAL,0,0,0,255); red.setBlockIncrement(16); red.addAdjustmentListener(this); p.add(greenLabel = new JLabel(“Green 0“); p.add(green = new JScrollBar(Adjustable.HORIZONTAL,0,0,0,255); green.setBlockIncrement(16); green.addAdjustmentListener(this); p.add(blue
5、Label = new JLabel(“Blue 0“); p.add(blue = new JScrollBar(Adjustable.HORIZONTAL,0,0,0,255); blue.setBlockIncrement(16); blue.addAdjustmentListener(this); contentPane.add(p,“South“); colorPanel = new JPanel(); colorPanel.setBackground(new Color(0,0,0); contentPane.add(colorPanel,“Center“); public voi
6、d adjustmentValueChanged(AdjustmentEvent evt) redLabel.setText(“Red “ + red.getValue(); greenLabel.setText(“Green “ + green.getValue(); blueLabel.setText(“Blue “ + blue.getValue(); colorPanel.setBackground(new Color(red.getValue().green.getValue(),blue.getValue(); _; public static void main(String a
7、rgs) JFrame f = new simple(); f.show(); private JLabel redLabel; private JLabel greenLabel; private JLabel blueLabel; private JScrollBar red; private JScrollBar green; private JScrollBar blue; private JPanel colorPanel; (分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.本题程序的功能是监听对于列表项的操作。窗口中有一个列表和“添加”、“删除”和“关闭”三
8、个按钮。单击“添加”按钮,会在当前所选列表项后添加一个名为“新增表项”的列表项,同时后台输入列表中的表项数量。单击“删除”按钮,如果未选中表项,则弹出提示消息框“请选择表项”,否则将选中的表项删除,同时后台输出删除表项的内容和列表中的表项数量。单击“关闭”按钮退出程序。程序中存在若干错误,请找出并改正(注意:不得改动程序的结构,不得增行或删行)。 import java.awt.*; import java.awt.event.*; import javax.swing.JOptionPane; public class advance public static void main(Stri
9、ng args) final Frame frmFrame = new Frame(); Panel pnlPanel1 = new Panel(); Panel pnlPanel2 = new Panel(); final List istList = new List(8); for(int i = 0; i 10; i+) String strName = “表项“ + (new Integer(i+1).toString(); istList.add( strName ); Button btnButton1 = new Button(“添加“); Button btnButton2
10、= new Button(“删除“); Button btnButton3 = new Button(“关闭“); btnButton1.addActionListener( new ActionListener() publiC void actionPerformed(ActionEvent e) lstList.add(“新增表项“,istList.getSelected()+1); System.out.println(“列表中的表项数量“ + istList,getItemCount() ); ); btnButton2.addActionListener (new ActionLi
11、stener () public void actionPerformed(ActionEvent e) if(istList.getSelected() = null) JOptionPane.showMessageDialog(frmFrame,“请选择表项“); return; System.out.println(“删除表项的内容:“+ istList,getSelectedItem(); istList.delete(istList.getSelectedIndex(); System.out.println(“列表中的表项数量: “ + istList,getItemCount (
12、); ); btnButton3.addActionListener(new ActionListener () public void actionPerformed(ActionEvent e) System.exit (0); ); pnlPanel1 .add (istList); pnlPanel2 .add (btnButton1); pnlPanel2 .add (btnButton2); pnlPanel2,add (btnButton3); frmFrame.add(“North“,pnlPanel1); frmFrame.add(“South“,pnlPanel2); fr
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 JAVA145 答案 解析 DOC
