问答题

下列程序打包到example包,main方法调用线程类输出0~9这10个数,请填写横线处的内容。
注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。
______
interface MyInterface

public abstract void print(int n);

class Mythread extends Thread ______ MyInterface

public void run()

for(int i = 0; i < 10; i++)
this.print(i);

public void print(int n)

System.out.print(n +" ");


public class Example1_6

public static void main(String argv[])

Mythread th = new Mythread();
______

【参考答案】

①package example;
②implements
③th.start();
热门 试题

问答题
以下程序是一个简单文本处理器,菜单项可以打开、编辑、保存一个文件。文件内容显示在下面的文本区域中(提示,打开文件通过文件选择器来完成)。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。运行结果如下图所示。 注意:不改动程序的结构,不得增行或删行。 import java.awt.*; import java.awt.event.*; import java.io.* ; import javax.swing.*; class FileFrame extends JFrame File file; JTextPane textpane; FileInputStream readStream; JScrollPane scroll; public FileFrame() super ( 文件浏览 ); JMenu fileM = new JMenu( 文件 ); OpenAction open = new OpenAction (); SaveAction clear = new SaveAction (); ExitAction exit = new ExitAction(); JMenuBar mb = new JMenuBar(); fileM.add(open); fileM.add(clear); fileM.add(exit); mb.add(fileM); textpane=new JTextPane(); scroll=new JScrollPane(textpane); getContentPane().add(scroll); getContentPane().addJMenuBar(mb); class OpenAction extends AbstractAction public OpenAction () super( 打开 ); public void actionPerformed( ActionEvent e ) JFileChooser chooser=new JFileChooser(); int state=chooser.showOpenDialog(null); file=chooser.selectedFile(); if(file!=null&&state==JFileChooser.APPROVE_OPTION) try readStream=new FileInputStream(file); textpane.read(readStream, this); readStream.close(); catch(IOException ioE) class SaveAction extends AbstractAction public SaveAction() super( 保存 ); public void actionPerformed( ActionEvent e ) if(file==null) return; try FileWriter out = new FileWriter(file); out.read(textpane.getText()); out.close(); catch (IOException ioE) class ExitAction extends AbstractAction public ExitAction() super( 退出 ); public void actionPerformed( ActionEvent e ) System.exit(0); public static void main(String argv[]) FileFrame f = new FileFrame(); f.setDefaultCloseOperation(JFrame. EXIT ON CLOSE); f.setSize(300,400); f.show();