Hello there,
I'd like to quickly start off by saying after contemplating what section to post this in this one seemed more appropriate then any of the other sections, though I have a gut feeling I'm still wrong.
I'm fairly week at OO programming, no particular reason aside from I'm much more used to C which is more procedural.
My problem at the moment is (and forgive my terms they're probably going to be wrong) I have two graphic classes 'startMenu' and 'Camera', which are part of a game I'm getting to grips with. I want to make it so that 'startMenu' will "go away" after the user hits enter, which I've currently implemented very poorly with a scan statement. From running this code with the other classes I find that nothing comes up (no window) until I hit enter. In this case it seems to skip (although is probably appearing for a nano second) everything in 'startMenu' and just goes to 'Camera'.
Because I'm so used to procedural I'm just so baffled by the fact it's not similar to C in the sense that a scanf statement will "Stop" everything and wait for input; where as here it waits for input then starts.
How do I make it so that 'startMenu' will show in the window and after the key enter is pressed it will show 'Camera'? (If that question makes any sense).
I also have some additional questions:
- How do I "take away" a class from the JFrame? I'm '.add' ing stuff to it is there a similar command to remove it from the frame entirely instead of just being in the background.
- How do I layer graphics in the JFrame? I've heard and looked at panels, content and just '.add' ing it to the window in the right order. What would be the best option for a game?
- How can I make an Image a button? I've looked around but all tutorials regarding this are just "Put image on button", I want the image to act as a button.
Thank you for your time, I hope I haven't wasted it.
class Thing { public Thing() { JFrame mainwindow = new JFrame("Dooby"); mainwindow.add(new startMenu()); Scanner scan = new Scanner(System.in); String startit = scan.nextLine(); mainwindow.add(new Camera()); mainwindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainwindow.setSize(800, 600); mainwindow.setVisible(true); mainwindow.setLocationRelativeTo(null); } public static void main (String[] args) { new Thing(); } }