Java experts, please help with simple problem!!

pillage2001

Lifer
Sep 18, 2000
14,038
1
81
I need to create a frame which has a button and at least two textfield. It's really simple but I can't seem to do it. I'm used to doing java application but do not know how to use GUI. :( Anybody knows how to build one real quick or show me how to do it?? How I wish this is VB. :(
 

pillage2001

Lifer
Sep 18, 2000
14,038
1
81


<< look at swing or AWT.

awt is quick and dirty, swing is a ltlle more legant
>>


I'm currently looking at AWT cause it's simple and fast. I don't need anything fancy. My lecturer requires me to build a simple email program where I just need to send to a email address and some short message.

Any idea?
 

manly

Lifer
Jan 25, 2000
13,286
4,060
136
Programmatically, Swing and AWT aren't that different. I haven't done Java GUI programming in a while, but the APIs are pretty convenient to use. The actual problems are in the runtime performance, not in the APIs themselves.

Anyhow, you should check the Swing track in The Java Tutorial. And yeah, you can use the JavaMail library instead of implementing your own email package.
 

pillage2001

Lifer
Sep 18, 2000
14,038
1
81
Thanks manly. I've found a couple of examples and trying to build the frame now.

Last question, are textfields the same as string??

Can I do this:

String str;
JTextField text1 = new JTextArea ( yada yada)

Then I read from the text field like this.......

str = text1; <-----is this valid??
 

manly

Lifer
Jan 25, 2000
13,286
4,060
136
Well, consider OOP fundamentals.

The only way a JTextField could be a String is if it extended String. And if you consult the JavaDocs you'll see that it does not.

The quick answer to your question is:

String str = myTextField.getText();

Basically, you have to learn the APIs to write programs. How much you need to learn to accomplish the task at hand really is up to you. For a simple assignment, you might get away with a lot of cut & paste from various sources, and little more than changing some variable names. That's how most programmers operate anyway; find out how to do something through Google or whatever.