Simple Applet Question

Hi. I have made a simple program which asks for the users name, and then using PrintWriter writes whatever the user enters, onto a text file and so on. However, I want to use this program on my webpage, currently I am using a very simple javascript 'prompt' but i do not know how to save it to a file in javascript. So I took my code and made it into an applet (extends applet, etc...) but when i load it in a web page it says loading applet and then goes away. SO, i was wondering if somebody could please help me to make my java applet have a space where the user can enter in their name and press "ok" or whatever it may be. As always here is my code that I used...
Please either help me to do this on my webpage with Javascript or a java applet, thanks alot ;)
MY CODE:
import java.io.*;
import javax.swing.*;
public class userNames
public static void main(String args[])
PrintWriter myStream = null;
try
myStream = new PrintWriter(new FileOutputStream("names.txt" , true));
catch(FileNotFoundException e)
System.out.println("Sorry, no such file");
String askName = JOptionPane.showInputDialog("Hello, what is your name?");
String a = "";
String b = null;
int count = 0;
while(askName!=a && askName!=b)
count++;
myStream.println(count + ". " + askName);
myStream.close();
JOptionPane.showMessageDialog(null, "Thank you "+ askName+"!");
System.exit(0);

An applet will try to write to the local file system, ie the user who loads the page.
That, and applets are subject to many security restrictions, File I/O being one of them. I'd suggest you give up trying this with Applet.
HTH,
Radish21

