以下程序是一个简单文本处理器,菜单项可以打开、编辑、保存一个文件。文件内容显示在下面的文本区域中(提示,打开文件通过文件选择器来完成)。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。运行结果如下图所示。注意:不改动程序的结构,不得增行或删行。importjava.awt.*;importjava.awt.event.*;importjava.io.*;importjavax.swing.*;classFileFrameextendsJFrame{Filefile;JTextPanetextpane;FileInputStreamreadStream;JScrollPanescroll;publicFileFrame(){super("文件浏览");JMenufileM=newJMenu("文件");OpenActionopen=newOpenAction();SaveActionclear=newSaveAction();ExitActionexit=newExitAction();JMenuBarmb=newJMenuBar();fileM.add(open);fileM.add(clear);fileM.add(exit);mb.add(fileM);textpane=newJTextPane();scroll=newJScrollPane(textpane);getContentPane().add(scroll);getContentPane().addJMenuBar(mb);}classOpenActionextendsAbstractAction{publicOpenAction(){super("打开");}publicvoidactionPerformed(ActionEvente){JFileChooserchooser=newJFileChooser();intstate=chooser.showOpenDialog(null);file=chooser.selectedFile();if(file!=nulltextpane.read(readStream,this);readStream.close();}catch(IOExceptionioE){}}}}classSaveActionextendsAbstractAction{publicSaveAction(){super("保存");}publicvoidactionPerformed(ActionEvente){if(file==null)return;try{FileWriterout=newFileWriter(file);out.read(textpane.getText());out.close();}catch(IOExceptionioE){}}}classExitActionextendsAbstractAction{publicExitAction(){super("退出");}publicvoidactionPerformed(ActionEvente){System.exit(0);}}publicstaticvoidmain(Stringargv[]){FileFramef=newFileFrame();f.setDefaultCloseOperation(JFrame.EXITONCLOSE);f.setSize(300,400);f.show();}}
请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。[题目要求]生成下面左边图形界面,单击图中的New按钮,弹出如右图所示的对话框。源程序:importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassJava_3{ publicstaticvoidmain(String[]args){ MulticastFrameframe=newMulticastFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); }}classMulticastFrameextendsJFrame{ publicMulticastFrame(){ setTitle("MulticastTest"); setSize(WIDTH,HEIGHT); MulticastPanelpanel=newMulticastPanel(); ContainercontentPane=getContentPane(); contentPane.add((1)); } publicstaticfinalintWIDTH=300; publicstaticfinalintHEIGHT=200;}classMulticastPanelextendsJPanel} publicMulticastPanel(){ JButtonnewButton=newJButton("New"); add(newButton); ActionListenernewListener=newActionListener(){ publicvoidactionPerformed(ActionEventevent){ makeNewFrame(); } }; newButton.addActionListener(newListener); closeAllButton=newJButton("Closeall"); add(closeAllButton);}privatevoidmakeNewFrame(){ finalBlankFrameframe=newBlankFrame(); frame.show(); ActionListenercloseAllListener=newActionListener(){ publicvoidactionPerformed(ActionEventevent){ frame.(2)();//使窗口隐藏或消除 } }; closeAllButton.addActionListener((3)); } privateJButtoncloseAllButton;}ClassBlankFrameextendsJFrame{ publicBlankFrame(){ (4)++; setTitle("Frame"+counter); setSize(WIDTH,HEIGHT); setLocation(SPACING*counter,SPACING*counter); } publicstaticfinalintWIDTH=200; publicstaticfinalintHEIGHT=150; publicstaticfinalintSPACING=30; privatestaticintcounter=0;}
下列声明和赋值语句错误的是( )。
从对象流中读取对象,请在画线处加入代码完成此程序【 】。 import java.util.*; import java.io.*; public class UnSerializeDate { Date d = null; UnSerializeDate() { try{ FileInputStream f = new FileInputStream("data.ser"); ______; d = (Date) s.readObject(); f.close(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String args[ ]) { UnSerializeDate a = new UnSerializeDate(); System.out.println("The date read is :"+a.d.toString()); } }
阅读下面程序 import java.io.*; public class ExceptionCatch { public static void main(String args[]) { try { FileInputStream fis=new FilelnputStream("text"); System.out.println("content of text is:"); } catch(FileNotFoundException e) { System.out.println(e); System.out.println("message:"+e.getMessage()); e.printStackTrace(System.out); } ______ { System.out.println(e); } } } 为保证程序正确运行,程序中下画线处的语句应是
用static修饰的方法,称为静态方法。它们不是对象的方法,而是整个类的方法。静态方法只能处理用关键字 ______ 修饰的数据。
在关系数据库中,用来组织索引结构联系的是( )。
一个项目具有—个项目主管,—个项目主管可管理多个项目,则实体“项目主管”与实体“项目”的联系属于【 】的联系。
按照流的方向来分,I/O流包括输入流和【 】。
下列程序段的输出结果是()。voiddoublearithmaticoperator(){inta=10,b=4,c=20,d=6;System.out.print(a+b*c+d);System.out.print(",");System.out.print(a+c%b);System.out.print(",");System.out.println(a++*b+c*-d);}
计算机系统的组成是( )。
显示图像使用的是Graphics类中的【 】方法。
在Java语言中有多种实现的机制,下列( )属于垃圾回收机制。
Java源程序文件编译后产生的文件成为字节码文件,其扩展名为【 】。
下列语句片段:int resultint a=17,b=6;result=(a%b>4)?a%b:a/b;System.out.println(result)的结果为 ( )
下列常见的系统定义的异常中,( )是输入、输出异常。
Java的字符类型采用的是Unicode编码方案,每个Unicode码占用( )个比特位。
请将下列程序的空白处补充完整。Importjava.awt.*; PublicclassEll_4 { Publicstaticvoidmain(Stringargs[]) { Framef=newFrame(“BorderLayout”); fiadd(“North”,newbuRon(“North”)); f.add(“East”,newbutton(“East”)); f.add(“West”,newbutton(“West”)); f.add(“South”,tf); f.setSize(200,200) fipack(); fisetVisible(true); } }
下面是一个Applet程序,其功能是建立一个图形用户界面的窗口,包括一个文本显示区和一个按钮,点击按钮,可以声文本区已有的文本基础上追加显示10条"Welcome to China!”信息,并且文本区由滚动条控制文本的上下滚动。请改正程序中的错误(有下画线的语句),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 〈applet code="exl3_4.class"width=800 height=400〉 〈/applet〉 */ public class exl4_3 extends JApplet{ JButton jb=new JButton("Add Text"); JTextPane jtp=new JTextPane(); public void init(){ jb.addActionListener(new Ac60nListener(){ pubhc void actionPerformed(ActionEvent e){ for(int i=1;i<10;i++) jtp.geText(jtp.setText()+"Welcome to China! /n"); } }); Container cp=getContentPane(); cp.add(new JScrollPane(jtp)); cp.add(BorderLayout.SOUTH,jtp); } public static void main(Stdng[] args){ ex14_3 obj14_3=new ex14_3(); String str=obj14_3.getClass().toString(); if(str.indexOf("class")!=-1) str=str.substring(6); JFrame frm=new JFrame(str); frm.addWindowListener(new WindowAdapter(){ pubhc void windowClosing(WindowEvent we){ System.exit(0); } {); frm.getContentPane().add(ex3_10); frm.setSize(300,400); frm.setVisible(true); } } ex14_3.html 〈HTMI〉 〈HEAD〉 〈TITLE〉ex14_3 〈/HEAD〉 〈BODY〉 〈applet code="ex14_3.class"width=800 height=400〉 〈/applet〉 〈/BODY〉 〈/HTML〉
给出下列的不完整的方法,则下列的哪个声明可以被加入①行完成此方法的声明? ① ② { success = connect( ); ③ if (success = = - 1 ) { ④ throw new TimedoutException( ) ⑤ } ⑥ }
