Can you fix the formatting of the code? The indentations are not right. There are missing }s
The posted code is a mess. There are a lot of definitions missing.
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.
Can you fix the formatting of the code? The indentations are not right. There are missing }s
The posted code is a mess. There are a lot of definitions missing.
If you don't understand my answer, don't ignore it, ask a question.
WITHOUT THE LINE OF CODE frame.pack(); it gives me what i want but the frame has no size at all, so i have to make the screen bigger completely to see anything on the frame.
without the code frame.pack(); it presents the data as shown on the image.
how do i give this frame a size without using frame.pack(); code although this line of code is using for size or frame. Attachment 2690
Can you edit the code and format it properly?
Nested statements should be indented
}s should NOT be hidden at the end of statements. Put them on their own line.
No, the compiler will accept the whole program on one line.There is no errors in the code so doesnt that mean that the indentation are correct?
If you don't understand my answer, don't ignore it, ask a question.
is this better
Last edited by stresstedout; March 4th, 2014 at 01:56 AM.
No.Too many nested statements start in the first column making it hard to read and understand the logic in the code.
The }s should not be one above the other (in the same column)
See post#51 for an example of proper formatting.
If you don't understand my answer, don't ignore it, ask a question.
Its a little better, but there are still too many statements starting in the first column.
And there are too many statements that are indented that should NOT be indented:Those two statements should start in the same column.ImageIcon icon = new ImageIcon(img); JPanel gridPanel = new JPanel(new GridLayout(6, 0, 6, 6));
Here is a hidden } that makes the code hard to read and understandAt the end there is }}. }s should be on their own line and NOT in the same columnframe.setVisible(true);}
If you don't understand my answer, don't ignore it, ask a question.
i have edited it and hope i have understood and corrected what you asked for
Last edited by stresstedout; March 4th, 2014 at 01:57 AM.
One problem I see inside the while loop is there are method calls being made that should only be made one time, not every time an image is created:
setVisible() - only needs to be done ONE time after the GUI has been built
adding to frame at BorderLayout.NORTH - only ONE component will be there, all the other add()s are useless
pack() - only once after everything has been added
If you don't understand my answer, don't ignore it, ask a question.
PLEASEEE can you tell me more about the methods?
The methods should be called when they are needed to do something.
1)When does the GUI need to be packed and shown?
2)When does a filled panel need to be added to the frame?
3)When should the image be created from the bytes just read from the database?
4)When should the new image be added to a panel with a button?
5)When should the panel with the image and the button be added to the panel with the gridlayout?
If you don't understand my answer, don't ignore it, ask a question.
where do i put them gui being packed and the panel added to the frame? im confused
Take the questions one at a time and decide when they should be executed. Make a list of pseudo code statements to show when each should be executed.
This project may be too advanced for your current knowledge. Maybe you should start with something simpler.
Look at the tutorial about how to build a GUI: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
If you don't understand my answer, don't ignore it, ask a question.
IS THIS WHAT YOU MEAN?
Last edited by stresstedout; March 4th, 2014 at 01:57 AM.
No, that does not look like a list of steps in pseudo code.
The code is missing several steps.
What does the for loop that loops 2 times do? Why is it there?
Are there supposed to be buttons with the images?
I don't see them in the posted code. I thought that showing them with the images was a BIG problem.
If you don't understand my answer, don't ignore it, ask a question.
there are buttons which go on the images to hide them... so when the use clicks the button they see the image under it..
i need to add the buttons now, the only problem i have with them is that i cannot get them to go on the images, this is where i am struggling.
any tips?
do i add them in the while loop?
also the for loop was a mistake it onli loops once
What is a loop that loops once?
See post#70.problem i have with them is that i cannot get them to go on the images
Put them in a panel and add that panel to the panel with the gridlayout. See steps 4 & 5 in post#92
If you don't understand my answer, don't ignore it, ask a question.
i have spent a whole 2 days tryna figure this out but all i get is errors, and now i have gone back to the orignal code.
please can you help.. anything at all?
i have to show my tutor tomorrow and i feel really upset that i cant do this.
A suggestion to learn how to make a GUI with image over button:
Take the code from andbin's post#51 and modify it to build panels with images over buttons using the technique shown in post#70.
The results could look like this:
ImageOverButton.png
When that works, you should be able to apply the techniques to the program you are trying to build.
If you don't understand my answer, don't ignore it, ask a question.
I have looked through the program written by adbin and i have come up with this, but i still cannot understand of where to put the button becuse at the moment it just comes beside it. so i have left it out the code. please help
Last edited by stresstedout; March 4th, 2014 at 01:57 AM.
look at post#70 for how to put the image above the button. There isn't any Database used in the code from post#51. Using a DB just makes it harder for this testing. Use a single image that is read from a file.it just comes beside it
What is the reason for this code:for (int i = 0; i < 1; i++)
If you don't understand my answer, don't ignore it, ask a question.
that line of code is for how many times it prints the images in the columns or rows.
You do NOT need a for statement that only loops one time.
If you don't understand my answer, don't ignore it, ask a question.
i have seen post 70 but im not sure on where to put it, where ever i put it goes beside it. please could give me a hint.. im really stuck or i wouldnt ask.