Similar Messages

  • Simple applet, curious yellow sign...

    This maybe a noob thing that I have run into. I have looked on some of the threads but can't find anything that relates to my specific problem. Below is a simple applet that displays a input message box user puts in name and it displays a greeting nothing fancy just something basic.
    I loaded the .class file on to the freewebs<dot> com server where my site is hosted at and did the applet tag and it runs. The only problem is it displays a yellow glow around the applet box and a yellow information warning. I did the reading on applets from the tutorial and didn't come across anything that mentioned anything like this, maybe I missed it. When I run the applet on the web it doesn't show any error messages or codes just that yellow information warning. How can I fix this.
    import javax.swing.JApplet;
    import javax.swing.JOptionPane;
    public class HelloFromBlahWebsite extends JApplet
              public void start()
                   String sName;
                   sName = JOptionPane.showInputDialog(null,
                   "What is your name?","Welcome to My Page",
                   JOptionPane.QUESTION_MESSAGE);
                   JOptionPane.showMessageDialog(null,
                   "Greetings From Me and welcome to my site,  " + sName + "!", "Greetings",
                   JOptionPane.INFORMATION_MESSAGE);
         }

    0xfeedadeadf15h wrote:
    How can I fix that?You don't. That's pretty much the idea ...
    Or a better question would be how do I get the applet signed so it doesn't show up?... unless of course you sign your applet. To do this you'll need to get a certificate, which costs quite some money.

  • Help - Applet Question ???

    Hi, I thought I post it yesterday, but I could not find it.
    I write a simple applet as follow:
    public class demoapplet extends Applet {
    private StringBuffer buf = new StringBuffer(1000);
    public void init() { }
    public void start() {
    //display start info
    disp("start");
    buff = processXML();
    sendHTTP(buff);
    //display start info
    disp("end");
    public void disp(string st) {
    Graphics g;
    g.drawString(st,10,60);
    public stringbuffer processXML() { ...}
    public void sendHTTP(stringbuffer buf) {... }
    My question:
    1. How to init Graphics object?
    If I use paint method, I can not pass string variable.
    2. How to send stringbuffer to another application
    via HTTP?
    3. Any problem I put my processXML and sendHTTP in start method? It only be called once when user load html page.
    Many thanks

    Hey Hi! david...
    first of all make your questions a bit more clear,
    about getting the graphics object you can get it by
    Graphics g=getGraphics();
    in the Applet.
    Also about getting the string in the paint method of the Applet. you can declare a string variable in the class and it would be accessible in the paint method.
    I first of all suggest you to get your basics right ..
    regards
    vikram

  • Simple/silly question: how do I set/change default font/color for outgoing mail messages?

    Simple/silly question: how do I set/change default font/color for outgoing mail messages?

    Just a suggestion..........
    Download Thunderbird.  Easier to use when it comes to what you want to do w/your emails. 

  • Trying to add a simple applet to a web page

    Well, I was trying to add a simple applet to a web page(php nuke Home section), it didn't fin my applet, so I changed it and added it to a simple html file to make it as simple as I could get it.
    This is the code in the html file:
    <applet code="usblock.class" width="400" height="400">The browser doesn't support applets...</applet>The directory: www/usblock.html & www/usblock.java & www/usblock.class - As you can see the files are all in the same directory/folder.
    usblock.java code:
    import javax.swing.*;
    import java.awt.*;
    public class usblock extends JApplet
         public void init()
              JPanel p = new JPanel(new BorderLayout());
              p.add(new JLabel("Heisann"));
              add(p, BorderLayout.CENTER);
    }now as I open the html local on my computer, it workes. As soon as I open the usblock.html from my website, it doesn't.
    It gives me this error here:
    load: class usblock.class not found.
    java.lang.ClassNotFoundException: usblock.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 moreSo I thought it was that it couldn't find the .class file. Well, I went through the How To add applets that I found somewhere on sun.com. It had exactly the same as I had.
    Im figuring the problem is something easy and not hard to detect. But my eyes can't find it somehow. This is my second time trying applets, and I kinda forgot how I got it to work the first time.
    Im just glad for all the help I can get.
    Thanks a lot.
    LordSvae
    PS: Sry for the size of the post, but I'm not sure how much info I was supposed to put in here, so I thought the more the better, right? :S

    Hii,
    I doesn't know the solution but same kind of problem is come with me & I found that the problem is of Path i.e. you need to set a codebase attribute . For tempory solution what i do i simply copy the .class file in to html file dir.

  • Simple Applet does not run in IE 5.0

    Hi,
    Am trying to run a simple applet in IE 5.0 on MS Window NT Server machine. I disabled the
    JVM option in Tools/Internet Options/Advanced/Java column. I have MS VM(Miscrosoft Virtual Machine) JIT(Just In Time Compiler) enabled. As a
    result any applet will run on the MS VM JIT only. I use a simple applet in which I just add
    a button to the applet. My applet runs fine in JVM Ver 1.4 but when I try to run it in MS VM
    using JIT I get the following exception
    Error loading class: ImageTest1
    java.lang.NoClassDefFoundError
    java.lang.ClassNotFoundException: ImageTest1
         at com/ms/vm/loader/URLClassLoader.loadClass (URLClassLoader.java)
         at com/ms/vm/loader/URLClassLoader.loadClass (URLClassLoader.java)
         at com/ms/applet/AppletPanel.securedClassLoad (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
         at com/ms/applet/AppletPanel.run (AppletPanel.java)
         at java/lang/Thread.run (Thread.java)
    Can any one help me in solving the problem ? My applet source is
    import java.applet.*;
    import java.awt.*;
    public class ImageTest1 extends Applet
         public ImageTest1()
              System.out.println("On the Console !!!!");
         public void init()
              Button bt = new Button("Hello !!");
              this.setLayout(new FlowLayout());
              this.add(bt);     
    Thanks,
    Bala

    Take your HTML file and convert it with the HTMLConverter that comes with your JDK, this will create an <OBJECT> tag from the existing <APPLET> in the HTML file. With the newly created <OBJECT> tag, IE will know that it's supposed to run your applet with Java plugin (the only way for you to run an applet that uses swing.
    V.V.

  • Need help coding simple applet program

    Hello I'm attempting to learn applet programming in either swing or awt. Whichever is best for current applications. I want to begin by creating my first hello world application. I want to create a simple applet that has two buttons, press button number one and the text "hello world 1" comes up somewhere on the applet, press two and "hello world 2" comes up. can anyone help me with this simple applet? Thnx in advance

    http://java.sun.com/docs/books/tutorial/applet/

  • 4 Simple Flash Questions that Are Stumping Me!

    What is the Frame Rate for Web Animations
    Q1. I am making an animation which will be played on the web. What is the default frame rate (fps) of Flash CS5? And what is the frame rate of for web?
    Q2. My animation needs to be 30 seconds long. So at 15 fps that would mean I need to use 600 frames in Flash?
    How Do I Mask everything so all I see is the Content on the Stage?
    I have a wide image that extends past my movies stage size so when I preview my movie the image is visible. How do I mask out anything that extends past my movies window size? I believe I can create a layer named "mask" and place it above all other layers, but I forget how to make the mask. Any help is appreciated.
    How to Fade a Graphic
    I have a graphic element (some type) and I want it to fade from 0% to 100%. In older versions of Flash I could just select the symbol and then set it's alpha value to 0%, move a few keyframes and then set the alpha to 100%. Voila! but now it doesn't seem to work that way. How can I do this in CS5?

    Ned, it says 24 fps which means there is 24 frames per second so each 24 frames is 1 second.
    Date: Fri, 4 Nov 2011 05:35:16 -0600
    From: [email protected]
    To: [email protected]
    Subject: 4 Simple Flash Questions that Are Stumping Me!
        Re: 4 Simple Flash Questions that Are Stumping Me!
        created by Ned Murphy in Flash Pro - General - View the full discussion
    1 You can create your character as a movieclip and copy/paste that movieclip from one file to another. 2. One way to create a movieclip is to copy all the frame of the animation's timeline (select them all, right click the selection, choose Copy Frames), then create a new movieclip symbol (Insert -> New Symbol...etc) right click on its only keyframe and chhose Paste Frames.  THat will put all the layers and frames you copied into the movieclip The only way to come close to being certain about the timing of you animation is to use code to keep track of the time, something like getTimer()..  The frame rate that a file plays at is not a reliable means of dictating the time it takes due to a variety of factors which include the amount of content you are trying to process and performance limits of the user's machine.
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4007420#4007420
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4007420#4007420. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Flash Pro - General by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Simple performance question

    Simple performance question. the simplest way possible, assume
    I have a int[][][][][] matrix, and a boolean add. The array is several dimensions long.
    When add is true, I must add a constant value to each element in the array.
    When add is false, I must subtract a constant value to each element in the array.
    Assume this is very hot code, i.e. it is called very often. How expensive is the condition checking? I present the two scenarios.
    private void process(){
    for (int i=0;i<dimension1;i++)
    for (int ii=0;ii<dimension1;ii++)
      for (int iii=0;iii<dimension1;iii++)
        for (int iiii=0;iiii<dimension1;iiii++)
             if (add)
             matrix[i][ii][iii][...]  += constant;
             else
             matrix[i][ii][iii][...]  -= constant;
    private void process(){
      if (add)
    for (int i=0;i<dimension1;i++)
    for (int ii=0;ii<dimension1;ii++)
      for (int iii=0;iii<dimension1;iii++)
        for (int iiii=0;iiii<dimension1;iiii++)
             matrix[i][ii][iii][...]  += constant;
    else
    for (int i=0;i<dimension1;i++)
    for (int ii=0;ii<dimension1;ii++)
      for (int iii=0;iii<dimension1;iii++)
        for (int iiii=0;iiii<dimension1;iiii++)
           matrix[i][ii][iii][...]  -= constant;
    }Is the second scenario worth a significant performance boost? Without understanding how the compilers generates executable code, it seems that in the first case, n^d conditions are checked, whereas in the second, only 1. It is however, less elegant, but I am willing to do it for a significant improvement.

    erjoalgo wrote:
    I guess my real question is, will the compiler optimize the condition check out when it realizes the boolean value will not change through these iterations, and if it does not, is it worth doing that micro optimization?Almost certainly not; the main reason being that
    matrix[i][ii][iii][...]  +/-= constantis liable to take many times longer than the condition check, and you can't avoid it. That said, Mel's suggestion is probably the best.
    but I will follow amickr advice and not worry about it.Good idea. Saves you getting flamed with all the quotes about premature optimization.
    Winston

  • Simple Applet not running in ie 5

    Hi I have built a simple applet consisting of 4 classes, The button panel, and three listener classes. When I run this from the command line it works fine, and presents me with a grey panel (100 * 180) and the three buttons are drawn onto the applet all of which work fine. But when I use the plug in html page I get a grey panel with a red 'X' in the top left hand corner! Do I have to upload all of this before I can even test it, or is it just a dumb typo??
    Here is the HTML plug in:
    <html>
    <head>
    <title>Button Applet</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <applet CODE="Buttons.class" CODEBASE = "Sun">
    </applet>
    </body>
    </html>

    Change your html file to look like this:
    <applet CODE="Buttons.class" CODEBASE = ".">
    Put the html file in the same directory as the one with the Buttons.class and try it again.
    ;o)
    V.V.

  • A few simple Logic questions...please help.

    I have a few probably simple Logic questions, that are nonetheless frustrating me, wondering if someone could help me out.
    1. I run Logic 8, all of the sounds that came with logic seem to work except organ sounds. I can't trigger any organ sounds (MIDI) on Logic, they won't play. I have a Yamaha Motif as my midi controller.
    Any idea why?
    2. I've starting running into a situation where I will record a MIDI track, the notes are recorded but they won't playback. The only track effected is the one that was just recorded. All other midi tracks playback.
    I have to cut the track, usually go out of Logic and back in, re record for it to playback properly. Any idea why this may be happening?
    3. How important is it to update to Logic 9. Are there any disadvantages down the road if I don't upgrade. If I purchase the $200 upgrade, do I get a package of discs and material, or it just a web download.
    Any help is appreciated!
    Colin

    seeren wrote:
    Data Stream Studio wrote:
    3) You get a full set of disks and manuals.
    They're including manuals now?
    I think his referring to the booklets ...on how to install etc
    It would be great to see printed manuals though ...I love books especially Logic/Audio related !!
    A

  • Simple applet html editor

    Hi,
    I need a simple applet html editor.
    Does anyone has implemented one?
    The functions I need is bold, italic, insert table, insert image, and all basic functions of an editor
    I need some source, because I dont want to make it from scratch
    Thanks

    Using the search feature of this site, I found:
    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=%2Bforum%3A57&qt=html+editor
    ;o)
    V.V.

  • Help with simple applet - dragging box

    Hi I need help with a simple applet concept.
    I have a picture drawn in the background, but I need to draw a square and resize it when I drag.
    So with the picture in the background I click, drag the mouse, and it draws a rectangle from the starting point to where the mouse is while the mouse is clicked.
    The only problem is I can't figure out how to do this without redrawing the whole picture. If I don't repaint, it just keeps stretching around rectangles and leaving them there.
    I don't really need exact code, just an idea on how to do this without repainting the background every time the mouse is moved (because the picture in the background is complicated to draw and takes like a second).
    Thanks
    [nvm, found out about xormode]
    Edited by: BugMenOTdhzj on Nov 30, 2009 4:47 PM

    BugMenOTdhzj wrote:
    ..the picture in the background is complicated to draw and takes like a second).Paint the 'picture in the background' to a BufferedImage, then when it comes to paint()/paintComponent(), draw the BI to the Graphics object (clipped, if necessary (1)), then draw the rectangle to the Graphics object. This would be further optimised at time of rendering, by drawing both the 'picture in the background' BI and rectangle to a second BI, and finally writing that 2nd BI to the Graphics object.
    1) There are potentially other improvements that can be made, particularly with clipping, but I suspect if you try as I suggested, the rendering will be very quick and responsive. I have 40 FPS sound trace animations that do a great deal more on each call to paintComponent(), before bursting the final BI to screen.

  • Simple Quick Question

    wrong section, post was moved.
    Message was edited by:
    Rob17

    you titled "simple quick question"...
    .. complicated to answer..
    a) the TermsOfUse of the iTS don't allow any processing of purchased files, these are "copy protected"..
    b) iM has a voice-over function..
    c) iM is a video-edit app.. easy to use... just learn to handle it...
    d) iM allows to "extract" audio (=muting the original audio, adding your own..)
    e) to learn iM, spend some time here: http://www.apple.com/ilife/tutorials/imovie/index.html
    f) use pencil and paper first! WRITE and scribble, what shall happen when in your movie/parody... make a script, draw a storyboard .. THEN launch iM.. in other words: think first, then edit.. iM is just a tool, it does not "create"... Picasso needed a papertowel and half a stencil to create art....
    g) to get comfortable with iM, start with your own, small, short (3min!) project... import some stills, edit them, add a funny voice-over, add sounds, add music... good? make a bigger one...
    h) .. in our Lecture II, we teach you how to import shows from TV, youtube, wherever..
    standard disclaimer:
    be nice to ©opyrights ...

  • Simple query question

    hi all,
    I have a XMLType table with one column - I have presently one row, in my column xmlsitedata I have stored one large xml file.The schema definition is given below:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    - <xs:element name="siteList">
    - <xs:complexType>
    - <xs:sequence>
    <xs:element name="site" type="siteType" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    - <xs:complexType name="siteType">
    - <xs:sequence>
    <xs:element name="nameEn" type="xs:string" />
    <xs:element name="nameFr" type="xs:string" />
    </xs:sequence>
    <xs:attribute name="code" type="xs:string" />
    </xs:complexType>
    </xs:schema>
    I have executed the query below:
    select x.XMLSITEDATA.extract('/siteList/site/nameEn/text()').getCLOBVal() "stName" from wsitelist x;
    and I get all english names of some 200 locations, however, there is 1 row selected and all names show up on one row. How do I split them into 200 or whatever rows?
    Thanks,
    Kowalsky

    Have a look at the answer provided in the following thread.
    very simple XML question
    This may solve your problem.
    use xmlsequence.
    Alvinder

