0

目前我正在做的是使用 javac Main.java 和 javac -cp lanterna.jar text.java 使它们出现。我想要它,这样当我在我的 UserInterface.class 中做某事时,灯笼类就会出现。

这是我的代码:

用户界面.java

import java.util.Scanner;
import java.io.IOException;
 
public class UserInterface {
 
    private QuoteList ql;
    private Scanner scanner;
 
    public UserInterface(QuoteList ql, Scanner scanner) {
        this.ql = ql;
        this.scanner = scanner;
    }
 
    public void start() throws IOException {
        while (true) {
            System.out.print("Commands:\n" + "1 - import quotes\n" + "2 - add a quote\n" + "3 - share a quote\n" + "4 - tell all quotes\n" + "x - stop\n");
            String command = scanner.nextLine();
            if (command.equals("1")) {
                System.out.print("Enter file: ");
                String file = scanner.nextLine();
                this.ql.importFile(file);
            }
            else if (command.equals("2")) {
                System.out.print("Write your quote: ");
                String q = scanner.nextLine();
                this.ql.addQuote(q);
            } else if (command.equals("3")) {
                System.out.println(ql.shareQuote());
            } else if (command.equals("4")) {
                this.ql.printQuotes();
            } else if (command.equals("x")) {
                //CALL TEXT CLASS HERE
                break;
            }
 
        }
    }
}

文本.java

import com.googlecode.lanterna.terminal.*;
import com.googlecode.lanterna.terminal.ansi.*;
import java.io.IOException;

public class Text {

    public static void main (String[] args) throws IOException {
        Terminal terminal = new DefaultTerminalFactory().createTerminal();
        terminal.enterPrivateMode();
        terminal.newTextGraphics().putString(20, 9, "Thank you for using Quote Generator!");
        terminal.flush();
        terminal.readInput();
        terminal.exitPrivateMode();
    }
}
4

0 回答 0