Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to make an applet save some data in a txt file at the ftp/server?  (Read 3278 times)
0 Members and 1 Guest are viewing this topic.
Avenger
Guest
« Posted 2006-04-19 18:47:57 »



EDIT : Look at my last post to see , I changed my mind and hence changed the problem.Did not wanna start a new topic.
Offline cborders

Junior Member





« Reply #1 - Posted 2006-04-19 19:01:53 »

make the action of the submit
1  
mailto:whoever@whereever.com
Avenger
Guest
« Reply #2 - Posted 2006-04-19 19:56:18 »

I  meant ... hm ... mailto , whose method is it?Or u mean html ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cborders

Junior Member





« Reply #3 - Posted 2006-04-19 20:21:46 »

It's an html thing
1  
<a href="mailto:whoever@whereever.com">Email Link</a>
Avenger
Guest
« Reply #4 - Posted 2006-04-19 20:57:38 »

EDITED :

Basically I changed my mind.As I described this is an applet.It shows 3 JTextFields and a JButton.I have this applet uploaded in my ftp and I run it from an index.html .  I want to take what is contained inside the JTextFields and write it inside a .txt file which is in my ftp called form.txt . Here is the whole code of the applet.It does not work.It loads the applet with its fields and the submit button but it does not write anything in the .txt file.

It is my first ever attempt at an applet so please excuse my inexperience.I tried many stuff .. been googling and checking tutorials and Streams .. and tried to wrap all streams I could find but still I could not do it :/ .Plz help me understand it because I really am at a loss as to how I should do it.So .. here is the code :

(note it was supposed to be somethign nice I wanted to make for my guild @ World Of Warcraft ... but damn me , it always is so easy in theory , but never in practise :/ )

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.URL;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;


public class DLFormApplet extends JApplet
{
   
    public void init()
    {
        DLForm form = new DLForm();
        add(form);
       
    }
}

class DLForm extends JPanel
{
    JPanel buttonPanel , mainPanel;
    JButton submitButton;
    JTextField contractorsName , targetsName , emailField;
    String form;
    FileOutputStream out;
    PrintStream p ;
    URL url;
   
       
    public DLForm()
    {
        SubmitListener l = new SubmitListener();
        buttonPanel = new JPanel();
        submitButton = new JButton("Submit");
        buttonPanel.add(submitButton);
        add(buttonPanel , BorderLayout.SOUTH);
       
        mainPanel = new JPanel();
        mainPanel.setLayout(new GridLayout(0,2));
        add(mainPanel , BorderLayout.CENTER);
       
        url = this.getClass().getClassLoader().getResource("form.txt");
       
         try
        {
            out = new FileOutputStream(url.getFile());
        }
        catch(Exception e)
        {
            e.getStackTrace();
        }
       
       
        contractorsName = new JTextField();
        addRow("Enter your character's name here:" , contractorsName);
        contractorsName.getDocument().addDocumentListener(l);
       
        targetsName = new JTextField();
        addRow("Enter target's name here:" , targetsName);
        targetsName.getDocument().addDocumentListener(l);
       
        emailField = new JTextField();
        addRow("Enter your email here:" , emailField);
        emailField.getDocument().addDocumentListener(l);
   
        submitButton.addActionListener(l);
       
     
    }

    public void addRow(String label, JTextField textField)
    {
        mainPanel.add(new JLabel(label));
        mainPanel.add(textField);
       
    }
   
    public String submit()
    {
        String s;
        s = "Contractor's name : "+contractorsName.getText()+"\n"+
                "Target's name : "+targetsName.getText()+"\n"+
                "Contractor's email : "+emailField.getText();
        return s;
    }
   
    private class SubmitListener implements ActionListener , DocumentListener
       {
           public void actionPerformed(ActionEvent event)
                    {
                        form = submit();
                        try
                        {
                        p = new PrintStream(out);
                        p.println(form+"\n");
                        p.println("ELEOS !!!! ELEOS !!!");
                        p.close();
                        }
                        catch(Exception e)
                        {
                            e.printStackTrace();
                        }
                    }

        public void insertUpdate(DocumentEvent e)
        {
        }

        public void removeUpdate(DocumentEvent e)
        {
        }

        public void changedUpdate(DocumentEvent e)
        {
        }
       }
   
}
Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2006-04-20 04:37:39 »

One way or another you are going to have to transfer uisng the FTP server which means FTP protocol.

You might want to start here:
http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp.html

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Avenger
Guest
« Reply #6 - Posted 2006-04-20 12:36:11 »

Hey Jeff thanks a lot ! I read the whole article and decided that I would use Jakarta Commons/Net library.But you see I have never used another library before other than the standard code which comes with jdk.So I am not sure as to how I can import it in my code.

I did as some tutorials suggested , adding the commons-net-1.4.1-src.zip in the classpath but I can not import from it.I tried playing around with its position but nothing worked so far.How do you use a library you jave just downloaded in your code?I have never done that before  Huh

Also later .... when I will want whoever acceses the ftp server to be able to do that thing I want , where in the ftp should I put the library ? I am confused as to how this whole thing works
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #7 - Posted 2006-04-20 12:58:37 »

I did as some tutorials suggested , adding the commons-net-1.4.1-src.zip in the classpath but I can not import from it.

That zip is the source code (thus the "-src").  You want to get a jar of the compiled commons-net classes and add that to your classpath.
You could also unzip the file you have and build the jar from the source.

Avenger
Guest
« Reply #8 - Posted 2006-04-20 13:03:42 »

hmmm and how do I build a jar file?I mean .. I should take the src/java/org/  .java files from in there and how do I make them all in a jar fie?
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #9 - Posted 2006-04-20 15:44:27 »

You would follow the instructions for building it that you find on the Jakarta Commons web page...

http://jakarta.apache.org/commons/building.html

.. they seem unnecessarily complicated... "maven" is a bit harder to use than "ant"... so..

Just go here http://jakarta.apache.org/site/downloads/downloads_commons-net.cgi
and download the binary distribution instead of the source.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #10 - Posted 2006-04-20 18:21:51 »

Hey Jeff thanks a lot ! I read the whole article and decided that I would use Jakarta Commons/Net library.But you see I have never used another library before other than the standard code which comes with jdk.So I am not sure as to how I can import it in my code.

I did as some tutorials suggested , adding the commons-net-1.4.1-src.zip in the classpath but I can not import from it.I tried playing around with its position but nothing worked so far.How do you use a library you jave just downloaded in your code?I have never done that before  Huh

To add a Jar:

If you are  in an IDE you generally set it in projedct properties.

If you are on the command line you put a reference in your classpath:
eg java --classpath .;foo.jar

However it looks like you downloaded source not the jar  This means you are either going to have to put it in with ther est of your source code to compile as aprt of your own source base OR compiel it yourself seperately into a JAR

or go find one thats already compield into a JAR for you.

Quote
Also later .... when I will want whoever acceses the ftp server to be able to do that thing I want , where in the ftp should I put the library ? I am confused as to how this whole thing works

See above.  If the JAR also has a native portion with it (ftp shouldnt) then you also need to make that dll/so/whatever your local natvie format dynamic load library is available on your library load path.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Avenger
Guest
« Reply #11 - Posted 2006-04-20 23:38:20 »

Thanks to both of you.I did a quick scan of what you said and I think I understood it , but I will have to test it more thoroughly later though.I will be at my parents house for the next 4 days without a computer , so I will check it when I come back and tell you if it worked.Thanks again  Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!