Maybe you are looking for

  • Problem with java based Web Services in ADF-.

    I have developed a Web service based on the Java class generated through Business components. Steps are as below:- 1)     Created a Read only View Object with EmpDeptViewObj name and has following query:- “select e.EMPLOYEE_ID,e.FIRST_NAME,e.LAST_NAM

  • Using remote folders as default iTunes music location

    Hello, I have all my music on a RAID5 Windows server that resides on my LAN. In Windows Media Player, I have the application monitoring my music folder on the server. WMP correctly displays music from the shared folder in my library. In other words,

  • Contact photo's show us too large?

    Not a big deal but just wondering if anyone else is experiencing or have even noticed when some of your contacts call you their contact photo is too big for the screen? Like it was resized or something? I upgraded from 3G to IP4 so I'm sure that's th

  • Locking tables

    I am declaring and using the following cursor:      CURSOR curCompany IS           SELECT c.Company_ID, c.No_Employees                FROM Company c                WHERE (SELECT COUNT(*) FROM Student s                     WHERE s.Company_ID = c.Compa

  • Pages won't load colmpletely although page says loading is 'done'

    When loading a page or link the page says it's 'done' loading but the loading bar is still not complete and the page can not be clicked on. I cannot reload the page as I can't click on any of the buttons and so I have to close the window completely a