Version: v.0.1A
JForge is a lightweight, cross-platform Integrated Development Environment (IDE) for Java, built entirely with Java Swing. It provides a clean, modern dark interface for comfortably writing, compiling, and running Java code, making it an excellent tool for learning and small projects.
- Built-in Compilation and Execution: Compile and run your Java code with a single keystroke (F5), with results and errors displayed in an integrated console.
- Syntax Highlighting: Automatic highlighting of Java keywords, strings, and comments to improve code readability.
- Modern Dark Theme: A meticulously configured dark interface for all UI components, reducing eye strain.
- File Management: A full suite of operations: create, open, save, and "save as...".
- Data Loss Protection: The IDE automatically prompts to save unsaved changes before closing a file or exiting.
- Useful Editor Features:
- Line numbering.
- Undo/Redo functionality.
- Automatic UI adjustment to window size.
- Standalone: Requires no external dependencies other than an installed JDK.
- Cross-platform: Works wherever Java is installed (Windows, macOS, Linux).
- Java Development Kit (JDK) version 8 or newer. Important: A JDK is required, not just a JRE, as JForge uses the compiler.
- Ensure that
javacandjavaare available from your command line.
-
Clone the repository:
git clone https://github.com/Jacqquard/JForge-IDE.git cd JForge-IDE -
Compile the source code: Open a terminal in the project folder and run the command:
javac Main.java
-
Run the application: After successful compilation, run the command:
java Main
The project is intentionally contained within a single file for simplicity and clarity.
JForge/
β
βββ Main.java # All code: logic, UI, and helper classes
All code is located in the Main.java file, which contains two classes: Main and TextLineNumber.
- Constants and UI Setup (
applyDarkUIManagerSettings): At the beginning of the class, color constants for the dark theme are defined. TheapplyDarkUIManagerSettingsmethod usesUIManager.put()to globally apply these colors to all Swing components, creating a unified and cohesive look. initComponents(): This method is responsible for creating and laying out the main interface elements:JTextPane(editorPane): The main field for code input and editing.JTextArea(consoleArea): A non-editable area for displaying compilation results and program output.JSplitPane: Divides the editor and the console, allowing the user to resize them.TextLineNumber: Adds a line number panel to the left of the editor.
setupMenu(): Creates the top menu ("File", "Edit", "Build") and binds the corresponding actions (newFile,openFile,compileAndRun, etc.) to its items usingActionListeners. Hotkeys (Ctrl+N, F5) are also configured here.- File Operations (
newFile,openFile,saveFile,saveFileAs): Implement the file handling logic. TheconfirmClose()method checks for unsaved changes and asks the user for confirmation, preventing accidental data loss. compileAndRun()(Key Method): Implements the IDE's main functionality.- It checks if the current code is saved. If not, it prompts to save.
- If the file has not been saved to disk, the code is written to a temporary file named
TempClass.java. - It gets the system Java compiler via
ToolProvider.getSystemJavaCompiler(). - It starts the compilation, redirecting the error stream to a
ByteArrayOutputStreamfor later output to the console. - If compilation is successful, it creates a new process using
ProcessBuilderto run the compiled.classfile (java TempClass). - The output and error streams of this process are captured and displayed in real-time in the
consoleArea.
applyHighlighting(): The method responsible for syntax highlighting. It uses regular expressions (PatternandMatcher) to find keywords, comments, and strings in the editor's text and applies the corresponding styles (StyledDocument) to them.
- This helper class is a
JComponentthat draws line numbers next to theJTextPanetext area. - It "listens" for changes in the document (
DocumentListener) and the component (ComponentListener,PropertyChangeListener) to automatically repaint when text is added/removed, or the window or font size changes. paintComponent(): The main drawing method. It calculates which lines are currently visible and draws their numbers, synchronizing their position with the text in the editor.updatePreferredWidth(): Dynamically calculates the required width for the line number panel based on the total number of lines in the document (e.g., 1000 lines require more space than 99).
JForge is a classic desktop application built on the event-driven model of Java Swing.
- Launch: The
mainmethod creates an instance ofMain(which is aJFrame) and makes it visible within the Swing Event Dispatch Thread (EDT). - Event Loop: The application enters an event-waiting loop. All user interactions (keystrokes, mouse clicks, window resizing) generate events.
- Event Handlers: Special listener objects, attached to UI components, intercept these events. For example, clicking the "Save" menu item generates an
ActionEventthat calls thesaveFile()method. Typing in the editor generates aDocumentEvent, triggeringapplyHighlighting()and the repainting of the line numbers. - Compilation and Execution:
- Pressing F5 calls
compileAndRun(). - This method runs on the main EDT, but to execute the compiled program, it launches a separate system process (
java MyClass). - To prevent the UI from "freezing" while waiting for the running program to finish, its output is read in a separate background thread (
new Thread(...)). - Data from this background thread is passed back to the EDT using
SwingUtilities.invokeLaterto safely update theconsoleArea.
- Pressing F5 calls
This architecture allows for a responsive interface that does not block during long-running operations like compiling and running user code.
This project is distributed under the MIT License. See the LICENSE file for details.

