• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about GUI display~~

 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yesterday, I made a basic GUI using JBuilder 7.
When I make the GUI java file, there was no warnings and errors. But when I want to run this file, all things are all right except the displaying of the GUI. The GUI didn't display at all! I trying to change JDK and setup runtime configuration and select the mian() of that GUI file. But nothing changed.
Plus, when I compile the file in the console, no problem also. But when I intend to run the class file, the GUI is still no be displayed? What's wrong? I con't understand!
Pls Guide me. Thank u in advance.

Regards,
George
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi George,
If it is a basic GUI, then perhaps you could post the code here and we can see what is wrong. Offhand I would guess that you are not setting visible to true. But it is hard to tell with so little to go by.
I am a little bit worried about your statement that you used JBuilder to create the GUI. Does this mean that you used the wizards within JBuilder, or JBuilder's drag and drop "Design" mode? If either answer is yes, then you need to be aware that JBuilder sometimes creates dependencies on Borland class files (which you cannot use in your submission), and JBuilder wizards and the design mode frequently writes code that does not conform to the Sun coding standards (despite the options that they give you to try and get that conformance). Feel free to use the IDE, but be very careful that what you submit is your own work.
Regards, Andrew
 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
Ya. I use the drag and grop tools to disign. Beacause I think control the Layout is a little bit unworthy. If the IDE has a better tool, why not use it? SUN said you can use IDE but the final assignment must be run correctly in the production of JAVA tech.(not Development).
Ya, JB will add some methods such as jbInit() in the GUI class. But If I state that I was using JBuilder 7 and JDK 1.4 to do the project, I think it will be OK. Is that right?

Regards,
George
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi George
Do you have the statement in your instructions:
You are permitted to use any IDE tool you choose, but you must not submit any code that is not your own work. The final program must have no dependencies on any libraries other than those of the Java 2 Platform.

As I said before: you do have to be careful with JBuilder that you do not end up with a dependancy on Borland class files (libraries). In a past job I spent considerable time removing those dependancies from an application I inherited. It can catch you when you dont expect it and cause you considerabal grief later.
I guess whether you can use the drag and drop tools depends on how strictly you take that requirement that all code you submit must be your own work. I can understand your argument, and I think it might be accepted but I am not comfortable with it myself.
Anyway, are you able to post the code?
Regards, Andrew
 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not exactly. Mine is said as below:
Throughout this exercise,you must use exclusively the Java 2 platform. You are not required to develop your code using any particular implementation of the Java 2 platform, but the submission that you return must have been tested and shown to work under a production(not development)version of Sun Microsystems' Java 2 platform.

I think that means if mine code can run in other computers which are only use JDK, not any IDEs, is that right?
And here is my code:

It is just a basic GUI and don't have any functionalities implemented.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi George,
First up, a change to get something displaying on the screen. Try replacing your main method with:

Now, to get picky:
The problem here is that you are putting your items into a JComponent. Nothing wrong with that, but the JComponent needs to go into something for it to be displayable. I chose a JFrame for this example.
This brings me to another issue with IDEs: as a tool to help you do what you would normally do faster, they can be good. But unless you can do the work yourself without the IDE, then you can get yourself lost as the IDE will assume you know what you are doing. So JBuilder was quite happy for you to add everything to the JComponent, because it assumed you wanted to do this. Even though the end result was not what you really wanted.
And yet another issue with using IDEs. Look at the generated code. Variable names such as jPanel1 and jPanel2. Now when you are working in the designer, you can change these variable names, but I think that it is faster to write the code manually than to go through the multiple mouse movements and clicks in order to do this. Also look at where the text for jMenuItem1 is set: JBuilder has set it twice! And why set it this way, when it could be set in the constructor? To me, this is just ugly code. You can easily fix it, but by the time you have done so, you might as well have done it all manually.
Sorry, I am a grumpy old man tonight. Going to bed now. Should be friendlier tomorrow, and I wont pick on JBuilder as much. Maybe
Regards, Andrew
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, but I'll pick on JBuilder. Placing it into a JComponent isn't the way I would do it and I think most of us here wouldn't do it that way either. The variable naming is also a way that we wouldn't have coded our GUIs. This is what an IDE brings, their own flavor, that doesn't match how we would have done things.
You can get yourself into trouble. Especially if you try and use JBuilder to connect your Actions/Events, this is where proprietary code will really start to show up.
If you use the SCJD as a learning tool, you will find that writing the GUI code on your own without an IDE is the best way to learn.
Good Luck.
Mark
 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya. Thank u cery much,Andrew and Mark.
Not a long time after I posted my code, did I realize what is wrong. I think I should make the class inherited from JFrame not JComponent.
Mark, I think u are right, doing without IDE will be better for my learning. And I'll do as you adviced. Thank u.

Regards,
George
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic