Join 149,708 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,273 people online right now. Registration is fast and FREE... Join Now!
I am working with some studnets on various projects which they have been asked to complete to earn a certificate in high school level computer science. The structure of their program and curriculum are highly regulated by a 3rd party organization....like the SAT tests are.
During my first year in this program with them I followed the rules I was given too closely. They were not supposed to have to learn or know any code relating to GUI's. Their program is actually graded on paper! Although I must certify it before it leaves the school.
Anyway they need to make a menu that fires their main classes. The menu needs to look like this:
The programs are all going ok -- simple database things based on xml.
But the only experience I have with Java is limited and limited to Guis. Because I did not teach the GUI -- i messed up thinking it would be easy to find and study old-school menu examples.
They get no points for any gui or graphic elements.
Anyway if anyone can direct me to a tutorial --or if you have a simple file I can start with I would appreciate it.
I should have lots of files to contribute as well. I will keep posting around.
I've read through your post a bunch of times, but I'm not sure that I really understand your problem.
Are you having trouble teaching how to build guis, or are you having trouble with the idea of creating a program where a user controls the flow of the program depending on their input?
If that's really what you mean, taking input from the console, I've got a very easy solution for you.
Use the Scanner class.
CODE
import java.util.Scanner.*;
public class ReadConsole { public static void main(String[] args) { Scanner input = new Scanner(System.in); String read = input.nextLine(); Int num = input.nextInt(); } }
The Scanner class is very easy to use, and it prevents you from needing to understand all of the wrapping that goes on with the IO package.
Just create a new Scanner object like I did with the constructor above. Then, everytime you call input.nextLine() or input.nextInt(), the console will wait for you to input some data, which is immediately stored in the variable preceeding the call.
Wow! So much good feedback. I will let my kids try it out and I as well and then post our results!
Tony D aka codeninja the domination
QUOTE(keems21 @ 16 Feb, 2007 - 07:44 PM)
If that's really what you mean, taking input from the console, I've got a very easy solution for you.
Use the Scanner class.
CODE
import java.util.Scanner.*;
public class ReadConsole { public static void main(String[] args) { Scanner input = new Scanner(System.in); String read = input.nextLine(); Int num = input.nextInt(); } }
The Scanner class is very easy to use, and it prevents you from needing to understand all of the wrapping that goes on with the IO package.
Just create a new Scanner object like I did with the constructor above. Then, everytime you call input.nextLine() or input.nextInt(), the console will wait for you to input some data, which is immediately stored in the variable preceeding the call.
I looked over everything and most of it I already knew how to do. The scanner class was new.
What I am missing- and again maybe it is just too old school ---
When the program starts I would like a list of options to appear on the screen.
-- I can do that.
Then when a user presses the 1 key on the keyboard I would like to call a method.
--I can call the method I just need to know how to assign the number 1 on the keyboard so it works the same as clicking the mouse on a Button.
--I am going to try this with the scanner class by storing the info in a variable but I thought each key had a number that could be accessed and then I am assuming there is an api available to help work with it.
Ideas?
I am having my students do the tutorials today as they are well written and should reinforce alot of needed skills.
Thanks.
Codeninja
QUOTE(codeninja @ 17 Feb, 2007 - 11:31 AM)
Wow! So much good feedback. I will let my kids try it out and I as well and then post our results!
Tony D aka codeninja the domination
QUOTE(keems21 @ 16 Feb, 2007 - 07:44 PM)
If that's really what you mean, taking input from the console, I've got a very easy solution for you.
Use the Scanner class.
CODE
import java.util.Scanner.*;
public class ReadConsole { public static void main(String[] args) { Scanner input = new Scanner(System.in); String read = input.nextLine(); Int num = input.nextInt(); } }
The Scanner class is very easy to use, and it prevents you from needing to understand all of the wrapping that goes on with the IO package.
Just create a new Scanner object like I did with the constructor above. Then, everytime you call input.nextLine() or input.nextInt(), the console will wait for you to input some data, which is immediately stored in the variable preceeding the call.
I'm not sure I understand exactly what you'd like...simply to display your list of choices, then take input from the user, and perform a set of actions based on that input. Is that correct?
CODE
import java.util.Scanner.*;
public class ReadConsole { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Menu System - Please enter your choice"); System.out.println("Option 1"); System.out.println("Option 2"); System.out.println("Option 3"); Int num = input.nextInt(); if(num==1) functionforoption1(); else if(num==2) functionforoption2(); else if(num==3) functionforoption3(); else //default case } }
Of course, there are a million ways to do it - case statements might be more beneficial here.
It sounds like what you're asking is if you can set up a KeyListener and catch events for console inputs, and I think (think) the answer is no. It would be kind of cool, but I think you'll have to settle for having to hit enter, validate the input, and then run your method based on the input. If you were allowed to use Swing, you'd be all set.
This post has been edited by alcdotcom: 17 Feb, 2007 - 10:19 PM
I looked over everything and most of it I already knew how to do. The scanner class was new.
What I am missing- and again maybe it is just too old school ---
When the program starts I would like a list of options to appear on the screen.
-- I can do that.
Then when a user presses the 1 key on the keyboard I would like to call a method.
--I can call the method I just need to know how to assign the number 1 on the keyboard so it works the same as clicking the mouse on a Button.
--I am going to try this with the scanner class by storing the info in a variable but I thought each key had a number that could be accessed and then I am assuming there is an api available to help work with it.
Ideas?
I am having my students do the tutorials today as they are well written and should reinforce alot of needed skills.
Thanks.
Codeninja
OK, now I see what you want. The only problem is that I don't know of any immediate solution. I can't say that I've ever tried to do something like this.
Here's my only thought as of now, create your own UI to replace the terminal/console, then add a key listener (or a key bind) to it. I'll try and throw something together for you as an example.
OK, now I see what you want. The only problem is that I don't know of any immediate solution. I can't say that I've ever tried to do something like this.
Here's my only thought as of now, create your own UI to replace the terminal/console, then add a key listener (or a key bind) to it. I'll try and throw something together for you as an example.
The Swing console emulation occurred to me, but he said that they get no credit for using Swing. Plus, it kinda seemed like overkill for their purposes. But it would be interesting to see your implementation. That's the cool thing about programming: everyone will have a different way of doing something.
I still feel like there should be some way to set up a KeyListener and get KeyEvents in a console because I've seen C apps that can do it. But I just don't know how at the moment. I'll do one more quick Google and see if I find anything.