Sie sind auf Seite 1von 3

WireFusion

Welcome to the Demicron Online Forums. If you are new to the forums community, read the
FAQ to get started.

FAQ Search Memberlist Usergroups Register


Profile Log in to check your private messages Log in

Pass URL

WireFusion Forum Index -> Java in WireFusion

View previous topic :: View next topic

Author Message

DaK888 Posted: Sat Jan 27, 2007 3:43 pm Post subject: Pass URL

A couple of newbie java questions.


Joined: 04 Dec 2004
Posts: 45
Trying to build a form that a user can enter information into that will help build a URL.

I've been playing around with the java.awt texbox solution and I'm now a bit stuck.

1. Using the example in the java.awt pdf from Demicron, I can get text entered into the text boxes
to build what looks like a correct URL (as the text is displayed in the status bar correctly). However,
it apperats I'm not passing the text to the URL object. When I test the applet, a browser window
opens as it should but I get a message that the "URL is not valid and could not be loaded" (in
firefox) and the address bar is blank. So I'm assuming that the text is not being passed to the URL
object. Of course, I could be completely wrong.

2. Lets say I get this thing working correctly, is there a way to put the %20 for spaces in a URL. I
assume it's a loop that replaces spaces with the characters in a string but I'm a bit lost.

Thanks in advance!

Back to top

Kostas Zotos Posted: Sat Jan 27, 2007 6:22 pm Post subject:

Hi,
Joined: 10 Oct 2005
Posts: 154
Location: Athens (Greece)
The following suggestion requires:

OBJECTS:
1) A Java object
2) A button (optionally -as you can just press the enter key-)
3) A WF URL object (optionally -you may prefer to load the URL directly from Java object without
using the URL object..-)

CONNECTIONS:
1) From Button out-port "Button Clicked" TO Java in-port named "Submit"

In case the WF URL object will be used:


2i) From Java object out-port "URL_Text" TO URL object in-port "Set URL"
2ii) From Java object out-port "URL_Text" TO URL object in-port "Load URL"
(note: is important -and logical- for case 2 to make the connections in the given order)

Code:
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.util.StringTokenizer;

public class cwob12345 extends bob53 implements ActionListener {

String InputTxt=" Write something here...";


TextField textField = new TextField(InputTxt);
String Formated_URL="";

public void init() {


a.getCmp().setLayout(null);
a.getCmp().add(textField);
textField.setBounds(10,20,380,25); //Set position (X, Y) and dimensions
(Width, Height) of our text Field.
textField.addActionListener(this);
}

public void actionPerformed(ActionEvent ev) {


if (ev.getSource()==textField){
inport_Submit();
}
}
// ---------------------------------------- In-ports -------------------------
--------------
public void inport_Submit (){
if (textField.getText()!="") {
Formated_URL=getFormated_URL(textField.getText());
LoadURL(Formated_URL);
}
}
// ------------------------------------ Custom method(s) ---------------------
--------------
public String getFormated_URL( String arg){
String Delimiter=" "; // The string used as
separator - here is the space " " -
StringTokenizer ST = new StringTokenizer(arg , Delimiter );
String NewURLString="", ReplacementTxt="";

while(ST.hasMoreTokens()) {
NewURLString=NewURLString+ReplacementTxt+ST.nextToken();
if (NewURLString !="") ReplacementTxt="%20"; // The string which will
replace the "Delimiter" string.
}
System.out.println("\nNew URL String is: \n" +NewURLString);
return NewURLString;
}

public void LoadURL (String arg){


URL MyURL=null;
try {
MyURL=new URL(arg);
//a.showDocument(MyURL, "_blank"); // To load the URL directly -in a
blank page- (without the WF URL Object)
sendText("URL_Text", MyURL.toString());
}catch(Exception e) {
System.out.println(e); // or e.printStackTrace();
}
}
}

To load the URL directly from Java object.. modify the code (lines in bold -located at about the end
of code- ) as follow (uncomment the one line and comment -or delete- the other -second-) :
.........
MyURL=new URL(arg);
a.showDocument(MyURL, "_blank"); // To load the URL directly -in a blank page- (without
the WF URL Object)
//sendText("URL_Text", MyURL.toString());
}catch(Exception e) {
.........

Note: Java has a string "replaceAll" method that implemented from 1.4 and newer JVM versions, so a
more compatible approach -StringTokenizer
Enumeration- has been used instead.

Kostas

Last edited by Kostas Zotos on Tue Feb 06, 2007 6:34 pm; edited 1 time in total

Back to top

DaK888 Posted: Sat Jan 27, 2007 7:30 pm Post subject:

You've been at this for awhile, haven't you Kostas?


Joined: 04 Dec 2004
Posts: 45
Thanks man, I'll give this a try. I'm sure it will work. Thanks for sharing!!!!

DaK
Back to top

Kostas Zotos Posted: Sat Jan 27, 2007 7:33 pm Post subject:

Don't mention it..


Joined: 10 Oct 2005
Posts: 154
Location: Athens (Greece) Quote:
You've been at this for awhile, haven't you Kostas?

Not sure understand.. the question.. what do you mean ?

Maybe that this was just a "piece of cake" matter.. Not exactly, depends the way you see it..

Everything (and time) is relative in this life..

Back to top

DaK888 Posted: Mon Jan 29, 2007 4:46 pm Post subject:

LOL! I was just commenting on the speed and detail in which you answered my question. You're
Joined: 04 Dec 2004
Posts: 45 obviously much more experienced than I am. :D

Back to top

Kostas Zotos Posted: Tue Jan 30, 2007 2:51 pm Post subject:

Never mind.. it could be better.


Joined: 10 Oct 2005 Your initial thoughts were in the right direction.
Posts: 154
Location: Athens (Greece) Everyone starts as a newbe.. (i have still a lot to learn -still learning..-)

Back to top

Display posts from previous: All Posts Oldest First Go

All times are GMT + 1 Hour


WireFusion Forum Index -> Java in WireFusion

Page 1 of 1

Jump to: Java in WireFusion Go

You cannot post new topics in this forum


You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group

Das könnte Ihnen auch gefallen