java - 我需要在它们的 Y 轴上移动两个形状,我该怎么做?
问题描述
我的作业中的问题需要一个从原始状态向上移动 50 像素的箭头。它需要一个“moveUp”方法,我需要使用setYInt()
andgetYInt()
方法来做到这一点。
这是我当前的代码:
import java.awt.*;
public class Arrow {
private Canvas canvas;
private Triangle head = new Triangle(120, 500, 50, 50, true);
private Rectangle shaft = new Rectangle(140, 550, 10, 100);
public Arrow(Canvas _canvas) {
canvas = _canvas;
Triangle head = new Triangle(120, 500, 50, 50, true);
Rectangle shaft = new Rectangle(140, 550, 10, 100);
}
public void draw() {
canvas.draw(head);
canvas.draw(shaft);
}
public void erase() {
canvas.erase(head);
canvas.erase(shaft);
}
public void moveUp() {
head.getYInt();
shaft.getYInt();
head.setYInt(head.getYInt - 50);
}
}
我在使用此代码时遇到的错误:
Arrow.java:32: error: cannot find symbol
head.setYInt(head.getYInt - 50);
^
symbol: variable getYInt
location: variable head of type Triangle
1 error
我不明白我应该如何获取 Y 整数并将其设置为不同的整数。任何帮助表示赞赏。
解决方案
head.setYInt(head.getYInt - 50);
您正在使用head.getYInt
which 不是功能。试试.getYInt()
吧。
推荐阅读
- google-apps-script - 带有编码的 Google 表格 IMPORTDATA
- android - 在实时应用程序中反应本机 udp 问题
- javascript - React Auth:承载未定义(401未授权)
- django - Django MultiSelectField 如何在表单中设置 disabled=True
- flutter - Row Flutter 内的响应式容器
- apache-camel - 当肥皂故障时,Camel cxf 导致 I/O 调度程序线程 100% CPU
- html - WordPress Bootstrap5 Navbar 未与其他 col div 对齐
- mysql - MySQL 在添加新的复合索引时是否会在表上获得锁?
- c# - 如何在elasticsearch中将字段类型从字符串更新为字符串数组?
- c# - ASP.NET CORE / 添加 .AddSignInManager 时遇到的问题
>(); 在启动类