简体   繁体   中英

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:

菜单

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.

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

在此处输入图片说明

Shell-like approach -- JLine

在此处输入图片说明

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

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. eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM