From post#92, re-ordered:
1)image created
2) new image added to a panel
3) button added to panel
4)panel with the image and the button added to the panel with the gridlayout
5)filled panel added to the frame
6)GUI packed and shown
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
From post#92, re-ordered:
1)image created
2) new image added to a panel
3) button added to panel
4)panel with the image and the button added to the panel with the gridlayout
5)filled panel added to the frame
6)GUI packed and shown
If you don't understand my answer, don't ignore it, ask a question.
It looks like steps 5 and 6 (from post#106) are not done last. They are done before steps 2, 3 & 4
For learning how to create a GUI make a test program as done in post #51. When that works, change it by using post#70.
If you don't understand my answer, don't ignore it, ask a question.
I wish rather than you telln m to make a test program just explain where im going wrong to help e understand, as you can see i have been tryn extremely hard to try and sort this.
i really do appreciate your help honestly but now im just really frustrated and cus its been a good few days and im just going round in circles, i need to show my tutor and i wont have it complete
The order of the steps is important.
Try the steps in the order I recommended and see what happens then.
If you don't understand my answer, don't ignore it, ask a question.
ive ammended it so its it is in right order now jsut not printing out the the way i want it to, there i somthing im doing wrong but i dont knw what.
Last edited by stresstedout; March 4th, 2014 at 01:57 AM.
Now what about step 4?
That has nothing to do with creating the GUI.is this in the wrong place?
If you don't understand my answer, don't ignore it, ask a question.
is this not step 4 ????
JPanel cellPanel = new JPanel(new BorderLayout());
cellPanel.add(gridPanel);
4)panel with the image and the button added to the panel with the gridlayout
No. That code does the opposite: adds gridpanel to the cellpanel (which should contain the image and button) Look at post#70
If you don't understand my answer, don't ignore it, ask a question.
i have added it there because if i put these anywhere else they give me errors.
when i put this at the top i get errors espeically that "icon" so im not sure on what to do here.
Last edited by stresstedout; March 4th, 2014 at 01:58 AM.
4)panel with the image and the button added to the panel with the gridlayout
That says to create a panel, add the two things to it and add that panel to the gridpanel. See post#70
That's it for me tonight. I'll be back tomorrow.
If you don't understand my answer, don't ignore it, ask a question.
please can u tell me where to put the code i need to show my tutor pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee before u go
For the very last time ....
import java.awt.*; import java.net.*; import javax.swing.*; public class ButtonAndImageGrid { private static String[] isbnCodes = { "0636920026518", "0636920030713", "9781782170303", "0636920028499", "0636920028925", "9781849699617" }; public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame frame = new JFrame("Button And Image Grid"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JPanel gridPanel = new JPanel(new GridLayout(0, 4, 10, 10)); for (int i = 0; i < isbnCodes.length; i++) { URL imgUrl; try { imgUrl = new URL("http://akamaicovers.oreilly.com/images/" + isbnCodes[i] + "/cat.gif"); } catch (MalformedURLException e) { System.out.println(e); continue; } ImageIcon icon = new ImageIcon(imgUrl); JButton cellButton = new JButton(isbnCodes[i]); JLabel cellLabel = new JLabel(icon); JPanel cellPanel = new JPanel(new BorderLayout()); cellPanel.add(cellButton, BorderLayout.NORTH); cellPanel.add(cellLabel, BorderLayout.CENTER); gridPanel.add(cellPanel); } frame.getContentPane().add(gridPanel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } }); } }
Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)
Useful links for Java beginners – My new project Java Examples on Google Code
[QUOTE=andbin;138842]For the very last time ....
after all this and the stress i dont think i need it need. im making a learing application.. how will my users learn from this memory is what my tutor asked me?
Last edited by stresstedout; March 4th, 2014 at 01:58 AM.
I'm not sure I understand what you are asking. Is it a question about the code or what?
If you don't understand my answer, don't ignore it, ask a question.
Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)
Useful links for Java beginners – My new project Java Examples on Google Code
I am making a project for children in school, the project is a LEARNING PROJECT.
I thought id make a memory game but when i showed my tutor he asked me what are they learning from this. so i have wasted my time trying to make this game.
I spent quite a long time trying to make this memory game so i dont want it to go to waste,
i like the fact i have used images from database which will get me extra marks but what do i do with those images now.
Can anyone suggest anything i could to do?? we have images on a jframe. how can i use images (images can either be to do with numeracy or words) to make a simple learning application or game?
Please help me with some easy ideas, as i do not have much time.
stresstedout, listen please. This thread has arrived at post #123 (with my current answer) and we have spoken about a lot of things. Still now I don't know if you have well understood the concepts and examples I have posted. And you not even have answered positively or negatively about this ..... I suppose of no .....
And now you say, if I understand correctly, that you don't know what you want to/can do??
I wasted my time in trying to repeat things many times and posting different examples and I was a bit frustrated by this. Sorry but this is not a good incentive (at least for me) to continue on this thread/topic and I also think this is not the right way to use the forum .....
Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)
Useful links for Java beginners – My new project Java Examples on Google Code
Andbin, I thought of making a memory and thats what i have been doing with help of youself and norm, i am really appreciate that you took time out to help me. I have un
Last edited by stresstedout; March 4th, 2014 at 01:58 AM.
So you want an idea for a game? There are lot of games that are made with a "grid" of images: Tic-tac-toe, Chess, Reversi, Peg solitaire, Sudoku, Scrabble. Just to name a few.
In these games the difficulty, at programming level, is not the display of images! The real difficulty is about all the "logic" that is behind the game. This logic can be very complex, you need not just some tens of lines of code but hundreds of lines.
And if for a game you want to develop some sort of "artificial intelligence" for a computer player, the complexity raises by 40, 50 times so that you need thousands and thousands of lines of code.
And If you don't write this code using all the good OOP principles, design patterns, valid data structures, etc.. you will end up to a code that is only absurd, incomprehensible, clunky and so on ...
I can understand .... and remember (for the future), that I like to help but I like people who have good will and want to read, study, try and experiment in order to understand.
Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)
Useful links for Java beginners – My new project Java Examples on Google Code
Thank you andbin