As a way of learning Java, I'm writing this little application for grade schoolers to practice basic math. The idea is that the kid does any number of math problems, as long as they are in the app, it just continues to throw problems at them until they click a 'Done' button. When they decide to be done, I want a new JFrame to come up that will show them all of the problems they attempted, along with their answer, and whether they got the problem right or wrong.
The advice that I am looking for is what is the best way for me present these results. I looked into the GridLayout and the GroupLayout, but I don't think that these are exactly right. I did something similar in VBA for Excel, and there I just ran a for loop with one iteration for every problem they attempted. Each iteration would add a row of labels to the frame with the elements of the problem displayed in the various labels. I tried this in Java, but I'm not even able to get the labels to even display.
So before I get all specific and start posting my code, I want to ask a bigger question, which is "what is the best method to create a view like this?" Often, I go off in one direction only to waste time before somebody suggests a totally different (and better) approach.
Thanks!
(edit: here's an image of how I did this in Excel. I'm trying to repeat basically the same thing in Java)
One simple way to make that design would be to use a mix of components. You could have a bunch of JLabels and JPanels stacked in a vertical FlowLayout. The grid you have described would be best designed in a JTable, something like the below:
If you like tables like Excel then, Java provides JTable class to create tables, if you want.
Tutorial : http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
Related
What I have in mind is to make a JTable. The model will use the 2D array's columncount and rowcount to set the JTable's rows and columns.
What I cant figure out is how do I go around making fields for these cells in the table?
Example fields like - Status(boolean), Image etc. So by having these fields I want to edit the cells when the application is running and show the user the updates.
I have tried to make a 2D object and add fields in there. But it doesnt seem to work.
What would be a good way to build this?
I am using swing to build this.
This isn't a very specific question so that limits the answer I can give - from what you want to do, I'd suggest
Making sure you understand how the Model-View-Controller paradigm works in Swing
Looking into the Observer / Observable framework and how it fits in with MVC
Extending some sort of Swing Component to reflect changes in your model.
Once you've covered the above you should find that implementing what you want to do is reasonably trivial, and that you can ask more directed questions that will get better responses.
I made an array list of strings and assigned an image to each string. Then, I randomized these images. I want to now make a method that swaps one button to the button adjacent to it, but I have no idea how to do this. Any suggestions about how to go about it? Thanks
First suggestion: Don't. Don't swap JButtons as you're making things much harder than they need to be. Instead if possible swap images or more specifically ImageIcons, and this can be easily done using the JButton method, setIcon(...).
It almost sounds as if you're trying to create a memory game, and if so there are plenty of examples of just this sort of thing to be found on this site, at least one created by me.
As always in these sorts of things, first concentrate on the program's model, that is, its logical underpinnings, and only after getting that working, apply it to the program's view or its GUI representation of the model's state.
I'm trying to work out how best to approach creating a program in java where I have a very simple GUI where a user can drop in multiple images and multiple text boxes move these around by dragging, resize, maybe a couple of other very simple features and then output a jpg for instance.
I have been looking around and all the program's I can find seem to be much more complex.
I have been trying to do this using java swing just creating a GUI that when you press a JButton inserts a picture into a JLabel, but I'm thinking this kind of thing must be the wrong approach and there must be a better way.
Any ideas and suggestions would be much appreciated...
Please bear with me as I've just started using NetBeans for the first time! Basically what I'm trying to do is create different panels that fit inside one frame, except that only one panel will be visible at a time. It'll start with one panel, and depending on what the user inputs, the panel that corresponds to what the user puts in pops up.
I've tried looking into utilizing LayeredPanes since that's what I've come after hours of researching this only.. I don't understand how to do it! I think using different panels would be much easier than using different frames, so that's why I'm just going to stick with layering panels.
If anyone could explain LayeredPanes, I'd be very grateful! I'm not sure my coding will help here, but if anyone needs it I'll put it up.
This tutorial should point you in the right direction, however, if you want to have items positioned over each other, you might also want to take a look at the CardLayout:
The CardLayout class manages two or more components (usually JPanel
instances) that share the same display space.
Reading your question I dont think that what you need is a LayeredPane,
Basically what I'm trying to do is create different panels that fit inside one frame, except that only one panel will be visible at a time.
Tell exactly what you want to achieve, I mean on what you are working on.
...and depending on what the user inputs, the panel that corresponds to what the user puts in pops up.
I'd like to suggest a JDialog , show dialogs depending on the user inputs. To make sure if this is what you need, you want to provide us with more information. :)
I would like to create a quiz for my Java GUI.
I'd like it to display a question on one page, then have a next button which takes the user to another page telling them if that question was correct or not, and if it is correct they can move on to the next question (by clicking another next button) and if they got it wrong, have to go back and answer it again. However I have no clue how to do this!!
So far I have a simple GUI with a welcome page and tabs down the side, one of which includes a quiz. Would it be a better idea to create the quiz in Flash or something and then embed it into my Java application? Or just do the whole thing in Java? I'm really new to java so I'm not at all sure what to do, any help would be greatly appreciated!
Thanks
It would be best to use just Java. Consider using CardLayout with your GUI to allow swapping questions, or else you can create and modify key components on the fly such as the text displayed by JLabels and JRadioButtons.
Key though before considering any GUI structures is to first create solid OOPS based non GUI classes to handle your questions. For instance, you may want classes for:
Question class that holds a question String, a List of possible answer Strings, a correct answer String. This class can randomly order the incorrect and correct answers, can have a method for checking if the answer selected is correct.
A Test class that holds a collection of questions, that can present questions in random order, that can hold the score obtained.
A QuestionReaderWriter class that can read and write questions to a text file (you definitely do not want to hard-code the question text).
For this type of app it would be best to use the language you are more familiar with.
Since this is just a simple display this then do that there really is nothing very difficult about it.
Personal, I would lean towards Flash as the flash IDE is drag and drop and an experienced flash guru could make this in a few hours. Flash IDE is geared towards this.