This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

textField in a Web App  RSS feed

 
John Waclawski
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay...JavaRanch came with high recommendations for being a great place to find answers regardless of how small they are. The more I read here the more I like what I see.
Anyways, my question....it's so simple I'm almost ashamed to ask it but I'm at a loss.
I have a textField I added and a button. For my self-training all I want to do at this point is type in a value into this textField, press the button & have a showMessageDialog box pop up with the value. Simple, huh? If it's of any help, I used Netbeans 5.5.1 to do this.
I've tried:
textField.getValueAsString();
textField.toString();
Neither worked.

I come from the VB6 side of things & worked with .Net some. I want to learn JAVA cuz it's not MS.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's actually not simple.

I don't think the VB approach to learning to program Java web applications will work. A better approach would be to find some simple command line tutorials to get your feet wet.

See:
http://www.coderanch.com/t/364753/Servlets/java/Head-First-Servlets-JSP
 
John Waclawski
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
It's actually not simple.

I don't think the VB approach to learning to program Java web applications will work. A better approach would be to find some simple command line tutorials to get your feet wet.

See:
http://www.coderanch.com/t/364753/Servlets/java/Head-First-Servlets-JSP


I've been plucking away at command line stuff for about 2-3 weeks now. Got my hands, head, feet wet with that. Find myself almost frustrated with all this command line stuff because it's not accomplishing what I really want to dive into.
I checked that link out & I guess I'm at a loss as to what that has to do with what I'm working with. I'm still reading thru it though.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your code in a servlet? In JavaScript? You're not giving us a whole lot of context to go on.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Is your code in a servlet? In JavaScript? You're not giving us a whole lot of context to go on.


VB6 made it incredibly easy to build Windows desktop applications.
Visual Studio .NET takes the same approach to building web applications.

With it, you.
Drag and drop widgets onto the screen,
Double click one of the buttons that you just placed on the screen in the last step and are brought into the 'code behind' method that is supposed to act on that button click event.
From there you can set the properties of any of the other widgets (myTextField.text = "Hello, World").
Then click the run button and visual studio will build the entire web application for you ASP, C#, HTML, and Javascript, then fire up a browser with the application running in it.

To get started in that environment, you don't need to know whether you're talking about javascript, HTML, C# etc... The IDE does it all for you.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Waclawski:
I checked that link out & I guess I'm at a loss as to what that has to do with what I'm working with. I'm still reading thru it though.


In it, I elaborated on why I think it's better to start out learning to write, compile, and run basic Java command line applications before tacking Servlet programming. The original poster's frustration was a perfect case for my point.
 
John Waclawski
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:


VB6 made it incredibly easy to build Windows desktop applications.
Visual Studio .NET takes the same approach to building web applications.

With it, you.
Drag and drop widgets onto the screen,
Double click one of the buttons that you just placed on the screen in the last step and are brought into the 'code behind' method that is supposed to act on that button click event.
From there you can set the properties of any of the other widgets (myTextField.text = "Hello, World").
Then click the run button and visual studio will build the entire web application for you ASP, C#, HTML, and Javascript, then fire up a browser with the application running in it.

To get started in that environment, you don't need to know whether you're talking about javascript, HTML, C# etc... The IDE does it all for you.


What he said.

I'm using Netbeans as my original posting stated. That's allowing me to write it, as default in JAVA. I do apologize if I didn't provide enough information. I will regress. This information is mostly for Bear Bibeault:

1. I'm using Netbeans 5.5.1
2. I have the Visual Web plugin module installed.
3. I created a new web application.
4. I dragged(drug) a textfield widget & a button widget to the screen.
a. For testing purposes of the button here is my code:
public String button1_action() {
String s;
s = "Test!";
JOptionPane.showMessageDialog(null,s);
return null;
}

b. I did set import javax.swing.*;
5. I press the button and a message dialog box comes up with "Test!" on it. So I know my button works.
6. I want to type in a value into the textField box I dropped on there. This is in JAVA per the default that NetBeans 5.5.1 uses. How do I get the message dialog box to display what I typed in?

Ben...I'm going to thoroughly read what you have posted. Thanks, Ben, for your information. At least it was a step in the right direction for me.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing doesn't work in a JEE web app.
Swing objects are meant to be run on the desktop or in an applet.
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Waclawski:
Okay...JavaRanch came with high recommendations for being a great place to find answers regardless of how small they are. The more I read here the more I like what I see.
Anyways, my question....it's so simple I'm almost ashamed to ask it but I'm at a loss.
I have a textField I added and a button. For my self-training all I want to do at this point is type in a value into this textField, press the button & have a showMessageDialog box pop up with the value. Simple, huh? If it's of any help, I used Netbeans 5.5.1 to do this.
I've tried:
textField.getValueAsString();
textField.toString();
Neither worked.

I come from the VB6 side of things & worked with .Net some. I want to learn JAVA cuz it's not MS.


If you are talking about a JTextField, I believe you get the data from it with the getText() method (defined in its superclass JTextComponent).
[ August 13, 2007: Message edited by: Red Smith ]
 
John Waclawski
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Red Smith:


If you are talking about a JTextField, I believe you get the data from it with the getText() method (defined in its superclass JTextComponent).

[ August 13, 2007: Message edited by: Red Smith ]


Tried that. The .getText() is an object not a string. At least according to Netbeans it is.

UPDATE!! Figured it out by following a video on Sun' web page on how to write a web app while implementing a WSDL.

I was partially right to begin with (as was Red Smith).

It's textField1.getText() but you add .toString(); at the end so it reads: textField1.getText().toString();

Thanks to all those that actually helped me with something constructive. Much appreciated!

Thanks again.
[ August 13, 2007: Message edited by: John Waclawski ]
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Waclawski:


Tried that. The .getText() is an object not a string. At least according to Netbeans it is.


What Class does getText() return? Or are you saying the method itself is an object???
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It's textField1.getText() but you add .toString(); at the end so it reads: textField1.getText().toString();


Glad you got it working, but just out of curiosity - what type of Class is your textField1?
 
John Waclawski
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Red Smith:


Glad you got it working, but just out of curiosity - what type of Class is your textField1?


Well now...that's a good question. And frankly I'm embarrassed I don't know the answer. I want to say it's an object. But looking at Netbeans they just call it a TextField.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!