Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm trying to make a coding game, for players to start learning Java. I created a post yesterday about the multi-row textfield(I need it for the actual in-game Java IDE). Since then I started to work on a multi-row text filed. I added the basics:

https://streamable.com/buse32

 

As you can see from the video it works, but there are some things missing(cursor, navigating trough code with arrow keys, CTRL+A, select, CTRL+C, CTRL+V, etc). I have no idea how to imlement theese things. Here is may code(GUI class):

Console console = new Console();

	@Override
	public void drawScreen(int x, int y, float ticks) {
		returns[0] = 0;
		int guiX = (width - guiWidth) / 2;
		int guiY = (height - guiHeight) / 2;
		
		//GL11.glColor4f(1, 1, 1, 1);
	
		mc.renderEngine.bindTexture(new ResourceLocation("jp", "textures/gui/java_final.png"));
		drawTexturedModalRect(guiX, guiY, 0, 0, guiWidth, guiHeight);
		
		
		
		for(int j = 1; j <= rows; j++) {
			String row = "nothing yet";
			int i;
			for(i = 1, row = ""; i <= letterCount; i++) {
				if(returns[j] != 0) {
					if(i < returns[j] && i >= returns[j-1]) {
					
						row += Keys[i];
						fontRendererObj.drawString(row, guiX + 10, guiY + 40 + (j - 1) * 10, 0x5e757d);
					
					}
				}
				if(returns[j] == 0) {
					if(i >= returns[j-1]) {
						row += Keys[i];
						fontRendererObj.drawString(row, guiX + 10, guiY + 40 + (j - 1) * 10, 0x5e757d);
						
					}
				}
				
				
				
			}
			
			
		}
		super.drawScreen(x, y, ticks);
				
		
		
	}
	
	
	
	@Override
	protected void keyTyped(char c, int key) {
		//change the "fontRendererObj.drawString("String before any key", guiX + 10, guiY + 40, 0x5e757d);" text to the key tapped
		switch(key) {
		case Keyboard.KEY_BACK:
			if(letterCount >= 1) {
				Keys[letterCount] = null;
				letterCount--;
				if(returns[returnCount] == letterCount + 1) {
					returns[returnCount] = 0;
					returnCount--;
					rows--;
				}
				
			}
			console.log("Returns: ");
			for(int cnt = 1;cnt <= returnCount; cnt++) {
				console.log(returns[cnt] + " ");
				
			}
			console.newline();
			console.log("Keys: ");
			for(int cnt = 1;cnt <= letterCount; cnt++) {
				console.log(Keys[cnt] + " ");
				
			}
			console.newline();
			console.log("Retrun Count: " + returnCount);
			console.newline();
			console.log("Rows: " + rows);
			console.newline();
			console.log("Letter Count: " + letterCount);
			console.newline();
			break;
		case Keyboard.KEY_ESCAPE:
			mc.displayGuiScreen(null);
			break;
		case Keyboard.KEY_RETURN:
			rows++;
			returnCount++;
			returns[returnCount]=letterCount + 1;
			console.log("Returns: ");
			for(int cnt = 1;cnt <= returnCount; cnt++) {
				console.log(returns[cnt] + " ");
				
			}
			console.newline();
			console.log("Keys: ");
			for(int cnt = 1;cnt <= letterCount; cnt++) {
				console.log(Keys[cnt] + " ");
				
			}
			console.newline();
			console.log("Retrun Count: " + returnCount);
			console.newline();
			console.log("Rows: " + rows);
			console.newline();
			console.log("Letter Count: " + letterCount);
			console.newline();
			break;
			
		default:
			if(c >= 32 && c <= 127) {
				letterCount++;
				Keys[letterCount] = c + "";
				console.log("Returns: ");
				for(int cnt = 1;cnt <= returnCount; cnt++) {
					console.log(returns[cnt] + " ");
					
				}
				console.newline();
				console.log("Keys: ");
				for(int cnt = 1;cnt <= letterCount; cnt++) {
					console.log(Keys[cnt] + " ");
					
				}
				console.newline();
				console.log("Retrun Count: " + returnCount);
				console.newline();
				console.log("Rows: " + rows);
				console.newline();
				console.log("Letter Count: " + letterCount);
				console.newline();
				
			}
			break;
		
		}
		
		
		
	}

 The console class is just a class I made to avoid writing "System.out.println" every time I want to print in console something:

package com.mikeyjy.methods;

public class Console {

	public void log(Object obj) {
		System.out.print(obj);
	}
	public void newline() {
		System.out.println();
	}
}

 

Edited by MikeyJY

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.