首页
试卷库
试题库
当前位置:
X题卡
>
所有题目
>
题目详情
下面程序段的输出结果为( )。 package test; public class ClassA int x=20; static int y=6; public static vo...
查看本题答案
包含此试题的试卷
计算机等级考试《单项选择》真题及答案
点击查看
你可能感兴趣的试题
下面程序段的输出结果为packagetestpublicclassClassA{intx=20sta
x=10
x-20
x=6
编译不通过
下列哪个选项的java源文件程序段是不正确的
package testpackage; public class Test{ }
import javi*; package testpackage; public class Test{ }
import jav*; class Person{} public class Test{ }
import javi*; import javaw*; public class Test { }
下面程序段的输出结果是publicclassTestpublicstaticvoidmainStri
01234
6789
012346789
5
下面代码段的输出结果为publicclassTest{publicstaticvoidmainStr
1
14
-15
若下面程序运行时输出结果为 1A10.1 2B3.5 请将程序补充完整 #include<i
下面程序段的输出结果为packagetestpublicclassAintx=20staticint
x=10
x=20
x=6
编译不通过
下面程序段的输出结果为 packagetest publicclassClassA intx=20
x=10
x=20
x=6
编译不通过
下面程序段的输出结果是publicclassTestpublicstaticvoidmainStri
n is 8
没有输出
n is 10
n is 9
下面程序段的输出结果为packagetest;publicclassClassAintx=20;st
x=10
x=20
x=6
编译不通过
下面程序段的输出结果为packagetestpublicclassClassAintx=20stat
x=10
x=20
x=6
编译不通过
下面程序段的输出结果为______packagetest;publicclassClassAintx
x=10
x=20
x=6
编译不通过
下面程序段的输出结果是publicclassTest{publicstaticvoidmainStr
01234
6789
012346789
5
下列程序段的输出结果为______ publicclassTest{ voidprintValu
执行下面的程序段输出结果为______ publicclassQ { publicstatic
下面程序段的输出结果是publicclassTest{publicstaticvoidmainStr
n is 8
没有输出
n is 10
n is 9
下面程序段的输出结果为packagetestpublicclassClassAintx=20stat
x=10
x-20
x=6
编译不通过
下面程序段的输出结果为packagetestpublicclassClassA{intx=20sta
x=10
x=20
x=6
编译不通过
下面程序段的输出结果是publicclassTest{publicstaticvoidmainStr
2
3
4
5
下面程序段的输出结果为packagetestpublicclassA{intx=20staticin
x=10
x=20
x=6
编译不通过
下面程序段的输出结果是publicclassTestpublicstaticvoidmainStri
;
&n
热门试题
更多
本题中在下画线上填写代码指定变量b为字节型变量f为单精度实型变量1为64位整型publicclassjava1publicstaticvoidmainString[]args______b=49;______f=8.9f;______l=0xfedl;System.out.printlnb=+b;System.out.printlnf=+f;System.out.printlnl=+1;
本题统计score[]=37896360597891中成绩不及格的人数publicclassjava1publicstaticvoidmainString[]argsintscore[]=37896360597891;intsum=0;inti=0;whilei<score.lengthifscore[i]>=60______;______;______;i++;System.out.printlnbelow60sum+sum;
使用VC++6.0打开考生文件夹下的源程序文件1.cpp该程序运行时有错请改正其中的错误使程序正确运行其输出的结果为30130注意错误的语句在//******error******的下面修改该语句即可试题程序#include<iostream.h>inta=10classTCpublicTCa=b=0voiddisplay//******error******cout<<a<<b<<end1voidfuncinta//******error******a+=avoidfunc2//******error******a+=aprivateintabvoidmainTCobjobj.func3obj.displayobj.func2obj.display
本题中主窗口有一个按钮显示Dialog单击该按钮后显示一个对话框对话框的标题是Dialog其上有一个文字标签欢迎学习Java.此时仍允许对原来窗口进行操作当关闭新生成的对话框时退出程序importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassjava2extendsFrameimplementsActionListenerpublicstaticvoidmainStringargs[]java2f=newjava2java2;Panelpan=newPanel;f.init;publicjava2Stringstrsuperstr;publicvoidinitaddWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;setSize200200;setLayoutnewFlowLayout;but=newButton显示Dialog;addbut;but.addActionListenerthis;dlg=newDialogthisDialog______;dlg.setSize10050;dlg.addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEvente______;;dlg.addCenternewLabel欢迎学习Java.;setVisibletrue;publicvoidactionPerformedActionEventedlg.setVisibletrue;privateDialogdlg;privateButtonbut;
本题提取字符串Chinaisagreatcountry.中的前5个字符生成一个新的字符串并将剩余字符组成另外一个新的字符串最后将两个新的字符串连接输出publicclassjava1publicstaticvoidmainString[]argsStringstr=Chinaisagreatcountry.;______;headstr=str.substring______;trailstr=str.substing______;System.out.printlnheadstr+trailstr;
本题的功能是监听鼠标的操作鼠标置于窗口中单击时左键或右键在单击的地方会画一个小矩形如果将鼠标置于小矩形上则鼠标光标状态改为小十字按下鼠标左键可拖曳双击鼠标左键或右键时小矩形消失importjava.awt.*;importjava.awt.event.*;importjava.util.*;importjava.awt.geom.*;importjavax.swing.*;publicclassjava3publicstaticvoidmainString[]argsMouseFrameframe=newMouseFrame;frame.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE;frame.show;classMouseFrameextendsJFramepublicMouseFramesetTitlejava3;setSizeDEFAULT_WIDTHDEFAULT_HEIGHT;MousePanelpanel=newMousePanel;ContainercontentPane=geeContentPane;contentPane.addpanel;publicstaticfinalintDEFAULT_WIDTH=300;publicstaticfinalintDEFAULT_HEIGHT=200;classMousePanelextendsJPanelpublicMousePanelsquares=newArrayList;current=null;addMouseListenernewMouseHandler;addMouseMotionListenernewMouseMorionHandler;publicvoidpaintComponentGraphicsgsuper.paintComponentg;Graphics2Dg2=Graphics2Dg;forinti=0;i<squares.size;i++g2.drawRectangle2Dsquares.geti;publicvoidfindPoint2Dpforinti=0;i<squares.size;i++Rectangle2Dr=Rectangle2Dsquares.geti;ifr.containspreturnr;returnnull;publicvoidaddPoint2Dpdoublex=p.getX;doubley=p.getY;current=newRectangle2D.Doublex-SIDELENGTH/2y-SIDELENGTH/2SIDELENGTHSIDELENGTHsquares.addcurrent;repaint;publicvoidremoveRectangle2Dsifs==nullreturn;ifs==currentcurrent=null;squares.removes;repaint;privatestaticfinalintSIDELENGTH=10;privateArrayListsquares;privateRectangle2Dcurrent;privateclassMouseHandlerextendsMouseActionListenerpublicvoidmousePressedMouseEventeventcurrent=findevent.getPoint;ifcurrent==nulladdevent.getPoint;publicvoidmouseClickedMouseEventeventcurrent=findevent.getPoint;ifcurrent!=null&&event.getClickCount>=2removecurrent;privateclassMouseMotionHandlerimplementsMouseMotionListenerpublicvoidmouseMovedMouseEventeventiffindevent.getPoint==nullsetCursorCursor.getDefaultCursor;elsesetCursorCursor.getPredefinedCursorCursor.CROSSHAIR_CURSOR;publicvoidmouseDraggedMouseEventeventifcurrent!=nullintx=event.getX;inty=event.getY;current.setFramex-SIDELENGTH/2y-SIDELENGTH/2SIDELENGTHSIDELENGTH;repaint;
本题中通过菜单Connect显示一个对话框单击ok按钮后所填写的内容就会传回到主窗口并显示出来importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassjava3extendsJFrameimplementsActionListenerpublicjava3setTitlejava3;setSize300300;addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;JMenuBarmbar=newJMenuBar;setJMenuBarbar;JMenufileMenu=newJMenuFile;mbar.addfileMenu;connectItem=newJMenuItemConnect;connectItem.addActionListenerthis;fileMenu.addconnectItem;exitItem=newJMenuItemExit;exitItem.addActionListenerthis;fileMenu.addexitItem;publicvoidactionPerformedActionEventevtObjectsource=evt.getSource;ifsource==connectItemConnectInfotransfer=newConnectInfoyournamepw;ifdialog==nulldialog=newConnectDialogthis;ifdialog.showDialogtransferStringuname=transfer.username;Stringpwd=transfer.password;ContainercontentPane=getContentPane;contentPane.addnewJLabelusername=+uname+password=+pwdSouth;validate;elseifsource==exitItemSystem.exit0;publicstaticvoidmainString[]argsJFramef=newjava3;f.show;privateConnectDialogdialog=null;privateJMenuItemconnectItem;privateJMenuItemexitItem;classConnectInfopublicStringusername;publicStringpassword;publicConnectfnfoStringuStringpusername=u;password=p;classConnectDialogextendsJDialogimplementsActionListenerpublicConnectDialogsuperparentConnecttrue;ContainercontentPane=getContentPane;JPanelp1=newJPanel;p1.setLayoutnewGridLayout22;p1.addnewJLabelUsername;p1.addusername=newJTextField;p1.addnewJLabelPassword;p1.addpassword=newJPasswordField;contentPane.addCenterp1;Panelp2=newPanel;okButton=addButtonp2Ok;cancelButton=addButtonp2Cancel;contentPane.addSouthp2;setSize240120;JButtonaddButtonContainercStringnameJButtonbutton=newJButtonname;button.addActionListenerthis;c.addbutton;returnbutton;publicvoidactionPerformedActionEventevtObjectsource=evt.getSource;ifsource==okButtonok=true;setVisiblefalse;elseifsource==cancelButtonsetVisiblefalse;publicvoidshowDialogConnectInfotransferusername.setTexttransfer.username;password.setTexttransfer.password;ok=false;show;ifoktransfer.username=username.getText;transfer.password=newStringpassword.getPassword;returnok;privateJTextFieldusername;privateJPasswordFieldpassword;privatebooleanok;privateJButtonokButton;privateJButtoncancelButton;
本题的功能是计算二维数组arr[][]=3421456720231034576223795650中的最小值并输出publicclassjava1publicstaticvoidmainString[]argsintarr[][]=3421456720231034576223795650;inti=0;intj=0;intmin=arr[0][0];whilei<3while______ifarr[i][j]<minmin=arr[i][j];j++;______;______;System.out.printlnThemin+min;
本题的功能是获得字符串China的长度和最后一个字符并将这些信息打印出来publicclassjava1publicstaticvoidmainString[]args______;str=China;intn=0;______;charc;______;System.out.println字符串中共有+n+个字符最后一个字符是+c;
本题中主窗口有一个按钮一个文本域和一个复选按钮初始时窗口的大小是不能调整的选中复选按钮后窗口大小就可以进行调整如果撤销复选按钮的选择则窗口的大小又不能调整单击按钮可以关闭程序importjava.awt.*;importjava.awt.event.*;classMyFrameextendsFrameCheckboxbox;TextAreatextButtonbutton;MyFrameStringssupers;box=newCheckbox设置窗口是否可调整大小;text=newTextArea1212;button=newButton关闭窗口;button.addActionListenerthis;box.addhemListenerthis;setBounds100100200300;setVisibletrue;addtextBorderLayout.CENTER;addboxBorderLayout.SOUTH;addbuttonBorderLayout.NORTH;______;validate;publicvoiditemStateChangedItemEventeifbox.getState==truesetResizabletrue;elsesetResizablefalse;publicvoidactionPerformedActionEventedispose;classjava2publicstaticvoidmainStringargs[]newMyFramejava2;
本题中主窗口中有两个下拉菜单一个控制绘制图形的颜色另一个控制绘制的图形在画板中单击鼠标则以单击的位置为左上角以选定的颜色绘制选定的图形importjava.awt.*;importjava.awt.event.*;classjava3extendsFrameString[]figureNames=圆形椭圆形正方形长方形;String[]colorNames=红色绿色.蓝色.黄色;Color[]colorValues=Color.redColor.greenColor.blueColor.yellow;ChoicechFigure=newChoice;ChoicechColor=newChoice;intcurXcurY;java3superjava3;addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;Panelp=newPanelnewGridLayout10;forinti=0;i<figureNames.length;i++chFigure.addItemfigureNames[i];forinti=0;i<colorNames.length;i++chColor.addItemcolorNames[i];p.addchColor;p.addchFigure;addpBorderLayout.NORTH;addMouseListenerthis;setSize300300;show;publicvoidupdateGraphicsgg.getColorcolorValues[chColor.getSelectedIndex];switchchFigure.getSelectedIndexcase0;g.fillOvalcurXcurY3030;break;case1:g.fillOvalcurXcurY3050;break;case2:g.fillReetcurXcurY3030;break;case3:g.fillRectcurXcurY3050;break;classMouseEventListenerimplementsMouseAdapterpublicvoidmousePressedMouseEventevtcurX=evt.getX;curY=evt.getY;repaint;staticpublicvoidmainString[]argsnewjava3;
本题的功能是通过按钮来选择窗口显示的风格窗口中有三个按钮MetalMotif和Windows单击任何一个按钮就能将窗口的风格改变为按钮名称所对应的风格importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;classPlafPanelextendsJPaneiimplementsActionListenerpublic______metalButton=newJButtonMetal;motifButton=newJButtonMotif;windowsButton=newJButtonWindows;addmetalButton;addmotifButton;addwindowsButton;metalButton.addActionListenerthis;motifButton.addActionListenerthis;windowsButton.addActionListenerthis;publicvoidactionPerformedActionEventevtObjectsource=evt.getSource;Stringplaf=;ifsource==metalButtonplaf=javax.swing.plaf.metal.MetalLookAndFeel;elseifsource==motifButtonplaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel;elseifsource==windowsButtonplaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel;tryUIManager.setLookAndFeel______;SwingUtilities.updateComponentTreeUIthis;catchExceptioneprivateJButtonmetalButton;privateJButtonmotifButton;privateJButtonwindowsButton;classPlafFrameextendsJFramepublicPlafFramesetTitlesimple;setSize300200;addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;ContainercontentPane=getContentPane;contentPane.addnewPlafPanel;publicclassjava2publicstaticvoidmainString[]argsJFrameframe=newPlafFrame;frame.show;
本题的功能是获取鼠标在窗口中的位置当鼠标移进窗口中就会实时显示鼠标在窗口中的相对位置比如显示为鼠标的当前位置XY其中X为横坐标Y为纵坐标importjava.awt.*;importjava.awt.event.*;importjava.util.*;importjavax.swing.*;publicclassjava2publicstaticvoidmainstring[]argsMouseFrameframe=newMouseFrame;frame.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE;frame.show;classMouseFrameextendsJFramepublicMouseFramesetTitlejava2;setSizeWIDTHHEIGHT;MousePanelpanel=newMousePanel;ContainercontentPane=getContentPane;contentPane.addpanel;publicstaticfinalintWIDTH=300;publicstaticfinalintHEIGHT=200;classMousePanelextendsJPanelpublicMousePaneladdMouseListenernewMouseHandler;addMouseMotionListenernewMouseMorionHandler;publicvoidpaintComponentGraphicsgsuper.paintComponentg;Stringtext=鼠标指针位置+mousex++mousey;g.drawstringtext1010;privateintmousexmousey;privateclassMouseMotionHandler______publicvoidmouseMovedMouseEventeventmousex=event.getX;mousey=event.getY;repaint;publicvoidmouseDraggedMouseEventeventmousex=event.getX;mousey=event.getY;repaint;privateclassMouseHandler______publicvoidmousePressedMouseEventeventmousex=event.getX;mousey=event.getY;
本题中定义了一个树型的通信录窗口左侧是一个树右侧是一个文本域单击树的结点则在右侧文本域中显示相关信息如果单击的是树结点则显示对应名字的电话信息importjavax.swing.*;importjavax.swing.tree.*;importjava.awt.*;importjava.awt.event.*;importjavax.swing.event.*;classMytree2extendsJFrameJTreetree=null;JTextAreatext=newJTextArea2020;Mytree2Containercon=getContentPane;DefaultMutableTreeNoderoot=newDefauhMutableTreeNode同学通信录;DefaultMutableTreeNodet1=newDefauhMutableTreeNode大学同学;DefaultMutableTreeNodet2=newDefaultMutableTreeNode研究生同学;DefaultMutableTreeNodet1_1=newDefauhMutableTreeNode陈艳;DefaultMutableTreeNodet1_2=newDefauhMutableTreeNode李小永;DefaultMutableTreeNodet2_1=newDefauhMutableTreeNode王小小;DefaultMutableTreeNodet2_2=newDefauhMutableTreeNode董小;setTitlejava2;root.addt1;root.addt2;t1.addt1_1;t1.addt1_2;t2.addt2_1;t2.addt2_2;tree=newITreeroot;JScrollPanescrollpane=newJScrollPanetext;JSplitPanesplitpane=newJSplitPaneJSplitPane.HORIZONTAL_SPLITtruetreescrollpane;tree.addTreeSelectionListenerthis;con.addsplitpane;addWindowListenerFlewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.ext0;;setVisibletrue;setBounds7080200300;publicvoidvalueChangedTreeSelectionEventeife.getSource==treeDefaultMutableTreeNodenode=DefauhMutableTreeNodetree.getLastSelectedPathComponent;ifnode.isLeafStringstr=______;ifstr.equals陈艳text.setTextstr+联系电话0411-4209876;elseifstr.equals李小永text.setTextstr+联系电话010-62789876;elseifstr.equals王小小text.setTextstr+联系电话0430-63596677;elseifstr.equals董小text.setTextstr+联系电话020-85192789;elsetext.setTextnode.getUserObject.toString;publicclassjava2publicstaticvoidmainStringargs[]Mytree2win=newMytree2;win.pack;
本题是一个Applet功能是用鼠标画不同颜色的图形页面中有5个按钮画红色图形画绿色图形画蓝色图形橡皮和清除单击前三个按钮中的一个按住鼠标左键或右键在而板中拖动就能画出对应颜色的线条单击橡皮按钮按住鼠标左键或右键在面板中拖动就能将面板中的图形擦除掉单击清除按钮就能将面板中所有的图形清除掉importjava.applet.*;importjava.awt.*;importjava.awt.event.*;publicclassjava3extendsAppletimplementsActionListenerintx=-1y=-1rubberNote=0clearNote=0;Colorc=newColor25500;intcon=3;Buttonb_redb_blueb_greenb_clearb_quit;publicvoidinitaddMouseMotionListenerthis;b_red=newButton画红色图形;b_blue=newButton画蓝色图形;b_green=newButton画绿色图形;b_quit=newButton橡皮;b_clear=newButton清除;addb_red;addb_green;addb_blue;addb_quit;addb_clear;b_red.addActionListenerthis;b_green.addActionListenerthis;b_blue.addActionListenerthis;b_quit.addActionListenerthis;b_clear.addActionListenerthis;publicvoidpaintifx!=-1&&y!=-1&&rubberNote==0&&clearNote==0g.setColorc;g.fillOvalxyconcon;elseifrubberNote==1&&clearNote==0g.clearRectxy1010;elseifclearNote==1&&rubberNote==0g.clearRect00getSize.widthgetSize.height;publicvoidmouseDraggedMouseEventex=inte.getX;y=inte.getY;repaint;publicvoidmouseMovedMouseEventepublicvoidupdateGraphicsgpaintg;publicvoidactionPerformedEventeife.getSource==b_redrubberNote=0;clearNote=0;c=newColor25500;elseife.getSource==b_greenrubberNote=0;clearNote=0;c=newColor02550;elseife.getSource==bbluerubberNote=0;clearNote=0;c=newColor00255;ife.getSource==b_quitrubberNote=1;clearNote=0;ife.getSource==b_clearclearNote=1;rubberNote=0;repaint;
本题的功能是监听键盘敲击事件并将敲击的字符显示在标签上开始文字标签提示Pleasepressyourkeyboard!当按下键盘上的字符键文字标签就变为’*’ispressed!*为所按字母importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassjava2extendsFrame______publicstaticvoidmainStringargs[]java2f=newjava2java2;Panelpan=newPanel;f.init;publicjava2Stringstrsuperstr;publicvoidinitaddWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;setSize200200;setLayoutnewFlowLayout;lab=newLabelPleasepressyourkeyboard!;addlab;addKeyListenerthis;setVisibletrue;publicvoidkeyTypedKeyEventelab.setText/’+______+/’ispressed!;repaint;publicvoidkeyPressedKeyEventepublicvoidkeyReleasedKeyEventeprivateLabellab;
本题是一个Applet页面中有两个文本域当左侧文本域中的文本发生变化时该文本域中的文本以行为单位按长度由短到长排列在右边的文本域中importjava.util.*;importjava.applet.*;importjava.awt.*;importjava.awt.event.*;publicclassjava2extendsAppletimplementsTextListenerTextAreatext1text2;publicvoidinittext1=newTextArea615;text2=newTextArea615;addtext1;addtext2;text2.setEditablefalse;______;publicvoid______ife.getSource==text1Strings=text1.getText;StringTokenizerfenxi=newStringTokenizers’/n’;intn=fenxi.countTokens;Stringa[]=newString[n];forinti=0;i<=n-1;i++Stringtemp=fenxi.nextToken;a[i]=temp;forinti=0;i<=n-1;i++forintj=i+1;j<=n-1;j++ifa[j].compareToa[i]<0Stringt=a[j];a[j]=a[i];a[i]=t;text2.setTextnull;forinti=0;i<n;i++text2.appenda[i]+n;
本题的功能是计算二维数组各个元素的和程序中定义了二维数组arrarr有3行4列共12个元素程序中采用for循环语句的嵌套来计算数组中各个元素的和并将结果保存在sum变量中最后打印输出结果publicclassjava1publicstaticvoidmainString[]argsintarr[][]=123456789101112;intsum=0;inti=0j=0;fori=0;______for____________;System.out.printlnsum=+sum;
本题定义了一个求两个数的最大值的方法max并调用该方法计算67和23的最大值publicclassjava1publicstaticvoidmainString[]argsjava1temp=newjava1;intres=max6723;System.out.printlnres=+res;staticintmax______intmaxNum;ifa>b______;elsemaxNum=b;______;
本题是一个Applet页面上有一个按钮请单击单击该按钮后弹出一个对话框对话框上有三个按钮橙色蓝色和红色单击其中任意一个按钮则可以将对话框的背景色设置为按钮名称所对应的颜色importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassjava2extendsJAppletprivateJFrameframe;______frame=newJFrame;frame.setTitlejava2;frame.setSize300200;frame.getContentPane.addnewButtonPanel;JButtonPopButton=newJButton请单击;getContentPane.addPopButton;PopButton.addActionListenernewActionListenerpublicvoidactionPerformedActionEventevtifframe.isVisibleframe.setVisiblefalse;else______;;classButtonPanelextendsJPanelprivateclassColorActionimplementsActionListenerprivateColorbackgroundColor;publicvoidactionPerformedActionEventactioneventsetBackgroundbackgrOundColor;repaint;publicColorActionColorcolorbackgroundColor=color;publicButtonPanelJButtonjbutton=newJButton橙色;JButtonjbutton1=newJButton蓝色;JButtonjbutton2=newJButton红色;addjbutton;addjbutton1;addjbutton2;ColorActioncoloraction=newColorActionColor.orange;ColorActioncoloraction1=newColorActionColor.blue;ColorActioncoloraction2=newColorActionColor.red;jbutton.addActionListenercoloraction;jbutton1.addActionListenercoloraction1;jbutton2.addActionListenercoloraction2;
本题的功能是用户利用单选按钮选择性别在下面的标签中显示用户的选择结果importjava.awt.*;______;publicclassjava2publicstaticvoidmainStringargs[]Framef=newFramejava2;f.setLayoutnewGridLayout31;f.addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;CheckboxGroupcg=newCheckboxGroup;Checkboxmale=newCheckbox男cgfalse;Checkboxfemale=newCheckbox女cgfalse;finalLabella=newLabel请选择你的性别;male.addItemListenernewItemListenerpublicvoiditemStateChangedItemEventela.setText你是个男生;;female.addItemListenernewItemListenerpublicvoiditemStateChangedItemEventela.setText你是个女生;;f.addmale;f.addfemale;f.addla;f.setSize200200;______;
本题的功能是监听对于颜色的复制和粘贴程序窗口中有一个颜色设置框和两个按钮名为复制和粘贴在颜色设置框中设置颜色后下面的预览面板将显示选中的颜色单击复制按钮后将设置的颜色复制到系统的剪贴板上然后继续选择其他颜色当单击按钮粘贴后预览面板的颜色将设置为刚才复制的颜色importjava.io.*;importjava.awt.*;importjava.awt.datatransfer.*;importjava.awt.event.*;importjava.awt.image.*;importjavax.swing.*;publicclassjava3publicstaticvoidmainString[]argsJFrameframe=newSerialTransferFrame;frame.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE;frame.show;classSerialTransferFrameextendsJFramepublicSerialTransferFramesetTitlejava3;ContainercontentPane=getContentPane;chooser=newJColorChooser;contentPane.addchooserBorderLayout.CENTER;JPanelpanel=newJPanel;JButtoncopyButton=newJButton复制;panel.addcopyButton;copyButton.addActionListenernewActionListenerpublicvoidactionPerformedActionEventeventcopy;;JButtonpasteButton=newJButton粘贴;panel.addpasteButton;pasteButton.addActionListenernewActionListenerpublicvoidactionPerformedActionEventeventpaste;;contentPane.addpanelBorderLayout.SOUTH;pack;privatevoidcopyClipboardclipboard=Toolkit.getDefaultToolkit.getSystemClipboard;intcolor=chooser.getColor;SerialSelectionselection=newSerialSelectioncolor;clipboardsetContentsselectionnull;privatevoidpasteClipboardclipboard=Toolkit.getDefaultToolkit.getSystemClipboard;Transferablecontents=clipboard.getContentsnull;ifcontents==nullreturn;tryDataFlavorflavor=newDataFlavorapplication/x-java-serialized-object;class=java.awt.Color;ifcontents.isDataFlavorSupportedflavorColorcolor=Colorcontents.getTransferDataflavor;______;catchClassNotFoundExceptionexceptionJOptionPane.showMessageDialogthisexception;catchUnsupportedFlavorExceptionexceptionJOptionPaneshowMessageDialogthisexception;catchIOExceptionexceptionJOptionPane.showMessageDialogthisexception;privateJColorChooserchooser;classSerialSelectionimplementsTransferableSerialSelectionSerializableoobj=o;publicDataFlavor[]getTransferDataFlavorsDataFlavor[]flavors=newDataFlavor[2];Classtype=obj.getClass;StringmimeType=application/x-java-serialized-object;class=+type.getName;tryflavors[0]=newDataFlavormimeType;flavors[1]=DataFlavor.stringFlavor;returnflavors;catchClassNotFoundExceptionexceptionreturnnewDataFlavor[0];publicbooleanisDataFlavorSupportedDataFlavorflavorreturnDataFlavor.stringFlavor.equalsflavor||application.equalsflavor.getPrimaryType&&x-java-serialized-object.equalsflavor.getSubType&&flavor.getRepresentationClass.isAssignableFromobj.getClass;publicvoidgetTransferDataDataFlavorflavorthrowsUnsupportedFlavorExceptionif!isDataFlavorSupportedflavorthrownewUnsupportedFlavorExceptionflavor;ifDataFlavor.stringFlavor.equalsflavorreturnobj.toString;returnobj;privateSerializableobj;
本题是一个Applet功能是监听用对于文本域中文本的选择页面中有一个文本域一个复制按钮和一个文本框选中文本域中部分文字后单击按钮复制所选文字将显示在文本框中importjava.applet.Applet;importjava.awt.*;importjava.awt.event.*;publicclassjava3extendsAppletimplementsActionListenerTextAreata=newTextArea530;TextFieldtf=newTextField30;Buttonbutton=newButton复制;Stringtext=AWT提供基本的GUI组件/n+具有可以扩展的超类/n+它们的属性是继承的/n;publicvoidinitsetLayoutnewFlowLayoutFlowLayout.left;ta.setTexttext;ta.setEditabletrue;addta;addbutton;addtf;ta.addActionListenerthis;publicvoidactionPerformedActionEventeStrings;s=ta.getSelectText;ife.getSource==buttontf.setTextss=ta.getSelectText
本题中数组arr中存储了学生的成绩分别为87455678675691628263程序的功能是计算低于平均分的人数并打印输出结果请在程序空缺部分填写适当内容使程序能正确运行publicclassjava1publicstaticvoidmainString[]argsintarr[]=56917867568745628263;intnum=art.length;inti=0;intsumScore=0;intsumNum=0;doubleaverage;whilei<numsumScore=sumScore+arr[i];______;average=______;i=0;doifarr[i]<averagesumNum++;i++;while______;System.out.printlnaverage+average+belowsaverage+sumNum;
本题是一个计时器窗口中有1个文字标签和3个按钮名为复位开始和暂停初始状态时只有开始按钮可用单击该按钮开始计时并且开始按钮的标签变为继续且不可用暂停按钮变为可用单击暂停按钮后暂停按钮变为不可用复位和继续按钮变为可用此时如果单击复位按钮将恢复到初始状态如果单击继续按钮则继续进行计数importjava.awt.*;importjava.awt.event.*;publicclassjava3extendsFrameextendsRunnableLabeltimeDisp=newLabel0:0Label.CENTER;ThreadtimerThread;inttime=0;ButtonbtReset=newButton复位;ButtonbtStart=newButton开始;ButtonbtStop=newButton暂停;java3superjava3;Panelp=newPanelnewGridLayout10;btReset.setEnabledfalse;btStop.setEnabledtrue;addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;btReset.addActionListenernewResetListener;btStop.addActionListenernewStopListener;btStart.addActionListenernewStartListener;p.addbtReset;p.addbtStart;p.addbtStop;addpBorderLayout.SOUTH;timeDisp.setFontnewFontCourierFont.BOLD60;addtimeDispBorderLayout.CENTER;pack;show;voidstopThreadt=timerThread;ift!=nulltimerThread=null;tryt.join;catchExceptionepublicvoidrunwhiletimerThread==Thread.currentThreadtimeDisp.setText+time/10+:+time%10+0;time++;tryThread.sleep100;catchExceptione;classResetListenerimplementsActionListenerpublicvoidactionPerformedActionEventevtthis.stop;timeDisp.setText0:0;time=0;btReset.setEnabledfalse;btStart.setEnabledtrue;btStop.setEnabledfalse;btStart.setLabel开始;classStopListenerimplementsActionListenerpublicvoidactionPerformedActionEventevtjava3.this.stop;btReset.setEnabledtrue;btStart.setEnabledtrue;btStop.setEnabledfalse;btStart.setLabel继续;classStartListenerimplementsActionListenerpublicvoidactionPerforrnedActionEventevttimerThread=newThreadjava3.this;timerThread.start;btReset.setEnabledfalse;btStart.setEnabledfalse;btStop.setEnabledtrue;btStart.setLabel继续;staticpublicvoidmainString[]argsnewjava3;
本题是一个Applet页面中有10个按钮名称从0~9用鼠标任意单击其中一个按钮后通过键盘上的上下左右键可以控制按钮在窗口中移动importjava.applet.*;importjava.awt.*;importjava.awt.event.*;publicclassjava2extendsApplet______Buttonb[]=newButton[10];intxy;publicvoidinitforinti=0;i<=9;i++b[i]=newButton+i;b[i].addKeyListenerthis;addb[i];publicvoid______Buttonbutton=Buttone.getSource;x=button.getBounds.x;y=button.getBounds.y;ife.getKeyCode==KeyEvent.VK_UPy=y-2;ify<=0y=0;button.setLocationxy;elseife.getKeyCode==KeyEvent.VK_DOWNy=y+2;ify>=300y=300;button.setLocationxy;elseife.getKeyCode==KeyEvent.VK_LEFTx=x-2;ifx<=0x=0;button.setLocationxy;elseife.getKeyCode==KeyEvent.VK_RIGHTx=x+2;ifx>=300x=300;button.setLocationxy;publicvoidkeyTypedKeyEventepublicvoidkeyReleasedKeyEvente
本题的功能是监听鼠标左右键的单击以及面板中滚动条的添加在窗口的画板中单击鼠标左键在单击的位置绘制一个圆当绘制的圆大于画板的大小时画板就添加滚动条在画板中单击鼠标右键则清除画板中的所有图形importjavax.swing.*;importjavax.swing.event.MouseInputAdapter;importjava.awt.*;importjava.awt.event.*;importjava.util.*;publicclassjava3extendsJPanelprivateDimensionsize;privateVectorobjects;privatefinalColorcolors[]=Color.redColor.blueColor.greenColor.orangeColor.cyanColor.magentaColor.darkGrayColor.yellow;privatefinalintcolor_n=colors.length;JPaneldrawingArea;publicjava3setOpaquetrue;size=newDimension00;objects=newVector;JLabelinstructionsLeft=newJLabel单击鼠标左键画圆.;JLabelinstructionsRight=newJLabel单击鼠标右键清空画板.;JPanelinstructionPanel=newJPanelnewGridLayout01;instructionPanel.addinstructionsLeft;instructionPanel.addinstructionsRight;drawingArea=newJPanelprotectedvoidpaintComponentGraphicsgsuper.paintComponentg;Rectanglerect;forinti=0;i<objects.size;i++rect=Rectangleobjects.elementAti;g.setColorcolors[i%color_n];g.fillOvalrect.xrect.yrect.widthrect.height;;drawingArea.setBackgroundColor.white;drawingArea.addMouseListenernewMouseListener;JScrollPanescroller=newJScrollPanedrawingArea;scroller.setPreferredSizenewDimension200200;setLayoutnewBorderLayout;addinstructionPanelBorderLayout.NORTH;addscrollerBorderLayout.CENTER;classMyMouseListenerextendsmouseInputAdapterfinalintW=100;finalintH=100;publicvoidmouseReleasedMouseEventebooleanchanged=false;ifSwingUtilities.isRightMouseButtoneobjects.removeAllElements;size.width=0;size.height=0;changed=true;elseintx-e.getX-W/2;inty=e.getY-H/2;ifx<0x=0;ifY<0y=0;Rectanglerect=newRectanglexyWH;objects.addElementrect;drawingArea.scrollRectToVisiblerect;intthis_width=x+W+2;ifthiswidth>size.widthsize.width=this_width;changed=true;intthis_height=y+H+2;ifthis_height>size.heightsize.height=this_height;changed=true;ifchangeddrawingArea.setPreferredSizesize;drawingArea.revalidate;drawingArea.paint;publicstaticvoidmainStringargs[]JFrameframe=newJFramejava3;frame.addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;frame.setContentPanenewjava3;frame.pack;frame.setVisibletrue;
使用VC++6.0打开考生文件夹下的源程序文件1.cpp该程序运行时有错请改正其中的错误使程序正确运行其输出的结果为30130注意错误的语句在//******error******的下面修改该语句即可试题程序#include<iostream.h>inta=10classTCpublicTCa=b=0voiddisplay//******error******cout<<a<<b<<end1voidfuncinta//******error******a+=avoidfunc2//******error******a+=aprivateintabvoidmainTCobjobj.func3obj.displayobj.func2obj.display
本题提示输入年份然后判断该年份是否为闰年importjava.io.*;publicclassjava1publicstaticvoidmainString[]argsInputStreamReaderir;BufferedReaderin;ir=newInputStreamReaderSystem.in;in=newBufferedReaderir;intyear=1900;System.out.print请输入年份;tryStrings=in.readLine;______;______Exceptioneif______System.out.printlnyear+是闰年;elseSystem.out.printlnyear+不是闰年;
本题的功能是定义自己的组件类窗口中排布着12个按钮鼠标移动按钮时按钮背景颜色改变用鼠标单击按钮时后台将显示该按钮对应的字符importjava.awt.*;importjava.awt.event.*;importjava.util.*;classjava3extendsFrameStringkeys=123456789*0#;java3superjava3;addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;setLayoutnewGridLayout4366;forinti=0;i<keyslength;i++KeyButtonkb=newKeyButtonkeys.charAti;kb.addkeyListenerthis;kb.setBackgroundColor.pink;kb.setForegroundColor.black;addkb;setSize200200;show;classKeyEventHandlerextendsKeyAdapterpublicvoidkeyTypedKeyEventevtSystem.out.printlnevt.getChar;publicstaticvoidmainString[]argsnewjava3;classKeyButtonextendsComponentKeyListenerkeyListener;booleanhighlighted;charkey;KeyButtoncharkthis.key=k;addMouseListenernewMouseEventHandler;publicvoidpaintGraphicsgintw=getSize.width;inth=getSize.height;Strings=+key;FontMetricsfm=g.getFontMetrics;ifhighlightedg.setColorgetBackground;g.fillRoundRect00w-1h-11010;g.setColorgetForeground;g.drawRoundRect00w-1h-11010;g.drawstringsw-fm.stringWidths/2h-fm.getHeight/2+fm.getAscent;classMouseEventHandlerextendsMouseAdapterpublicvoidmousePressedMouseEventevtifkeyListener!=nullkeyListener.keyTypednewKeyEventKeyButton.thisKeyEvent.KEY_TYPEDSystem.currentTimeMillis0KeyEvent.VK_UNDEFINEDkey;publicvoidmouseEnteredMouseEventevthighlighted=true;repaint;publicvoidmouseExitedMouseEventevthighlighted=false;repaint;publicsynchronizedvoidaddKeyListenerKeyListener1keyListener=AWTEventMulticaster.addkeyListener1;publicsynchronizedvoidremoveKeyListenerKeyListener1keyListener=AWTEventMulticaster.removekeyListener1;
热门题库
更多
嵌入式软件助理工程师
计算机操作系统
软件测试工程师
计算机等级考试
法宣在线考试
司法卷一
司法卷二
司法卷三
司法卷四
企业法律顾问资格考试
“十三五”规划继续教育
潜力激活与创造力开发继续教育
创新创业能力继续教育
科研方法与论文写作继续教育
全面深化改革实现文明发展
提高自身绩效路径与方法