Skip to content

NCurses Implementation written in Java, with a Wrapper for making GUIs

Notifications You must be signed in to change notification settings

CommandJoo/Java-Native-NCurses

Repository files navigation

Welcome to Java-Native-NCurses 👋

Version

c java

Java NativeCurses is an NCurses wrapper written in Java, it provides direct access to many NCurses methods, and also provides an API for directly creating GUIs using Windows Buttons and Text fields


Quickstart

Download The latest version and add it as a Library to your Project

Alternatively Clone the Repository

git clone https://github.com/CommandJoo/Java-Native-NCurses

Usage

Running the Application

Building the library:

  • compiling and linking the library
cd ./src/native
make compile
make lib
  • Generating the header and then compiling and linking the library
cd ./src/native
make

Running the Jar

java -jar "build/libs/JavaCurses.jar"
#or
./run

Creating a GUI in Java NativeCurses

...
public static void main(String[] args) {
    int fps = 30;//too high fps will cause flickering
    int width = 40;//minimum width in characters
    int width = 10;//minimum height in lines
    WindowManager windowManager = new WindowManager(fps, width, height);
    Window window = windowManager.addWindow(0, new MyWindow());//add a window to the screen and make it be the actively rendered one
    
    windowManager.render();//starts the drawing
    windowManager.handleKey();//starts listening for inputs
}
public class MyWindow {
    public MyWindow() {
        super(null,
                Curses.width() / 2 - 30, //x position
                Curses.height() / 2 - 6, //y position
                60, //width in characters
                12, //height in lines
                ColorBuilder //create a new color pair
                        .create()
                        .defineForeground(new Color(70, 200, 150)) //Java Colors and Hex are supported
                        .defineBackground(1) //default black -> NativeCurses.BLACK
                        .build(), //get the color pair id
                        "MyWindow", //title
                        true //rounded corners
            ); 
    }
    
    public void init() {
        //initialize your components like Textfields
    }
    
    public void draw() {
        //Draw things like Text which aren't a component
    }
    
    public boolean handleKey(char ch) {
        return this.handleKeysForSub(someComponent, ch);//returns if a key has been handled by a component
        
    }
}

A working example of all the basic components and formatting can be found in ExampleProject
A Simple Snake-Game can also be found here: Snake


Author

Johannes Hans (@CommandJoo)

Show your support

Give a ⭐️ if this project helped you!