DEBUG key: /en/osp/ide_environment
DEBUG locale: sr
DEBUG target: /en/en/osp/ide_environment
🇬🇧 EnglishIn this tutorial you will learn how to prepare your development environment for building physics simulations in Java using IntelliJ IDEA and the ACM library, before moving on to the OSP framework itself. The goal is to guide you step by step through the entire process—from installing the IDE, to creating a new project, to writing your first application that simulates a pendulum without using any OSP classes.
acm.jar
)acm.jar
in your project to use the graphical and interactive components provided by the ACM (Stanford CS) library.GraphicsProgram
.Once you have successfully mastered this introductory section, you will be ready to move on to using the Open Source Physics (OSP) libraries and creating more advanced 2D and 3D simulations.
.exe
file and follow the installer steps:
Configure → Project SDK → Add SDK
, then point to the JDK folder.A) Using the official .tar.gz
cd ~/Downloads
tar -xzf ideaIC-*.tar.gz
sudo mv idea-IC-* /opt/idea-community
sudo tee /usr/local/bin/idea << 'EOF'
#!/usr/bin/env bash
/opt/idea-community/bin/idea.sh "$@"
EOF
sudo chmod +x /usr/local/bin/idea
You can now launch IntelliJ by typing idea
in your terminal.
B) Using Snap (Ubuntu, Mint…)
sudo snap install intellij-idea-community --classic
File → Settings → Plugins
, search for “Educational” and install the JetBrains Academy or Educational plugin.Before diving into developing your simulations or any other Java projects, you need to properly configure your IDE. The following steps will guide you through the essential IntelliJ IDEA settings: from integrating the JDK, to installing additional plugins, and customizing keyboard shortcuts and themes.
The first and most important step is to add your locally installed Java Development Kit (JDK) to IntelliJ IDEA. This enables compilation and execution of your Java applications.
File → Settings → Build, Execution, Deployment → SDKs
IntelliJ IDEA → Preferences → Build, Execution, Deployment → SDKs
+ → Add SDK → JDK
button.bin
, lib
, etc.):
C:\Program Files\Java\jdk-11.0.12
(Windows)/usr/lib/jvm/java-11-openjdk
(Linux)Project Structure → Project
and in the Project SDK field select the JDK you just added.To work with other languages and tools inside IntelliJ IDEA, install the appropriate plugins.
File → Settings → Plugins
(or IntelliJ IDEA → Preferences → Plugins
).IntelliJ IDEA lets you choose among predefined keymaps and UI themes to make your workspace more comfortable.
Settings → Keymap
– select “Default”, “Eclipse”, “Visual Studio”, or another layout.Settings → Appearance & Behavior → Theme
– choose “Darcula” (dark) or “IntelliJ Light.”
If you installed IntelliJ IDEA via the .tar.gz
archive, on its first launch the IDE will offer to create a desktop entry
for quick access from your application menu.
If that prompt does not appear automatically:
sudo tee /usr/local/bin/idea << 'EOF'
#!/usr/bin/env bash
/opt/idea-community/bin/idea.sh "$@"
EOF
sudo chmod +x /usr/local/bin/idea
idea
or find it in your desktop environment’s applications menu.To ensure your Java project in IntelliJ IDEA runs without errors, you need to correctly add and configure the Java Development Kit (JDK). Below is a detailed step-by-step guide walking you through the entire process, from opening the settings to selecting the new Project SDK.
File → Settings
IntelliJ IDEA → Preferences
Project Structure
(or press Ctrl+Alt+Shift+S
).
+
icon next to the SDK list and choose JDK
.
bin
and lib
subfolders. For example:
C:\Program Files\Java\jdk-11.0.12
(Windows)/usr/lib/jvm/java-11-openjdk
(Linux)Important: Make sure to select the JDK’s root folder, not a subdirectory.
OK
.
Project Structure → Project
again and in the Project SDK dropdown select the JDK you just added (e.g., Java 11).
After these steps, IntelliJ will use the selected JDK to compile and run your Java applications. You are now ready to continue working on your simulations or other Java projects.
In the following section, we will guide you through setting up a brand-new Java project in IntelliJ IDEA
without relying on the OSP libraries. Instead, we’ll use acm.jar
from the Stanford Java Task Force,
which is ideal for simple graphical and educational applications.
First, we’ll set up the basic project structure inside IntelliJ IDEA.
src
directory.
acm.jar
LibraryThe ACM library makes it easy to draw and use interactive GUI components for educational purposes. Follow these steps to download and include it:
acm.jar
from the Stanford site:
acm.jar
link directly:
acm.jar
+ → JARs or directories…
.acm.jar
and confirm with Compile scope.acm.jar
acm.jar
is a library developed by the Stanford team as part of the book
The Art and Science of Java (Eric Roberts). It’s designed for students to build simple graphical applications.
Main advantages:
acm.jar
The following code shows a simple GraphicsProgram
that draws a circle on the screen:
import acm.program.*;
import acm.graphics.*;
public class PendulumWithoutOSP extends GraphicsProgram {
public void run() {
GOval circle = new GOval(100, 100, 50, 50);
add(circle);
}
public static void main(String[] args) {
new PendulumWithoutOSP().start(args);
}
}
After running successfully, a window with a circle will appear. From there, you can implement the pendulum animation using numerical integration and periodic screen updates.
For more information on physics simulations using Swing and AWT, visit:
acm.jar
)
acm.jar
GraphicsProgram
, GLine
, GOval
, etc.
These resources cover everything from library downloads and introductions to JavaDocs and advanced GUI tutorials.
import acm.program.*;
import acm.graphics.*;
import java.awt.*;
public class PendulumSimulation extends GraphicsProgram {
private static final int PENDULUM_LENGTH = 200;
private static final double PERIOD = 2000; // in milliseconds
private static final double AMPLITUDE = 100;
private GLine rod;
private GOval bob;
public void run() {
setSize(400, 400);
int centerX = getWidth() / 2;
int topY = 50;
// create pendulum bob
bob = new GOval(20, 20);
bob.setFilled(true);
bob.setColor(Color.RED);
add(bob);
// create pendulum rod
rod = new GLine(0, 0, 0, 0);
add(rod);
while (true) {
long time = System.currentTimeMillis() % (long)PERIOD;
double angle = AMPLITUDE * Math.sin(2 * Math.PI * time / PERIOD);
double x = centerX + PENDULUM_LENGTH * Math.sin(Math.toRadians(angle));
double y = topY + PENDULUM_LENGTH * Math.cos(Math.toRadians(angle));
bob.setLocation(x - bob.getWidth()/2, y - bob.getHeight()/2);
rod.setStartPoint(centerX, topY);
rod.setEndPoint(x, y);
pause(10);
}
}
/** Entry point for launching the application */
public static void main(String[] args) {
new PendulumSimulation().start(args);
}
}
Below is an overview of the main parts of the code and an explanation of what happens when you extend the ACM class GraphicsProgram
,
as well as how the animation of the pendulum is set up and executed in the run()
method.
GraphicsProgram
In the public static void main(String[] args)
method, we create an object of the MatematickoKlatno
class and call
start(args)
. This triggers the ACM application lifecycle:
init()
– initialization before run()
is executed.run()
– the main animation logic.start()
and stop()
– called when the program starts and stops.At the beginning of the class, we define constants to control the pendulum's behavior:
PENDULUM_LENGTH
– length of the pendulum in pixels.PERIOD
– oscillation period in milliseconds.AMPLITUDE
– maximum angle or displacement in pixels.
Next, we declare graphical objects:
GLine string
for the pendulum string and GOval ball
for the pendulum bob.
run()
Method – Setup and Main LoopsetSize(600, 600)
defines the dimensions of the main window.GOval
and GLine
, set their properties and add them to the canvas using add(...)
.while(true)
loop continuously calculates positions and updates the display.while(true)
Looplong time = System.currentTimeMillis() % (long)PERIOD;
double angle = AMPLITUDE * Math.sin(2 * Math.PI * time / PERIOD);
double x = centerX + PENDULUM_LENGTH * Math.sin(Math.toRadians(angle));
double y = topY + PENDULUM_LENGTH * Math.cos(Math.toRadians(angle));
ball.setLocation(x - ball.getWidth() / 2, y - ball.getHeight() / 2);
string.setStartPoint(centerX, topY);
string.setEndPoint(x, y);
pause(10);
introduces a short delay for smooth rendering.
GraphicsProgram
Class
The GraphicsProgram
class from the ACM library automatically creates a GUI window and a canvas,
invokes init()
and run()
, and provides convenient methods:
add(GObject obj)
/ remove(GObject obj)
getWidth()
/ getHeight()
pause(int ms)
addMouseListeners()
, addKeyListeners()
setSize(width, height)
, setBackground(Color)
GLine
and GOval
ClassesGLine
new GLine(x1, y1, x2, y2)
setStartPoint(x, y)
, setEndPoint(x, y)
GOval
new GOval(width, height)
setFilled(true/false)
, setColor(Color)
setLocation(x, y)
By extending these classes, you get a fast and simple way to draw and animate in Java applications.