acm-java-libraries

How to write my Java program with the ACM library (ConsoleProgram)?

故事扮演 提交于 2020-01-04 15:30:28
问题 I want ask a little question about my program. This is my code sample: public static void main(String[] args) { int q; int p; int thelargest; int thesmallest; Scanner input = new Scanner(System.in); System.out.println("Enter the list of number : "); String input2 = input.nextLine(); String[] numbers = input2.split(" "); int[] result = new int[numbers.length]; for (p = 0; p < numbers.length; p++) { result[p] = Integer.parseInt(numbers[p]); } for (q = 0; q < result.length; q++) { System.out

Move a ball on mouse click in Java

亡梦爱人 提交于 2019-12-11 14:42:54
问题 I'm trying to create the classic Breakout game as part of my programming assignment. I have to start moving the ball on a mouse click from the user. So I'm using a mouselistener to achieve that. The code below is just a smaller, simpler version of what I'm trying to do. But it does not move the ball in gradual steps. It just displays the ball at it's final position after the while loop is done executing. import acm.graphics.*; import acm.program.*; import acm.util.*; import java.applet.*;

Cannot move an image

陌路散爱 提交于 2019-12-11 05:41:51
问题 I am trying to move an image from right to left. The image I am trying to move is drawTrain method in another class. I think I have to use drawTrain method with move() method. However, I do not know how to do that.. Or I'm totally wrong and there has to be another solution. So far, I tried to use something like train.drawTrain.move(movex, 0); train.drawTrain(0, 0).move(movex, 0); well.. failed.. I tried to search and google and everything, but I'm just sitting and spending several hours. If

Java ACM package

守給你的承諾、 提交于 2019-11-30 05:30:35
问题 I'm trying to write a java application in Eclipse. I'm really wanting to use the ACM.Program package, however, my copy of Eclipse doesn't have it installed! I've looked all over the net, and I can't find a single download for the ACM package. More info: Whenever I try the code: package helloGeiodo; import acm.program.*; public class Add2 extends Program { public void run() { println("This program adds two numbers."); int n1 = readInt("Enter n1: "); int n2 = readInt("Enter n2: "); int total =

ACM Interactors Freeze

偶尔善良 提交于 2019-11-27 05:39:13
I'm trying to make a very simple program with Swing and ACM interactors. It is taken directly from a class handout, but does not function on my computer. When I run it, it functions fine for about half a second, then briefly flashes, reloads, and then all button and text-field functionality is lost. Here's the code: import acm.program.*; import java.awt.event.*; import javax.swing.*; public class TextFieldExample extends ConsoleProgram { public void init() { nameField = new JTextField(15); add(new JLabel("Name: "), SOUTH); add(nameField, SOUTH); nameField.addActionListener(this); } public void

ACM Interactors Freeze

寵の児 提交于 2019-11-26 11:39:29
问题 I\'m trying to make a very simple program with Swing and ACM interactors. It is taken directly from a class handout, but does not function on my computer. When I run it, it functions fine for about half a second, then briefly flashes, reloads, and then all button and text-field functionality is lost. Here\'s the code: import acm.program.*; import java.awt.event.*; import javax.swing.*; public class TextFieldExample extends ConsoleProgram { public void init() { nameField = new JTextField(15);

Java Code for calculating Leap Year

ε祈祈猫儿з 提交于 2019-11-26 00:43:53
问题 I am following \"The Art and Science of Java\" book and it shows how to calculate a leap year. The book uses ACM Java Task Force\'s library. Here is the code the books uses: import acm.program.*; public class LeapYear extends ConsoleProgram { public void run() { println(\"This program calculates leap year.\"); int year = readInt(\"Enter the year: \"); boolean isLeapYear = ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)); if (isLeapYear) { println(year + \" is a leap year.\"); }