问题标签 [acm.graphics]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
10641 浏览

java - 无法找到/安装 Java 包 acm.graphics

我收到以下错误消息

这表明我没有 acm.graphics -package。

我试图通过以下方式在 MacPorts 中查找并安装该软件包失败

如何在您的计算机上安装 acm.graphics 包以用于 Java?

0 投票
1 回答
918 浏览

java - java中的窗口尺寸Gcanvas noob问题

我是一名高中生,通过视频在斯坦福学习 cs106a。

对于我当前的任务,我必须添加 GObjects 并将它们相对于窗口的大小定位。

我目前正在尝试使用命令获取窗口的宽度

我是一名高中生,通过视频在斯坦福学习 cs106a。

对于我当前的任务,我必须添加 GObjects 并将它们相对于窗口的大小定位。Gcanvas 作为一个类创建并在另一个类中实现。

类的头部和构造函数如下:

我目前正在尝试使用 drawGrid() 方法中的命令获取窗口的宽度。使用命令:

int width = getWidth();

但是宽度 = 0

可能导致这种情况的一件事:这是我使用多个类编写的首批程序之一。

谢谢您的帮助!

0 投票
3 回答
3529 浏览

java - 调用 GOval 方法

我不知道我是否正确调用了 GOval 方法。我的目标是创建目标公司徽标,但带有 5 个圆圈。我应该让目标符号在窗口中居中,并且圆的数量和尺寸由命名常量控制。

我从 GOval bigCircle 开始,那是我最外层的红色填充圆圈。我是否正确合并了 createFilledCircle 方法?

到目前为止,我只有三个圆圈,因为我们正在建立之前的作业,而那个作业只有三个圆圈。另外,N_CIRCLE 是如何融入图片的?

0 投票
1 回答
241 浏览

java - 无法使用 eclipse 显示 acm 图形

我一直在努力让 acm 图形在 Eclipse 中显示。当我简单地运行以下代码时,小程序启动但没有显示任何内容。该类位于源目录中的默认包中。提前感谢您的任何反馈。

0 投票
2 回答
1664 浏览

java - 使用 acm.graphics 时 mouseListener 的语法是什么

我有一个“按钮”,它只是GRect来自ACM Graphics Library。它有一个addMouseListener我尝试过(但失败了)的继承方法。我需要知道语法,以便当有人单击“按钮”时,我可以调用位于同一类中的另一个方法。

我想知道:

  1. ButtonName.addMouseListener还是addMouseListener(ButtonName)
  2. 我可以在创建按钮后立即放置上面提到的行吗?
  3. 允许单击按钮调用某些东西的语法是什么?
  4. 问题 3 中的语法应该去哪里?它有自己的类吗?

我截断的代码:

我的完整代码:

0 投票
1 回答
243 浏览

java - getWidth not working correctly as class variable

I am very new to java (and programming in general) and I trying to make a program that simply draws a vertical line down the centre of the screen. To do this, I made a variable x which gives me the x coordinate of the centre of the screen. I wanted to be able to use this variable within other private methods. When I run the code however, no line appears, as if x were set to 0.

If I put my variable x inside the run() method as below, the line is drawn correctly, but then I would not be able to use it later in other private methods as it is my understanding that then the variable would no longer be class variable but an instance variable and therefor only accessible by run() and no other methods?

Could someone enlighten me as to why the first code does not work whereas the second one does? Thank you very much in advance!

0 投票
1 回答
364 浏览

java - acm.graphics 的关键监听器

与这个问题有些相关。

我有一个内置在ACM 图形库中的游戏。我希望能够在按下P 键时暂停游戏。但是,我查看了文档,似乎简要提到了关键侦听器,但没有在这种情况下使用它们的实际示例(除非我错过了某些东西)。

我不想使用控制台或对话框,因为我不想通过键盘输入数据,我只想能够在我的主游戏循环中使用P 键打开和关闭我的暂停方法。这可能吗?