I am kind of curious on how would you manage to replace a certain picture on a Grid of rows=4 and columns = 4. Let say if I had 4 images and one of them being blank, how would go on about choosing 1 random images and enabling it to be placed on any row[] and col[].
would i need to do a Boolean logic with double nested for loops?
This is just out of curiosity due to a question a saw here online, I tried attempting it and failed lol. Thanks for your time.
Related
I am working on a mahjong project.
My code contains a dynamic List<List<Tiles>> board.
The abstract class Tiles gets extended by the different kind of Tiles the game has.
Now im interesting on extending this small project with GUI componenets.
My thinking is to create the grid with a GridBagLayout cause my Array is dynamic sized.
A simmilar question has been asked in the past but i had hard time understanding anything from the answers and its a bit old also. old post
What i need is: when im creating an array of Jbuttons i want uponcreation of each button to place inside of them the info of each cell of the array.
Here is for example what my board array looks like: (one cell example)
specialvalue= 1x
coordinates = {0,0}
colour = blue
how i can hold this information in a Jbutton ?
And if its not possible , whats the best way to go from here?
Thanks in advance,
I can post some code of the project upon needed.
As i come back to my question i see that there was never an exact answer so here is how i did it at last and worked.
I used an abstract class for the Tiles , then i created a hashmap at my GUI class and i made key-value pairs with keys:jbuttons and values: all the info of Tiles i needed.
That was the main key to the solution.
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.
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
Hey I'm writing a quiz application for android. Some of the questions asked require just true or false, and some you need to pick from 4 possible options. I've implemented an intereface with 4 radiobuttons and got that to work fine.
I was just wondering what the best way would be to adjust the number of radiobuttons depending on the question type? I've added in an extra field in my question object to state the number of possible answer choices, but i'm unsure how to use this in my program. Any pointers would be appreciated!
At the moment i'm using a textswitcher to update the question asked when I click next and was wondering whether I could use an imageswitcher to make the desired change with the radiobuttons?
ADDITIONALLY - I was thinking about how I could update the labels on the radiobuttons to the possible choices instead of simply A, B, C etc. just to make it look nicer.
You can try these 2
http://developer.android.com/reference/android/view/View.html#setVisibility%28int%29
http://developer.android.com/reference/android/widget/TextView.html#setText%28java.lang.CharSequence%29
I need to make kind of a game in Java but I am a total beginner. It has to be applicable to the web and I need to use images on it and action listeners. So, do you recommend any site to know how to begin?
The description of the game (it is not really a game but it implements things that usually are in a game) is this:
Show a matrix of images of 3x3 elements, then, hide them and put instead empty squares. The images shown in the matrix, must remain in the lower part of the screen just below the empty squares and they must be randomly positioned. The user, must click one image and put it on the correct empty square. The result, must be, how many images were correctly positioned, the time it took to end the game, the time between mouse clicked and released for each image.
For additional information, I want you to know that this application is for a friend of mine who studies medicine. He wants this program to test patients who accident and receive hits on their heads. You may think that the description I gave you may not be a good software for that purpose, and in fact, it may be not, but, once I know the management of all that is required (Images, MouseListeners, how to introduce it to a web etc), I will be able to make a better product. So, please tell me, how can I begin?. What do I need to know?
I would start here. Except for some startup boilerplate and the restrictions of the sandbax (which, based on your description, you will b unlikely to encounter), there is no fundamental difference in an applet from normal code.