TheFatIndian
TheFatIndian

Reputation: 11

Is there an easy way to print a graphical menu to console in Java?

So this is for an assignment (which I've already completed), I just left this part out because it seemed like a pain in the ass while I was working on the pattern logic.

The assignment asks that you print this menu graphic to help the user decide which pattern to pick. Is there an easy way to do it or do I just need to get a ton of printf/println statements in there? Seems like a very awkward thing to code. Here's an example:

Menu

EDIT: This is just for the graphical menu. I know I have to use loops for the actual patterns (which I've already done). The assignment is essentially finished, just missing this menu. I wasn't sure how best to print out this graphic horizontally without awkwardly formatting it by hand.

Upvotes: 1

Views: 2695

Answers (2)

Renat Gilmanov
Renat Gilmanov

Reputation: 17895

Text UI has been implemented so many times. Instead of spending some time trying to develop yet another text-based selection/navigation components try to use available solutions:

Fully featured text UI -- Lanterna

enter image description here

Shell-like approach -- JLine

enter image description here

There is another interesting answer, which provides two other, but not so good options.

Upvotes: 1

Brian Agnew
Brian Agnew

Reputation: 272417

I think it depends on whether you're going to be assessed on it.

My engineering head tells me that if you're not going to be assessed on it, getting the formatting correct is going to be fiddly and I would just reduce it down to 5 or so println()s, the implementation of which is nothing more than typing.

There's nothing to be ashamed of in such circumstances by choosing what appears to be a trivial exercise. Of course if part 2 of your assessment asks you to extend this to 6 lines (or similar) then a more extensible solution would be appropriate.

I note (following your edit) that you have pattern methods to generate the above. In that case you may wish to modify their inputs/outputs appropriately to facilitate the above. e.g. perhaps they could take in an array of 'n' lines, and append the pattern to those lines, line by line. You'd also need some justification method to pad those lines for the next pattern generator.

Upvotes: 0

Related Questions