How to Use Text Fields
2) then invoke frame.setVisible(...)
I have no clue how to put this.
What part of my answer was confusing?
I gave you the order in which your code needs to be executed.
Did you do what I suggested???
try setting the JPanel visible
There is no need to do that, a panel is visible by default. Did you read my suggestion???
becouse if so, I still get the same thing, a blank window.
then why post code you're just typing into the browser:
if you really want help, and not just trying to have a bit of fun,
post the code that is not working
best help is obtained by posting exact code (ctrl-c --> ctrl-v), not pseudo-code.
if you can add/show (e.g.) a JTextField in the frame, then adding/showing your own panel is (almost) exactly the same.
java needs to know where the .class file is.
In the case of the textfield, 'import javax.swing.JTextField;' or 'import javax.swing.*;' tells java where it is.
java looks in the current directory/folder as well, so here's a very simple example of classes in the same directory
create a .java file and call it MyPanel.java
copy this code into that file, save/compile, if OK close the file
now create another .java file, call it MyFrame.java (must be in the same directory/folder as MyPanel.java)
copy this code into that file, save/compile, now run this one (it has a main());
probably your next step is to look into 'Packages', where you might have numerous class files.
Adam Burda wrote:I am running windows 7 64bit Home Premium with an intel core i3 and 4GB of ram. I run my java code in eather prompt or i use JCreator LE. Every time i wright an app I get a blank frame or a blank panel. But only when I put in a JTextArea or a JTextField. Buttons, CheckBoxes, and Raido Buttons all show fine. But when i add a textfield the program compiles fine then i run it. The window pop's up, but nothing on it. Unless i grab one of the sides to adjust the size of the window myself, bigger or smaller. Then the window displays the buttons, textfield...... I have tryed resizing, and using other layouts. I have no clue what the bug is. This happens with any and all code I wright.
It is a problem that most of us face
You should read the Java API.
You can also use validate() and repaint() method
But I have seen such problems with Applets
take this Sample code where i got such problems
Sorry for such a big code but this is actually where I faced the problem for JCombobox an d JButtons to appear try it and there are many bugs and it is not a full fledged Calculator
But should help you understand
Please Quote if any mistakes as I have Edited it
Digen Mahara wrote:It is a problem that all of us face.
Try to use the getContentPane() mathod this should help you <google it> you will get something that may help you
Absolutely meaningless advice, that also suggests you are not familiar with the API.
How is getContentPane() supposed to help here? Why should it be necessary to search the net and not read the API?