-1
我問你是否有方法在應用程序(窗口)啓動之前從命令行參加輸入。我如何參加終端輸入?
這裏的,如果它可能是有用的代碼:
package classi.luca;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Scanner;
public class Test1 extends JPanel {
public void paint(Graphics g) {
super.paint(g); // call superclass to make panel display correctly
System.out.print("Do you want to visualize Circle data or Rectangle data? ");
Scanner in = new Scanner(System.in);
String figure_init = in.next();
FiguresInit figure = new FiguresInit(); // create a FiguresInt variable
switch (figure_init) {
case "Circle": figure.initCircle(g); // Initialize a Circle from FiguresInit
break;
case "Rectangle": figure.initRectangle(g);
break;
}
}
public static void main(String[] args) {
Test1 panel = new Test1();
FrameClass fr = new FrameClass("Disegno e Area del Cerchio"); // Inizialize a drawing panel of FrameClass Type
fr.init(panel);
panel.setBackground(Color.WHITE);
}
}
有沒有辦法出席打開應用程序窗口前System.in
掃描?
確定。我怎樣才能將'figure'傳遞給'Test1'? @Burkhard –
@LucaPierri看看他的代碼,他已經這樣做了(並在代碼上面的他的句子中寫到)。 – Tom
好的,非常感謝! –