Java Console Applet?

Is it possible to make a Java applet that runs just like a console.
Like, you’d have a console screen embedded in the page that you’re running your applet in.
Your applet would have no visual interface, just a console one.

I’m using the Eclipse environment to program this.

(And to everyone who’ll say ‘boo java’s ded language,’ I have to use this language for my IB Computer Science course in school. This project is my dossier.)

  1. I don’t know
  2. I’m sure it’s easier with NetBeans

you realize 1 contradicts 2, right?

What? Do you mean making a program that just uses a TUI?

If so, then yes.

Can it be made like a console, without having to code a whole console interface? (for an applet, not application)

It completely depends on what the console is to be able to do.
If it has simple commands that’s one thing (e.g. quake1’s console), but if it has more of a functional/expression based syntax that’s a whole other ballgame (serious sam’s console for example).
Anything is possible, given sufficient time.
If you do go for a more complex console syntax/abilities, I’d recommend using a parser generator tool such as javacc or freecc to make that part much easier. If it’s simple, then a hand-crafted state machine would work just fine.

https://www.aperturescience.com/
Is this kind of thing your after? (minus the feed of course)

Yes I’ve coded the console application as …well, an application. I’d like to be able to embed it into a webpage as an applet. As far as I can tell about applets, they have to be graphical. I’m hoping that I’m just mistaken, and this isn’t the case at all.

Something like this?

Thanks, Will! I have it all set up now in my project, but I don’t know how to actually utilize it. I’m a total Java newbie.

I’m not really too familiar with Java either, I only just started programming with it a few months ago with emphasis on object-oriented implementation. I’m more into C.

I did a couple of years of Java at uni, but since joining the working world I’ve moved onto C#/.Net. As far as I know Applets utilise a GUI automatically to allow them to work as embeddable objects, so access to the main Java console isn’t possible.

The Applet has a rectangle of screen it can draw on (or more usually populate with controls). There is nothing stopping you adding a single textarea and handling the text entry into it as if it was a dos box, or perhaps more likely, adding a textarea with an input field below it, so as to make historical output non-editable.
You can then colour/align things so they look like they are one thing.

Like I said, anything is possible with the application of enough time and skill, and skill comes with practice, which takes time. Tho talent helps too I guess.

Thanks for all your help, guys. But it looks like I’ll have to code an entire console interface for the applet, which is just out of the scope of my dossier.
Thanks again though!
-Dillon

Coding a simple console is easy tho. Chuck a readonly textarea and an editable text field on, and whenever someone presses enter in the text field, read it’s contents and do something based on what the start of it is.
e.g. // on enter: if (enteredText.startsWith("echo")) { // code for echo command here... } else if (enteredText.startsWith("dir")) { // code for dir command here... } //... else { outputArea.addText("\nSupported commands are..."); // or however this is done - been a while... }

No no, I have a command system set up currently. I mean the actual console interface itself, not the whole command parsing / executing system.

Never heard of a switch statement…?

And I inferred that he meant the ACTUAL Java console, not inventing your own one.

switch statements need a jumpable index so can’t use strings or general expressions in all C based languages - others do allow switching on a string, but last I checked, not Java, and not on an expression like the above definitely.
That said, if it were any more complex then I’d advise having a tokeniser and a switch statement on the token ID. Just trying to keep my example simple enough for anyone to follow as I have no idea what level people are at with their coding, so applying the entirety of my 20+ years as a coder might not get the best result…

As for the actual Java console, that lives in the systray when a Java applet starts, no - to my knowledge there is no access to it, but definitely not for input anyway.

One other thing I would recommend tho: make your console app exactly that - something you can run from the command line and use straight text input/output, and have a layer handling input/output that can be swapped for the applet version.
This allows you to quickly test stuff even if the applet interface is not ready yet, and allows you to itterate its form e.g. you have a commandline (cmd window) layer, a version 0 applet layer that has a text field for input and another for output but no prettyness, and a version X one that is as fancy as you want, if you have time to work on it. Meanwhile the core code is separate and can be worked on independently.

Founded in 2004, Leakfree.org became one of the first online communities dedicated to Valve’s Source engine development. It is more famously known for the formation of Black Mesa: Source under the 'Leakfree Modification Team' handle in September 2004.