0

だから私は特定のフォントを表示するためにこのプロジェクトをやっています。問題は、元のコードが機能することですが、スキャナーを使用しようとすると機能しません

オリジナルコード

 public static void main(String[]args)
{
font("Times New Roman");
}

public static void font(String x){
World canvas = new World();//Creates a new world called canvas
Graphics picGraphics = canvas.getGraphics();//creates picGraphics which gets used in the world
picGraphics.setColor(Color.MAGENTA);//Color is set to Magenta
Font font = new Font(x,Font.BOLD,80);
picGraphics.setFont(font);//sets the font
//drawString parameters tell the string that is written and the coordinates to place the word
picGraphics.drawString("Font Tester",105,255);
canvas.repaint();
}

今すぐスキャナーでコードを

public static void font2(){
World canvas = new World();//Creates a new world called canvas
Graphics picGraphics = canvas.getGraphics();//creates picGraphics which gets used in the world
picGraphics.setColor(Color.MAGENTA);//Color is set to Magenta
Scanner keyboard=new Scanner(System.in);
String x = keyboard.next();
Font font = new Font(x,Font.BOLD,80);
picGraphics.setFont(font);//sets the font
//drawString parameters tell the string that is written and the coordinates to place the word
picGraphics.drawString("Font Tester",105,255);
canvas.repaint();
}

そのコードでわかるように、ユーザーがプログラムに表示するフォントを直接入力できるように、スキャナーがあります。ただし、Time New Roman などの例でその新しいコードを使用するたびに、ウィンドウに表示されるフォントは Times new Roman ではなく、Arial に似ています... また、スキャナをメイン メソッドに配置しようとしましたが、これもそうではありません。 t 異なる結果を与える

ヘルプ?

ところで: World canvas = new World(); その他のビットは、フォントを表示できるポップアップ空白ウィンドウの表示に役立ちます

ありがとう

4

1 に答える 1