首页
试卷库
试题库
当前位置:
X题卡
>
所有题目
>
题目详情
软件需求分析一般应确定的是用户对软件的( )。
查看本题答案
包含此试题的试卷
计算机等级考试《单项选择》真题及答案
点击查看
你可能感兴趣的试题
热门试题
更多
本题中在下画线上填写代码指定变量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;
本题中主窗口有一个按钮显示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;
本题的功能是用键盘上的方向键来控制直线的绘制方向如果一直按向上的方向键则在窗口中从焦点开始向上缓慢绘制直线按其他方向键也会向对应的方向缓慢地绘制直线如果按下<Shift>键的话绘制直线的速度会加快importjava.awt.*;importjava.awt.geom.*;importjava.util.*;importjava.awt.event.*;importjavax.swing.*;publicclassjava3publicstaticvoidmainString[]argsSketchFrameframe=newSketchFrame;frame.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE;frame.show;classSketchFrameextendsJFramepublicSketchFramesetTitlejava3;setSizeDEFAULT_WIDTHDEFAULT_HEIGHT;SketchPanelpanel=newSketchPanel;ContainercontentPane=getContentPane;contentPane.addpanel;publicstaticfinalintDEFAULT_WIDTH=300;publicstaticfinalintDEFAULT_HEIGHT=200;classSketchPanelextendsJPanelpublicvoidsketchPanellast=newPoint2D.Double100100;lines=newArrayList;KeyHandlerlistener=newKeyHandler;addkeyListenerthis;setFocusabletrue;publicvoidaddintdxintdyPoint2Dend=newPoint2D.Doublelast.getX+dxlast.getY+dy;Line2Dline=newLine2D.Doublelastend;lines.addline;repaint;last=end;publicvoidpaintComponentGraphicsgsuper.paintComponentg;Graphics2Dg2=Graphics2Dg;forinti=0;i<lines.size;i++g2.drawLine2Dlines.geti;privatePoint2Dlast;privateArrayListlines;privatestaticfinalintSMALL_INCREMENT=1;privatestaticfinalintLARGE_INCREMENT=5;privateclassKeyHandlerimplementsKeyListenerpublicvoidkeyPressedKeyEventeventKEYkeyCode=event.getKeyCode;intd;ifeventisShiftDnwnd=LARGE_INCREMENT;elsed=SMALL_INCREMENT;ifkeyCode==KeyEvent.VK_LEFTadd-d0;elseifkeyCode==KeyEvent.VK_RIGHTaddd0;elseifkeyCode==KeyEvent.VK_UPadd0-d;elseifkeyCode==KeyEvent.VK_DOWNadd0d;publicvoidkeyReleasedKeyEventeventpublicvoidkeyTypedKeyEventeventcharkeyChar=event.getKeyChar;intd;ifCharacter.isUpperCasekeyChard=LARGE_INCREMENT;keyChar=Character.toLowerCasekeyChar;elsed=SMALL_INCREMENT;
本题定义了一个长度为10的boolean型数组并给数组元素赋值要求如果数组元素下标为奇数则数组元素值为false否则为truepublicclassjava1publicstaticvoidmainString[]argsbooleanb[]=______;forinti=0;i<10;i++if______b[i]=false;else______;forinti=0;i<10;i++System.out.printb[+i+]=+b[i]+;
本题中通过菜单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;
本题的功能是将文件java2.java复制为文件java2.java.bakimportjava.io.*;publicclassjava2publicstaticvoidmainStringsarg[]tryFilefile=newFilejava2.java.bak;______;FilelnputStreamrfile=newFileInputStreamjava2.java;FileOutputStreamwfile=newFileOutputStreamjava2.java.bak;intc;whilewfile.writecharc;rfile.close;wfile.close;catchExceptioneSystem.out.println读取文件的时候发生错误!;System.out.println复制操作完成!;
本题中定义了一个树型的通信录窗口左侧是一个树右侧是一个文本域单击树的结点则在右侧文本域中显示相关信息如果单击的是树结点则显示对应名字的电话信息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;
本题的功能是获得系统剪贴板中的内容窗口中有一个菜单Edit和一个文本域Edit中有菜单项CutCopy和Paste在文本域中输入内容可以通过菜单进行剪切复制和粘贴操作如果系统剪贴板为空又做粘贴操作的话则设置文本域中背景颜色为红色并显示错误信息importjava.awt.*;importjava.io.*;importjava.awt.datatransfer.*;importjava.awt.event.*;classjava3extendsFrameimplementsActionListenerClipboardOwnerTextAreatextArea=newTextArea;java3superjava3;addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;MenuBarmb=newMenuBar;Menum=newMenuEdit;setLayoutnewBorderLayout;addCentertextArea;m.addCut;m.addCopy;m.addPaste;mb.addm;setMenuBarthis;forinti=0;i<m.getItemCount;i++m.itemi.addActionListenerthis;setSize300300;show;publicvoidactionPerformedActionEventevtifPaste.equalsevt.getActionCommandbooleanerror=true;Transferablet=getToolkit.getSystemClipboard.getContentsthis;tryift!=null&&t.isDataFlavorSupportedDataFlavor.stringFlavortextArea.setBackgroundColor.white;textArea.setForegroundColor.black;textArea.replaceRangeStringt.getTransferDataDataFlavor.stringFlavortextArea.getSelectionStarttextArea.getSelectionEnd;error=false;catchUnsupportedFlavorExceptionecatchIOExceptioneiferrortextArea.setBackgroundColor.red;textArea.setForegroundColor.white;textArea.repaint;textArea.setTextERROR/nEithertheclipboard+isemptyorthecontentsisnotastring.;elseifCopy.equalsevt.getActionCommandsetContents;elseifCut.equalsevt.getActionCommandsetContents;textArea.replaceRangetextAtea.getSelectionStarttextArea.getSelectionEnd;voidsetContentsS=textArea.getSelectedText;StringSelectioncontents=newStringSelections;getToolkit.getSystemClipboard.setContentscontentsthis;publicvoidlostOwnershipClipboardclipboardTransferablecontentsSystem.out.printlnlostownership;publicstaticvoidmainStringargs[]newjava3;
本题的功能是监听键盘敲击事件并将敲击的字符显示在标签上开始文字标签提示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;
本题定义了一个求两个数的最大值的方法max并调用该方法计算67和23的最大值publicclassjava1publicstaticvoidmainString[]argsjava1temp=newjava1;intres=max6723;System.out.printlnres=+res;staticintmax______intmaxNum;ifa>b______;elsemaxNum=b;______;
本题的功能是监听对于颜色的复制和粘贴程序窗口中有一个颜色设置框和两个按钮名为复制和粘贴在颜色设置框中设置颜色后下面的预览面板将显示选中的颜色单击复制按钮后将设置的颜色复制到系统的剪贴板上然后继续选择其他颜色当单击按钮粘贴后预览面板的颜色将设置为刚才复制的颜色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;
本题将数组中arr[]=563791的各个元素按下标的逆序输出publicclassjava1publicstaticvoidmainString[]argsintarr[]=563791;______;n=______;whilen>=0System.out.printarr[n]+;______;
本题是一个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;
本题提示输入年份然后判断该年份是否为闰年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;
本题中定义了一个简单的计算器可以进行基本的四则运算程序中包含16个按钮用来表示0~9+-*/=运算符和小数点程序顶部的文本框用来显示操作数以及结果importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassjava2publicstaticvoidmainString[]argstryUIManager.setLookAndFeelUIManager.getSystemLookAndFeelClassName;catchExceptioneJFrameframe=newCalculatorFrame;frame.show;classCalculatorPanelextendsJPanelimplementsActionListenerprivateJTextFielddisplay;privateJButtonbtn;privatedoublearg=0;privateStringop==;privatebooleanstart=true;publicCalculatorPanelsetLayoutnewBorderLayout;display=newJTextField0;display.setEditablefalse;adddisplayNorth;JPanelp=newJPanel;p.setLayoutnewGridLayout44;Stringbuttons=789/456*123-0.=+;forinti=0;i<buttons.length;i++btn=newJButtonbuttons.substringii+1;p.addbtn;______;addpCenter;publicvoidactionPerformedActionEventevtStrings=evt.getActionCommand;if’0’<=s.charAt0&&s.charAt0<=’9’||s.equals.ifstartdisplay.setTexts;elsedisplay.setTextdisplay.getText+s;start=false;elseifstartifs.equals-display.setTexts;start=false;elseop=s;elsedoublex=______;calculatex;op=s;start=true;publicvoidcalculatedoublenifop.equals+arg+=n;elseifop.equals-arg--n;elseifop.equals*arg*=n;elseifop.equals/arg/=n;elseifop.equals=arg=n;display.setText+arg;classCalculatorFrameextendsJFramepublicCalculatorFramesetTitlejava2;setSize220180;addWindowListenernewWindowAdapterpublicvoidwindowClosingWindowEventeSystem.exit0;;ContainercontentPane=getContentPane;contentPane.addnewCalculatorPanel;
热门题库
更多
软件测试工程师
计算机等级考试
法宣在线考试
司法卷一
司法卷二
司法卷三
司法卷四
企业法律顾问资格考试
“十三五”规划继续教育
潜力激活与创造力开发继续教育
创新创业能力继续教育
科研方法与论文写作继续教育
全面深化改革实现文明发展
提高自身绩效路径与方法
互联网监管与网络道德建设
“互联网+”和电子商务继续教育