我正在尝试从本地目录打开jpg图像文件,只需将其绘制到屏幕上。
这是代码,但是图像位置没有引用并且会出现各种错误!
错误是:“找不到符号变量g”,这是指我努力绘制图像的位置(见代码底部附近)
我是一个学习者 - 很抱歉,如果它显而易见!感谢帮助: - )
import comp102.*;
import java.util.Scanner;
import java.awt.*;
/** A program that plays Rock-Paper-Scissors with the user.
*/
public class RPS{
String paper = "paper";
String rock = "rock";
String scissors = "scissors";
/** Play one round of RPS and print out the choices and the result */
public void playRound(){
String paper = "paper";
String rock = "rock";
String scissors = "scissors";
System.out.print ('\f'); // clears screen
Scanner currentUserSelection = new Scanner(System.in);
UI.initialise();
String enterText = null;
System.out.println("Make your Selection; Paper, Rock or Scissors: ");
enterText = currentUserSelection.next();
if(enterText == paper){
drawImage("paper-left.jpg", 100, 100, null);
}
}
}
答案 0 :(得分:0)
使用Graphics
设置变量public void paint(Graphics g){
//image code
}