问答题 本题读取用户输入的字符流,直到用户输入字符串quit后结束。 importjava.io.*; public class javal{ public static void main(String[]args){ ; BufferedReader in; ir=new InputStreamReader(System.in); in=new BufferedReader(ir); System.OUt.println("please input:"); while( ){ try{ String s=in.readLine(); System.out.println("echo:"+s); if(S.equals("quit")) ; )catch(Exception e){ } } } }
判断题 按委托协议的约定,公积金管理中心应定期(每月和每年)按比例将委托贷款手续费划归给承办银行 。( )
问答题 本题是一个Applet,它显示了一个树型结构。单击树结点的时候,就能将其子结点展开,同时下面的文本框可以显示出所单击的结点的路径,比如单击了根结点下B结点下B2结点,则文本框显示为"[TOP,B,B2]"。 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; public class java2 extends JApplet { JTree tree; JTextField jtf; public void init() { Container cp=getContentPane(); cp.setLayout(new BorderLayout()); top=new DefaultMutableTreeNode(" TOP"): DefaultMutableTreeNode a=new Default- MutableTreeNode("A"); DefaultMutableTreeNode al = new Default- MutableTreeNode("Al"); a.add(a1); DefatIltMutableTreeNode a2=new Default- MutableTreeNode("A2"); a.add(a2); DefaultMutableTreeNode a3=new Default- MutableTreeNode("A3"); a.add(a3); DefaultMutableTreeNode b=new Default- MutableTreeNode("B"); DefaultMutableTreeNode bl=new Default- MutableTreeNode("Bl"); b.add(b1); DefaultMutableTreeNode b2=new Default- MutableTreeNode("B2"); b.add(b2); DefaultMutableTreeNode b3=new Default- MutableTreeNode("B3"): b.add(b3); top.add(a); top.add(b); tree=new JTree(top); int v=ScrollPaneConstants.VERTICAL_ SCROLLBAR_AS_NEEDED; int h=ScrollPaneConstants.HORIZONTAL_ SCRoLLBAR_AS_NEEDED; JScrollPane jsp=new JScrollPane(tree,V,h); cp.add(jsp,BorderLayout.CENTER); jtf=new JTextField(20); cp.add(jtf,BorderLayout.SOUTH); tree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { doMouseClicked(me); } }); } void doMouseClicked(MouseEvent me) { tp=tree.getPathForLocation(me.getX (),me.getY()); if(tp!=null) jtf.setText(tp.toString()); else jtf.setText(""); } }
问答题 本题中使用了选项卡,窗口中有一个选项卡,总共有“系统”、“声卡”、“显卡”、“网卡”和“帮助”5项选项面。单击各个选项的文字标签后,所选中的选项将为当前选项。“系统”选项上有3个复选按钮,分别控制“声卡”、“显卡”和“网卡”三个选项,选中某个按钮后,它所指示的选项就可用,否则不可用。 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class java3 extends JFrame{ JTabbedPane config=new JTabbedPane(): public java3(){ super("java3"); setSize(500,300); setDefaultCloseoperation(EXIT_ON_CLOSE); JPanel configPane=new JPanel(); configPane.setLayout(new BoxLayout(config- Pane,BoxLayout.Y_AXIS)); JTextArea question=new JTextArea("下面的哪 个选项\n"+"你想设置?"); question.setEditable(false); question.setMaximumSize(new Dimension(300, 50)); question.setAlignmentX(0.Of); question.setBackground(configPane.getBack- ground()); JCheckBox audioCB=new JCheckBox ("声卡", true); JCheckBox nicCB=new JCheckBox("网卡", true); JCheckBox tvCB=new JCheckBox("显示卡", false); configPane.add(Box.createVerticalGlue()); configPane.add(question); configPane.add(audioCB); configPane.add(nicCB); configPane.add(tvCB); configPane.add(Box.ereateVerticalGlue()); JLabel audioPane=new JLabel("声卡页面"); JLabel niePane=new JLabel("网卡页面"); JLabel tvPane=new JLabel("显示卡页面"); JLabel helpPane=new JLabel("帮助信息"); audioCB.addItemListener(new TabManager(au- dioPane)); nicCB.addItemListener(new TabManager (nicPane)); tvCB.addItemListener(new TabManager (tvPane)): config.addTab("系统",null,configPane," Choose Installed Options”); config.addTab("声卡",null,audioPane,"Audio system configuration”); config.addTab("网卡",null,nicPane;"Netwot- king configuration"); config.addTab("显示卡",null,tvPane,"Video system configuration"); config.addTab("帮助",null,helpPane,"How Do I…"); getContentPane().add(config,BorderLayout. CENTER); } class TabManger implements ActionListener{ Component tab; public TabManager(Component tabToManage){ tab=tabToManage; } public void ItemStateChanged(ItemEvent ie){ int index=config.indexOfComponent(tab); if(index!=-l){ config.setEnabledAt(index,ie.getStateChange() = =ItemEvent.SELECTED); } this.repaint(); } } public static void main(String args[]){ java3 SC=new java3(); se.setVisible(true); } }
判断题 案件风险应作为一项重要的内容纳入各营业机构每年的风险评估。
问答题 本题的功能是监听对于颜色的复制和粘贴。程序窗l:1中,有一个颜色设置框和两个按钮,名为“复制”和“粘贴”,在颜色设置框中设置颜色后,下面的预览面板将显示选中的颜色,单击“复制”按钮后,将设置的颜色复制到系统的剪贴板上,然后继续选择其他颜色,当单击按钮“粘贴”后预览面板的颜色将设置为刚才复制的颜色。 importjava.io.*; import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; public class java3 { public static void main(String[]args) { JFrame frame=new SerialTransferFrame(): frame.setDefaultCloseoperation(JFrame.EXIT ON_CLOSE); frame.show(); } } class SerialTransferFrame extends JFrame { public SerialTransferFrame() { setTitle("java3"): Container contentPane = getContentPane(); chooser=new JColorChooser(); contentPane.add(chooser,BorderLayout.CEN- TER); JPanel panel=new JPanel(); JButton copyButton=new JButton("复制"); panel.add(copyButton); copyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { copy(); } }); JButton pasteButton=new JButton("粘贴"); panel.add(pasteButton); pasteButton.addAetionListener(new ActionListener() { public void aetionPerformed(AetionEvent event) { paste(); } }); contentPane.add(panel,BorderLayout.SOUTH); pack(); } private void copy() { Clipboard clipboard =Toolkit.getDefaultToolkit().getSystemClip- board(); int color=chooser.getColor(); SerialSeleetion selection=new SerialSelection (color); clipboard.setContents(selection,null); } private void paste() { Clipboard clipboard =Toolkit.getDefaultToolkit().getSystemClip- board(); Transferable contents=clipboard.getContents (null); if(contents= =null)return; try { DataFlavor flavor=new DataFlavor( "application/x-java-serialized-object;class= java.awt.Color"); if(contents.isDataFlavorSupported(flavor)) { Color color =(Color)contents.getTransferData(flavor); ; } } catch(ClassNotFoundException exception) { JOptionPane.showMessageDialog(this,excep- tion); } catch(UnsupportedFlavorException exception) { JOptionPane.showMessageDialog(this,excep- tion); } catch(IOException exception) { JOptionPane.showMessageDialog(this,excep- tion); } } private JColorChooser chooser; } class SerialSelection implements Transferable { SerialSelection(Serializable o) { obj=o: } public DataFlavor[]getTransferDataFlavors() { DataFlavor[]flavors=new DataFlavor[2]; Class type=obj.getClass(); String mimeType ="application/x-java-serialized-object;class =" +type.getName(); try { flavors[0]=new DataFlavor(mimeType); flavors[1]=DataFlavor.stringFlavor; return flavors; } catch(ClassNotFoundExeeption exception) { return new DataFlavor[O]; } } public boolean isDataFlavorSupported(DataFlavor flavor) { Return DataFlavor.stringFlavor.equals(flavor)‖"appli- cation".equals(flavor.getPrimaryType()) &&"x-iava-serialized-object".equals(flavor. getSubType()) &&flavor.getRepresentationClass().isAssign- ableFrom(obj.getClass()); } public void getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if(! isDataFlavorSupported(flavor)) throw new UnsupportedFlavorException(flaVor); if(DataFlavor.stringFlavor.equals(flavor)) return obj.toString(); return obj; } private Serializable obj; }
问答题 本题提取字符串“China is a great country.”中的前5个字符生成一个新的字符串,并将剩余字符组成另外一个新的字符串,最后将两个新的字符串连接输出。 public class javal{ public static void main(String[]args){ Stling str="China is a great country."; ; headstr=str.substring( ); trailstr=str.substring( ); System.out.println(headstr+trailstr); } }
判断题 房地产司法拍卖估价,评估的是市场价值,而房地产抵押估价,评估的应是谨慎价值。( )
问答题 本题是一个Applet,功能是用鼠标画不同颜色的图形。页面中有5个按钮“画红色图形”、“画绿色图形”、“画蓝色图形”、“橡皮”和“清除”,单击前三个按钮中的一个,按住鼠标左键或右键在面板中拖动,就能两出对应颜色的线条,单击“橡皮”按钮,按住鼠标左键或右键在面板中拖动就能将面板中的图形擦除掉,单击“清除”按钮,就能将面板中所有的图形清除掉。 import java.applet.*; import java.awt.*; import java.awt.event.*; public class java3 extends Applet implements ActionListener {int x=-1,y=-1,rubberNote=0,clearNote=0; Color C=new Color(255,0,O); int con=3; Button b_red,b_blue,b_green,b_clear,b_quit; public void init() { addMouseMotionListener(this); b_red=new Button("画红色图形"); b_blue=new Button("画蓝色图形"); b_green=new Button("画绿色图形"); b_quit=new Button("橡皮"); b_clear=new Button("清除"); add(b_red); add(b_green); add(b_blue); add(b_quit); add(b_clear); b_red.addActionListener(this); b_green.addActionListener(this); b_blue.addActionListener(this); b_quit.addActionListener(this); b_dear.addActionListener(this); } public void paint() (if(x!=-l&&y!=-l&rubberNote= = 0R&clearNote= =0) {g.setColor(c); g.filloval(X,Y,con,con); } else if(rubberNote= =1&&clearNote= =O) {g.clearRect(x,Y,10,10); } else if(clearNote= =1&&rubberNote= =O) {g.clearRect(0,0,getSize().width,getSize(). height); } } public void mouseDragged(MouseEvent e) {x=(int)e.getX();y=(int)e.getY();repaint(); } public void mouseMoved(MouseEvent e){) public void update(Graphics g) {paint(g); } public void actionPerformed(Event e) {if(e.getSource()= =b-red) {rubberNote=0;clearNote=0;c=new Color (255,0,0); } else if(e.getSource()= =b_green) {rubberNore=0;clearNote=0;C=new Color(0, 255,0); } else if(e.getSource()= =b_blue) {rubberNote=0;clearNote=0;C=new Color(0, 0,255); } if(e.getSource()= =b—quit) {rubberNote=1;clearNote=0; } if(e.getSource()= =b—clear) {clearNote=1;rubberNote=0;repaint(); } } }
问答题 本题的功能是通过鼠标确定两个点,然后画两点间的直线。窗口中有一个按钮“Draw line”,单击该按钮后,它就处于按下状态,然后用鼠标在窗口中单击一下,在单击的地方就会出现一个坐标圆点,用鼠标在另外一个地方单击一下又会出现另外一个圆点,并且此时在两个坐标圆点间画出一条直线,且“Draw line”处于可用状态,再单击这个按钮就可以画另外一条直线。 Import java.awt.* ; import java.awt.event.*; import javax.swing.*; class EventQueuePanel extends JPanel implements Ac- tionListener {EventQueuePanel() {JButton button=new JButton("Draw line"); add(button); button.addActionListener(this); } public void actionPerformed(ActionEvent evt) (Graphics g=getGraphics(); P=getClick(); g.drawOval(P.x-2,P.Y-2,4,4); Point q=getClick(); g.drawOval(q.x-2,q.y-2,4,4); g.drawLine(P.X,P.Y,q.x,q.y); g.dispose(); } public Point getClick() {EventQueue eq=Toolkit.getDefaultToolkit(). getSystemEventQueue(); while(true) {try {AWTEvent evt=eq.getNextEvent(); if(evt.getID()= =MouseEvent.MOUSE. PRESSED) {MouseEvent mevt=(MouseEvent)evt; Point P= (); Point top=getRootPane().getLocation(); P.X-=top.x; P.Y-=top.Y; return P; } } catch(InterruptedException e) {} } } private int Y=60; } class EventQueueFrame extends JFrame {public EventQueueFrame() {setTitle("java2"); setSize(300,200); addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0); } }); Container contentPane=getContentPane(); contentPane.add(new EventQueuePanel()); } } public class java2 {public static void main(String[]args) {Frame frame=new EventQueueFrame(); frame.show(); } }