Results 1 to 8 of 8
  1. #1
    barr is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default Help with newb-project much appreciated

    Hi, I'm quite new to java and have never done any applets before.

    Now I need to create a fileupload-applet för my webpage. I guess I'm into some serious learning by trial-and-error and I need it done by 12/12 :p

    Anyhow, I've managed to get a HelloWorld applet up and running, and now I need to learn how to communicate with servers and send files. A google search mostly ends up in ads for fileupload-applets, so I thought I'd try this forum out.

    Is there any good tutorials for java/server communications, or can anyone here show me some examples?

    The book I've got, Java Software Solutions, does unfortunately not adress these things...

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Welcome...

  3. Commmunications:
  4. Networking Basics (The Java™ Tutorials > Custom Networking > Overview of Networking)
  5. Lesson: All About Sockets (The Java™ Tutorials > Custom Networking)
Luck,
CJSL
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Reply With Quote Reply With Quote

  • #3
    barr is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    Thank you, I wasn't aware of that sun had those basic tutorials. Neat.

    Question: Is there a way for the applet to know it's location on the server?

    For example, the applet is located at "htp://mydomain.com/scripts/applet/", and I want to connect with a php-file in the same folder.

    So instead of:

    Java Code:
    URL  requestHandler = new URL("htp://mydomain.com/scripts/applet/requestHandler.php");
    Can I do something like this?

    Java Code:
    URL appletLocation = *get the location of the applet*;
    URL requestHandler = new URL(appletLocation, "requestHandler.php");
    Last edited by barr; 12-04-2008 at 02:46 PM.

  • #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    Java 2 Platform SE 5.0 look at the getPath(), getHost() etc methods. I think those may be what you want

  • #5
    barr is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by xcallmejudasx View Post
    Java 2 Platform SE 5.0 look at the getPath(), getHost() etc methods. I think those may be what you want
    Thanks, I found the getCodeBase() that seems to be what I want.

    *********************

    Now I'm working with the interface, and I have a problem with the following code:

    Java Code:
    public class gallery{
    		JLabel title = new JLabel("Gallery");
    		public void show(){
    			contentPanel.removeAll();
    			contentPanel.add(title, BorderLayout.NORTH);
    			contentPanel.add(text, BorderLayout.CENTER);
    			
    		}
    	}
    	
    	public class uploader{
    		JLabel title = new JLabel("Uploader");
    		public void show(){
    			contentPanel.removeAll();
    			contentPanel.add(title, BorderLayout.NORTH);
    			contentPanel.add(text, BorderLayout.CENTER);
    			
    		}
    	}
    I have two buttons, one for uploading and one for browsing. The event handlers for the buttons sets the JLabel text to a string returned from a php-page that returns time(), and calls uploader.show() resp. browser.show(), that clears the contentPanel and adds it's own content.

    However, the JLabel title only changes the first time I press a button, if I first press the button "upload", the title changes to Uploader, and if I then press "Browse", the title changes to "Gallery". But after that, the title don't change anymore. But the JLabel text change each time I press a button.

    How can this be?

  • #6
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    I'm not familiar with JLabel or contentPanel but I think it may be something to do with add. Is there a set or clear method available? The way I picture any add method working is to actually add some object, not just change the text of the object, which is why I think you may need to contentPanel.set() or something.

    Have you tried clearing the title right after the button is pressed and then re-writing the title again over it?

  • #7
    barr is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    Thanx, I found out that contentPanel.validate() solved my problem.

  • #8
    barr is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    I've come to the point where a can send and recieve http-requests, but I'm doing something wrong.

    Java Code:
    POST /info.php HTTP/1.1
    Host: mypage.com
    Connection: Keep-Alive
    Content-Type: multipart/form-data; boundary=gismoquack
    Content-Length: 158
    
    
    --gismoquack
    content-disposition: form-data; name="id"
    
    user
    --qismoquack
    content-disposition: form-data; name="filename"
    
    test.jpg
    --qismoquack--
    info.php checks if "id" and "filename" is posted, but it says that only "id" is posted.

    Can you see what I've done wrong?

  • Similar Threads

    1. Project Help
      By XxHEXSORxX in forum AWT / Swing
      Replies: 4
      Last Post: 01-28-2009, 10:01 AM
    2. Help With Project!!!
      By jackhammer in forum New To Java
      Replies: 5
      Last Post: 12-04-2008, 05:10 AM
    3. Java newb Q: 8-digit id
      By 1111FM in forum New To Java
      Replies: 2
      Last Post: 09-29-2008, 02:37 PM
    4. Newb Topics
      By dkizzy in forum New To Java
      Replies: 2
      Last Post: 09-17-2008, 07:01 AM

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •