⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finder.java

📁 That is some example about GUI. It is very good for user to use on BlueJ.
💻 JAVA
字号:
import java.io.*;
class Finder { 
    private String line1, line2, line3;
    private BufferedReader keyboard;
    private BufferedReader inStream;

    public static void main (String [] args) {
        Finder aFind = new Finder();     
        aFind.doSearch();
    }

    private void doSearch() {
        keyboard = new BufferedReader(
            new InputStreamReader(System.in));
        String fileName = prompt("Type file to search: ");
        String wanted = prompt("Type string to find: ");
        line1 = "";
        line2 = "";
        try {
            inStream = new BufferedReader(new 
                FileReader(fileName));
            while ((line3 = inStream.readLine()) != null) {
                if ( line2.indexOf(wanted) >= 0 ) {
                    displayLine();
                }
                // advance to the next group of 3
                line1 = line2;
                line2 = line3;
                // and get new line3 from file...
            }
            // check the last line
            line3 = "";                //remove null eof value
            if (line2.indexOf(wanted) >= 0) {
                displayLine();
            }
            inStream.close();
        }
        catch (IOException e) {
            System.err.println("Error in Finder: "+ e.toString());
            System.exit(1);
        }
    } 

    private void displayLine() {
        System.out.println("[=== context:");
        System.out.println(line1);
        System.out.println(line2);
        System.out.println(line3);
        System.out.println("===]");
        System.out.println("");
    }

    private String prompt(String message) {
        String reply = "";
        try {
            System.out.print(message);
            System.out.flush();
            reply = keyboard.readLine();
        }
        catch (IOException e) {
            System.err.println("Keyboard "+ e.toString());
            System.exit(2);
        }
        return reply;
    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -