Computer Science Canada JPanel hurts my brain |
Author: | Tallguy [ Thu Oct 04, 2012 5:02 pm ] | ||||
Post subject: | JPanel hurts my brain | ||||
Greetings All!!! I am once again back into java Here is my dilemma i am using the GUI's in JPanel (ONLY) to create a GUI for a calculator. I just can not for the life of me get it to appear on my screen, the array holds the String values to be used in GridLayout. i am only able to BorderLayout || FlowLayout || GridLayout. I can do this in about 10 min using JFrame, but we are not allowed to touch it. Here is the code that matters Any help would be awesome
MY MAIN
|
Author: | Insectoid [ Thu Oct 04, 2012 6:09 pm ] |
Post subject: | RE:JPanel hurts my brain |
I've never been able to get any of Java's gui elements to do what I want. If you were me you'd give up now, but you're Tallguy, not me, so don't give up. Then again, I am six & a half feet tall, so maybe you are me. |
Author: | Tony [ Thu Oct 04, 2012 7:49 pm ] | ||
Post subject: | Re: JPanel hurts my brain | ||
Doesn't answer your question, but... are you using Java 5+ ? for-each loops are your friend Tallguy @ Thu Oct 04, 2012 5:02 pm wrote: String [] values = { "7", "8", "9","/", "P","4","5","6","*","\u221A","1","2","3","-","C","0",".","+/-","+","="}; for (int i=0; i<values.length ; i++){ buttons.add(new Button(values[i])); System.out.print (values[i]); } vs.
|
Author: | DemonWasp [ Thu Oct 04, 2012 8:08 pm ] |
Post subject: | RE:JPanel hurts my brain |
JPanels represent "panel" components, not "frame" components: that is, they don't represent windows on their own. You need to add them to a JFrame (or other container) which is being drawn to have the panel be drawn. See: http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html Edit: You could use another top-level container, such as JDialog or JApplet. |
Author: | TokenHerbz [ Thu Oct 04, 2012 9:46 pm ] |
Post subject: | RE:JPanel hurts my brain |
yeah JApplet would, but i find with that the complier (i suppose depending which you use) wont detect bugs that are found compiling to JFrame.. so i would use JFrame and then change it to JApplet. |
Author: | DemonWasp [ Thu Oct 04, 2012 10:16 pm ] |
Post subject: | RE:JPanel hurts my brain |
I'm not sure what you mean by that sentence. If your compiler isn't finding compile-time problems, then it's not compliant with the Java Language Specification, which means it is not a Java compiler. Which compiler were you having trouble with (and give an example of the code in question)? |
Author: | Tallguy [ Thu Oct 11, 2012 9:29 am ] | ||||
Post subject: | Re: JPanel hurts my brain | ||||
Thank you all - I have got it to work. Note that this assignment is just the GUI aspect, once i get the application working I'll post in submissions. Here is the fix, my main was able to use JFrame, just none of the contents Main
CalculatorView
@Tony - You are awesome good sir, I always forget about the for-each loops Tony wrote: Doesn't answer your question, but... are you using Java 5+ ? for-each loops are your friend Insectoid wrote: I've never been able to get any of Java's gui elements to do what I want. If you were me you'd give up now, but you're Tallguy, not me, so don't give up. Then again, I am six & a half feet tall, so maybe you are me. -only 6'4" EDIT-Added syntax |
Author: | QuantumPhysics [ Mon Oct 15, 2012 9:55 pm ] |
Post subject: | RE:JPanel hurts my brain |
Its not JPanel, its just java overall. Why not use a Applet or Jython wx package. |
Author: | Tallguy [ Wed Oct 17, 2012 10:32 am ] |
Post subject: | RE:JPanel hurts my brain |
assignment specifications |
Author: | QuantumPhysics [ Fri Oct 19, 2012 12:11 am ] |
Post subject: | RE:JPanel hurts my brain |
Oh. Fair Enough. |