[4034] in java-interest

home help back first fref pref prev next nref lref last post

Re: Can someone please help me on 3 java things.

daemon@ATHENA.MIT.EDU (Lein Ton)
Thu Dec 7 23:31:19 1995

Date: Thu, 7 Dec 1995 20:33:45 -0500 (EST)
From: ton@cc.gatech.edu (Lein Ton)
To: Jonathan_Mark_Smith@CCMAIL.PRUSEC.COM, java-interest@java.sun.com

----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Content-Lines: 51

Hi Jonathan,

1)
saving to and reading from files is not possible from applets if
they run under Netscape (security). With the appletviewer it works
though.
What I'm currently coding is saving through email, and loading 
through an URL. It's not ideal, but I seem to be able to get it 
to work. 

Reading and writing are performed with FileOutputStream and
FileInputStream (how unexpected!)

2 small examples:

FileInputStream fi = new FileInputStream(fileName);
aByte=fi.read();
fi.close();

FileOutputStream fo = new fileOutputStream(fileName);
fo.write(anInt);
fo.close; 

You most probably want to know how to write Strings etc. 
I still have to find out, but it will have something to do with
reading and writing arrays of bytes.

2)
I don't know how to use java as an CGI program, but I figure that
it works exactly the same as starting other scripts; you might
even be able to start it from a perl script.

I used a mailto cgi script to send mail within java by doing this:
	  try {
	    URL u= new URL("http://icg.resnet.upenn.edu/mailto.cgi?to=you@there
                           &from=me@here&subject=mysubject&body=mybody");
	    u.openConnection();
	    InputStream is=u.openStream();
 	    while (is.available()!=0) {
	      is.read();
	    }
	  } catch (IOException e) {
		System.out.println("exception");
	  }
Perhaps there's an easier way, but this works.

3)
see the included file (I don't know exactly what you mean by option buttons)

take care, 
Lein
----------
X-Sun-Data-Type: default
X-Sun-Data-Description: default
X-Sun-Data-Name: Test2.java
X-Sun-Content-Lines: 109

import java.awt.*;
import java.applet.*;

public class Test2 extends Applet
{
        Panel infobar;
        Panel mainbar;
        TextField name;
        TextField email;
        TextField usrl;
	Choice myChoice;

        public void init()
        {
                setLayout(new BorderLayout());
                setBackground(Color.gray);
                setFont(new Font("Helvetica", Font.BOLD, 12));
        }

        public void start()
        {
                Panel p = new Panel();
                p.setLayout(new GridLayout(2,2));
                p.add(name = new TextField("Name", 30));
                p.add(email = new TextField("E-mail address",30));
                p.add(usrl = new TextField("URL",30));
               
                mainbar = new Panel();
                mainbar.setLayout(new BorderLayout());
                mainbar.add("West", p);

                
		/*                List l = new List();
                l.setMultipleSelections(false);
                l.addItem("Java is Cool");
                l.addItem("This applet is cool");
                l.addItem("I want more");
                l.addItem("John is greats");
                */


		myChoice=new Choice();
		  myChoice.addItem("Java is Cool");
		  myChoice.addItem("This applet is cool");
		  myChoice.addItem("I want more");
		  myChoice.addItem("John is greats");
                add("West", myChoice);


                add("Center", mainbar);
 
                infobar = new Panel();
                infobar.add(new Button("Send data to Site"));
                infobar.add(new Button("Clear all Fields"));
                infobar.add(new Button("Reset all Fields"));
                infobar.setBackground(Color.red);
                add("South", infobar);
        }

        public boolean action(Event evt, Object arg)
        {
                if("Send data to Site".equals(arg))
                {
                        
                        showStatus("If this worked... the data would be submitting");
                        return true;
                }
                else if("Clear all Fields".equals(arg))
                {
                        name.setText("");
                        email.setText("");
                        usrl.setText("");
                        return true;
                }
                else if("Reset all Fields".equals(arg))
                {
                        name.setText("Your name here please");
                        email.setText("Your e-mail address here please");
                        usrl.setText("Your URL have please");
                        return true;
                }
                else if(evt.target instanceof List)
                {
                        showStatus(arg.toString());
                        return true;
                }
	if (evt.target == myChoice) {
	  switch(myChoice.getSelectedIndex()) {
	  case 0: {
	    break;
	  }
	  case 1: {
	    break;
	  }
	  case 2: {
	    break;
	  }
	  case 3: {
	    break;
	  }
	  }
	  return true;
	}
                return false;           
        }

}


-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post