aspose file tools
The moose likes Beginning Java and the fly likes textField in a Web App Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "textField in a Web App" Watch "textField in a Web App" New topic
Author

textField in a Web App

John Waclawski
Greenhorn

Joined: Aug 13, 2007
Posts: 10
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

Joined: Dec 11, 2004
Posts: 13410

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


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
John Waclawski
Greenhorn

Joined: Aug 13, 2007
Posts: 10
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

Joined: Jan 10, 2002
Posts: 56175
    
  13

Is your code in a servlet? In JavaScript? You're not giving us a whole lot of context to go on.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Aug 13, 2007
Posts: 10
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Aug 05, 2007
Posts: 105
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

Joined: Aug 13, 2007
Posts: 10
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

Joined: Aug 05, 2007
Posts: 105
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

Joined: Aug 05, 2007
Posts: 105

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

Joined: Aug 13, 2007
Posts: 10
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: textField in a Web App
 
Similar Threads
Populate the 'current' JTextField via a button/label
HTML to Applet
How to change the tab order for jumping from one textfield to another
Issue with Vaanilla Struts 2/Hibernate CRUD example
Populate the 'current' JTextField via a button/label