FileDialog in AWT Applet

Hi,
I have an applet with menu options for Opening and saving a file. Is there any way to create a file dialog for opening and saving through AWT without any usage of SWING?
Any response will be greatly appreciated!!

/*  <applet code="FileApplet" width="400" height="400"></applet>
*  use: >appletviewer FielApplet.java
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class FileApplet extends Applet
    public void init()
        final TextArea textArea = new TextArea();
        final FileDialog
            openDialog = new FileDialog(new Frame(), "open", FileDialog.LOAD),
            saveDialog = new FileDialog(new Frame(), "save", FileDialog.SAVE);
        openDialog.setDirectory(".");
        saveDialog.setDirectory(".");
        final Button
            open = new Button("open"),
            save = new Button("save");
        ActionListener l = new ActionListener()
            String newLine = System.getProperty("line.separator");
            public void actionPerformed(ActionEvent e)
                Button button = (Button)e.getSource();
                if(button == open)
                    openDialog.show();
                    if(openDialog.getFile() == null)
                        return;
                    File file = new File(openDialog.getFile());
                    BufferedReader br = null;
                    try
                        br = new BufferedReader(new InputStreamReader(
                                                new FileInputStream(file)));
                        textArea.setText("");
                        String line = "";
                        while((line = br.readLine()) != null)
                            textArea.append(line + newLine);
                        br.close();
                    catch(FileNotFoundException fnfe)
                        System.out.println(fnfe.getMessage());
                    catch(IOException ioe)
                        System.out.println(ioe.getMessage());
                if(button == save)
                    saveDialog.show();
                    if(saveDialog.getFile() == null)
                        return;
                    File file = new File(saveDialog.getFile());
                    // write to file...
        open.addActionListener(l);
        save.addActionListener(l);
        Panel northPanel = new Panel();
        northPanel.add(open);
        northPanel.add(save);
        setLayout(new BorderLayout());
        add(northPanel, "North");
        add(textArea);
    public static void main(String[] args)
        Applet applet = new FileApplet();
        Frame f = new Frame();
        f.addWindowListener(new WindowAdapter()
            public void windowClosing(WindowEvent e)
                System.exit(0);
        f.add(applet);
        f.setSize(400,400);
        f.setLocation(200,200);
        applet.init();
        applet.start();
        f.setVisible(true);
}

Similar Messages

  • The final solution to greek characters in AWT applets(????)

    OK. I have searched the whole web and asked whoever I knew. The question was simple: How do I show greek characters in a TextField in an AWT Applet? Some people said that I should change the font properties inside MY jre/lib installation but then I want EVERYONE and not just ME seeing the greek characters! Adding a greek font into the applet's jar was another "solution" but who wants to have an applet of about 2MBs? So I think I have come up to the answer ... ONLY with jre > 1.4.0 somebody could handle greek characters in AWT Applets without trooble! If somebody has managed to show and handle greek characters in a TextField inside an AWT Applet (which I doubt), I would like to know EXACTLY HOW as I am tired of non-working "solutions"! I hope this post saves you from a lot of time searching for the HolyGrail

    I haven't worked with a TextField but I worked with a JTextField. My solution wasn't very straightforward but it did the job.
    I used this solution in order to work with linux, but you must add an if
    statement to check the OS.
    If your problem was how to view Greek characters in a non internation version of
    Java, then as far as I know, you cannot! Also JDK 1.3.1_01 and j2re 1.4.0_01
    use a different way of loading system fonts, so with the latter you cannot use system fonts unless you put them in you java directory.
    (I use linux so don't be surprissed if these work different in windows)
    import java.io.*;
    public class JTextFieldGr extends javax.swing.JTextField {
    public JTextFieldGr() {
    super();
    myInit();
    public JTextFieldGr(String text) {
    super(text);
    myInit();
    public void myInit() {
    addKeyListener(new java.awt.event.KeyListener() {
    public void keyTyped(java.awt.event.KeyEvent evt){
    try{
    String tmp=""+evt.getKeyChar();
    String uk=new String(tmp.getBytes(),"ISO-8859-7");
    evt.setKeyChar(uk.charAt(0));
    }catch(UnsupportedEncodingException e){
    e.printStackTrace();
    public void keyPressed(java.awt.event.KeyEvent evt){
    public void keyReleased(java.awt.event.KeyEvent evt){
    }

  • Awt Applet storing data in an array

    Hi,
    I have developed an awt applet which allows user to enter and store information in array. Yet, everytime i run my applet again previous information are lost. Has anyone got an idea of how i can resolve this.

    Hi,
    The problem is everytime u reload the applet the array gets re initalised and all its previuos contents are lost.
    u can try this
    use a vector instead of an array to store all the user information and then using ObjectOutputStream write it to a persistable store(eg:- a file or a database)
    since vector class is serialiable u can achieve this.
    but incase u r planning to write it into a file or insert it into the databse from an Applet u need to set appropriate permmissions for the applet by editing the policy file.
    hope that was helpful
    Regards,
    Partha

  • Displaying Asian characters in an AWT applet

    I want to display texts in different Asian languages (Chinese, Japanese, and Korean). The localized texts are correctly displayed by the applet if I use a font like Arial Unicode MS that supports all Asian Unicode characters. But I can not use this font for display the text because even on a Windows PC I can not be sure that this font is available. The alternative seems to be to use language dependent different fonts but I could not find comprehensive Information which font to use with which language. I thought also about the alternative to use a logical font name and adjust the font.properties file but the applet has to work also with the Microsoft JVM and I could not find any information about changing the font.properties for this VM. I also think that not every user of this applet is willing to adjust the font.properties. What is the best solution to support multiple Asian languages in the output of an applet?
    I am new to the problem of localization of Java applets so maybe this question sounds very simple for more experienced programmers.
    Thank you in advance for your help.
    Roland

    mswanson, I sincerely appreciate you posting your
    solution here for all of us to read. However, I
    wouldn't summarize downloading and installing a 24 mb
    font as "doing nothing", as you seem to state here.I could have worded it better. When I said, "do nothing except..." I was refering to the font.properties file. In fact, if you re-read the previous sentence you will see I started it with, "wrt font.properties...". "wrt" means "With Respect To".
    Also, the referenced page does not provide a link for
    downloading the font, as it seems to imply.My posting implied no such thing.
    So, anybody know if this is possible for the Arial
    Unicode MS font or any other comparable font? Any
    other ideas addressing the same problem?The HTML page I linked to contains a paragraph, "Windows 95, 98, 2000, XP, 2003 Fonts" and its first sentence contains a link to get the font - and you can derive all of your legal answers from that link as well (microsoft.com).
    Cheers.

  • Help - Why don't swing applet print, like awt applets do?

    I am using JTable in a applet, but I would like to be able to print the applet using microsoft explorer. I had written a bulkier version of the same applet using an array of TextFields to establish a Table effecte. The code is bulking and loads slow in the browser. JTables work better but the applet shows up all black when I try and print it. What do I do to fix the problem? Do I have to use TextField if I want to print it? Any suggestions would be helpfull.

    While waiting I dug deeper into the bugged section of code and found that:
    divider.setBounds(0,62,600,2);
    was the problem, and that:
    divider.setBounds(0,62,600,4);
    works.
    Don't ask me why I couldn't tell you, but IE 6 doesn't like the heigth to be less than 4. If it is the entire applet prints out black.

  • Applet(AWT) & JPanel(SWING)

    Can I add a AWT Applets to a JPanel?

    why would u want to do that??
    if u see Applet extends panel

  • Filedialog and applet

    i have a application taht compile perfectly when i made program, but when i made applet with it, the compiler stop to the filedialog, is filedialog ok with applet?

    Hi,
    Yes it is just make sure you have a frame to parent
    the dialog. An applet can't be the parent of the
    dialog. Something like:
    Dialog d = new Dialog( new Frame() );
    d.show();
    Regards,
    Manfred.thx man i didnt know that, now that work pefectly!!! thx man
    im leaving this topic

  • How to use the applet to upload the file ?

    I am facing a problem that , I don't know how to use applet to upload the file to server .
    I have the code to upload the file by using servlet .
    However , I want to use applet to upload the file .But , the format of servlet I have used is "multipart/form-data"
    but applet can not do so , I think it is the header of the data . I don't know what can I do .....
    Can anyone give me some suggestion or coding to write the file upload by using applet ?
    Besides , using the socket are there any other choices ?
    thx a lot !!!!

    Well, to upload files you need to
    Server App - running on the webserver
    1. Open a socket
    (Study the classes Socket, InputStream, OutputStream in the Java API)
    2. Wait for connection.
    3. Open FileOutputStream
    3. Read data from InputStream, Write to FileOutputStream
    4. Close InputStream and FileOutputStream
    Applet
    1. Open a filedialog (Swing, AWT)
    2. Open file (FileInputStream)
    3. Connect to uploadServer (steps described above)
    4. Read FileInputStream, write OutputStream
    5. Close File and Socket
    This is just simpl and basic terms get you on the right track
    Jonas

  • Unable to download images in a swing applet (1.3.1) behind proxy

    Hi
    One of my client have a proxy server and firewall and when they try to access my webserver
    then all the AWT applet are downloaded and rendered on client properly. However, the swing applet written
    using JDK 1.3.1 is downloaded and rendered but it doesn't display anything properly as images
    are not down loaded. I have used media tracker to add images to it like oMediaTracker.addImage( oImage, index );
    and then oMediaTracker.waitForAll();
    Java console display at client looks as follows:
    Java(TM) Plug-in: Version 1.3.1
    Using JRE version 1.3.1 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\toy
    Proxy Configuration: no proxy
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    q: hide console
    s: dump system properties
    t: dump thread list
    x: clear classloader cache
    0-5: set trace level to <n>
    Applet Initialization start...
    Applet Image Initialization start...
    Trace level set to 5: basic, net, security, ext, liveconnect ... completed.
    Opening      http:MyServer/24/x.gif
    Connecting     http:MyServer/24/x.gif with no proxy
    Connecting
    http:MyServer/24/x.gif with cookie "ASPSESSIONIDGQGQQVWC=DLNBDAOABFANEPJFFIGOOIPG;
    JSESSIONID=25Ais2tF1eBkevUhAa2akocfShzNdzyL7yC1I7UhJl7Z6BLZrnQK!
    -1149265879"
    Opening      http:MyServer/40/y.gif
    Connecting      http:MyServer/40/y.gif with no proxy
    Connecting      http:MyServer/40/y.gif with cookie "ASPSESSIONIDGQGQQVWC=DLNBDAOABFANEPJFFIGOOIPG;
    JSESSIONID=25Ais2tF1eBkevUhAa2akocfShzNdzyL7yC1I7UhJl7Z6BLZrnQK!
    -1149265879"
    Opening     http://MyServer/sun/beans/infos/PanelBeanInfo.class
    Connecting     http://MyServer/sun/beans/infos/PanelBeanInfo.class with no proxy
    Connecting http://MyServer/sun/beans/infos/PanelBeanInfo.class with cookie "ASPSESSIONIDGQGQQVWC=DLNBDAOABFANEPJFFIGOOIPG;
    JSESSIONID=25Ais2tF1eBkevUhAa2akocfShzNdzyL7yC1I7UhJl7Z6BLZrnQK!
    -1149265879"
    Opening http://MyServer/java/awt/ContainerBeanInfo.class
    Connecting http://MyServer/java/awt/ContainerBeanInfo.class with no proxy
    Connecting http://MyServer/java/awt/ContainerBeanInfo.class
    Client machine tries to access these images but i never receive a call at web server end when i see
    IIS log.
    CLient environment:
    -Windows 2000/XP/NT
    -Internet explorer 6.0 SP1 or IE 5.5 SP2
    with connection->LAN Setting->Use Automatic configuration script(only checked)
    -Java Plugin configured like proxies->Use Browser Setting
    -JDK 1.3.1 plug in at client(downloaded and Installed automatically on demand)
    -Object tag used to download applet and plugin
    -Firewall and proxy(i don't know about vendor)
    My webserver environment
    Windows 2000/iis 5.0 with anonymous authentication and
    cache-control header set to no-store (so that proxy doesn't cache anything)
    QUESTIONS:
    ~~~~~~~~~
    Q.1. When i try from home network that has a proxy then everything works fine. At client site everything except
    image download works fine. I mean jars are downloaded and i can see anything drawn using JAVA API.
    When i try from home i see following java console trace
    Java(TM) Plug-in: Version 1.3.1
    Using JRE version 1.3.1 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\wuko
    Proxy Configuration: Automatic Proxy Configuration
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    q: hide console
    s: dump system properties
    t: dump thread list
    x: clear classloader cache
    0-5: set trace level to <n>
    Trace level set to 5: basic, net, security, ext, liveconnect ... completed.
    Applet Initialization start...
    Applet Image Initialization start...
    Opening http://MyServer/24/connec.gif
    Connecting http://MyServer/24/connec.gif with proxy=197.168.1.100:808
    Connecting http://MyServer/24/connec.gif with cookie "ASPSESSIONIDQQGQQCYU=GBJFAOABCJFPDMGFHEKLDACA; JSESSIONID=26yu5m1b4upVuXoAoDmtMbWXQmetQpyzqjFANszo9vFubujT4qGX!-1149265879"
    Opening http://MyServer/24/cool.gif
    Connecting http://MyServer/24/cool.gif with proxy=197.168.1.100:808
    Connecting http://MyServer/24/cool.gif with cookie "ASPSESSIONIDQQGQQCYU=GBJFAOABCJFPDMGFHEKLDACA; JSESSIONID=26yu5m1b4upVuXoAoDmtMbWXQmetQpyzqjFANszo9vFubujT4qGX!-1149265879"
    etc
    I can't set the plugin at client to use automatic script just like IE browser uses. This option is not supported in JRE1.3.1. Looks to be supported in JRE1.4.1. My client doesn't want to set manual proxy ip and port in plugin as they don't want to reveal this info to everyone within the company for security reason.
    Q.2. Why some classes like PanelBeanInfo.class, JAppletBeanInfo.class are downloaded
    from my server while it doesn't exist at my webserver. Any thing stupid IE or plugin doing
    at client. Any Idea?
    Thanks in advance for any help.
    Ratan

    Thanks to Mike and other friends who already replied on this topic.
    Here is my research analysis:
    Answer to Question 1:
    ~~~~~~~~~~~~~~~~~~~~~
    The solution is to bundle all the images with JAR. Bundle with jar whichever needs it. However, it might require duplicacy.
    Image img = null;
    try
    img = Toolkit.getDefaultToolkit().getImage(getClass().getResource(fileName));
    catch (Exception e) { }
    In this case make sure that you have image at the same location where you access it. For example if you have to access an image in package class com.awt.ui.MyClass then your image should also be at location ..\com\awt\ui
    Note: It will require image duplicacy in your JAR but it solves the problem. It gives the advantage of fewer download from server.
    Answer to Question 2:
    ~~~~~~~~~~~~~~~~~~~~~
    IE treats applet as an active-X and try to look for these classes in your JAR. SUN has stopped its support in JDK1.3.1 and plus. What one can do is to create dummy classes with these names and bundle it with your JAR. You have to create these dummy classes if you enable Basic authentication on your web server then browser will try to look for these classes on the server and continue to prompt you for login and password. It might bother your customer un-necessarily to enter login and password too many times prompted by plug-in (plug in).
    --Ratan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • About images on applet

    Hi im creating an awt applet and i want to know theese 2 things
    1-)how can i make an image as a background image?
    2-)how can i use an image regularly(i mean giving its coordinate).
    Thanks

    I tried something like that but it didnt work
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.io.*;
    import java.awt.image.*;
    public class applet extends java.applet.Applet {
        private Image background;
        private ImageObserver obs;
        public void init()
            background = getImage(getCodeBase(),"background.jpg");
        public void paint(Graphics g)
            g.drawImage(background,10,10,400,400,obs);
    }this was what i found on google if there is any other way i would be appreciated if you share it with me?

  • Identifying "Warning! Applet window"

    Hi,
    I have some swing components called from awt applet( java 1.1).I have signed the jar and if the user has not imported the key it is showing me the "Warning! Applet window".Is there anyway I can identify in my code that user has not imported the key so that I can convey the user properly..
    Thanking you,

    .

  • Compiling Java Applets

    Hi!
    I've had some trouble running Java Applets on my server. After some debugging I have found that it maters how and/or where they are compiled.
    I have taken a simple HelloWorldApplet and compiled on my server. Then when I try to access it from a client computer all I get is a grey box with no error message.
    I then found an applet at the Java home page where it was possible to download the .CLASS file. When I copied this file to my server it works just fine.
    So my question is: Should not a simple applet work, just because it's compiled with the latest Java Edition??
    The thing is though, when I check the box under Tools > Internet Options > Advanced, Use Java 2 v1.4.1 for <applet> every applet work just fine. But shoulden't a simple Java Applet run without this option?
    I run a MS IIS5 server and use MS IE as a browser.
    Please help me.
    /Fredrik

    Should not a simple applet work, just because it's compiled with the latest Java Edition??Don't need to compile/recompile using the latest JDK since each version is fully compatible with old versions but for advanced ones must to use "target" parameter. As example, if one applet is using regular expression API, formerly Regex API, must to compile this way:
    javac -target 1.4 yourSource.java .
    For simple applets as mentioned in your post, formerly AWT applets, don't need special care, they will work fine in any JVM, any browser any platform since this is the most primitive JVM (1.1) but in some OS the vendor supressed JVM..M$, so you must to use Java plug-in. It just supplies a Java virtual machine to run your applets/applications and in this sense becames the "native" VM. This is the better choice at all that warrants the best performance among VM's.
    At this moment you can be sure your OS was deployed without Java support of course and there aren't server constraints (applets run in client side) so maintain Sun's JVM as default and there will be no presentation faults. Moreover M$ JVM has a dangerous security bug and also is obsolete version.
    Regards.

  • Linking HTML pages from shapes in a java Applet

    I have defined MouseEvents to some shapes in a ShapesPanel. When the user presses the mousebutton on those shapes, I want the user to be redirected to a HTML page. Is this possible?
    In HTML the linking code to another page is <a href..>
    What is the code in an applet?
    Here is some sample code:
    public void mousePressed(MouseEvent e)
         // System.out.println("MousePressed");
         if (rect1.contains(e.getX(),e.getY()) )
         System.out.println("MousePressed inside rect1");
         if (rect2.contains(e.getX(),e.getY()) )
         System.out.println("MousePressed inside rect2 ");

    I'm not an expert but got this from the java API javadocs.
    method in class java.awt.Applet.
    getAppletContext().showDocument(....)

  • Error when connecting Applet to EJB

    Hi,
    I have an Applet that I try to connect to an EJB, but without success.
    To pinpoint the problem, I took the client-side code of the example ...examples\ejb\basic\BeanManaged
    and made an AWT Applet out of it.
    I seem to trap some error when I call the getInitialContext() when trying to find the Home interface.
    Nothing happens in my code (ie. the Applet) after I enter this part of the code. It is a it hard to say
    where it stops, since I do not get all output. It seems to die when I am trying to instantiate the
    Context-object or the AccountHome object. Maybe I just have a Classpath error.
    When running the BeanManaged as a Java Application, everything is working fine.
    Does anyone have any experience in these matters ?
    I am using WL 5.1.0 (no SP-s), JDK 1.2.2
    Regards, Erik

    Thanks for you answer Jos, but honestly I don't know what I should do then, since I can't get data from database through the applet.
    I have read some articles that we can get data from database through the applet (they use tomcat too). I have followed what the article said, but I still get the error.
    Do you have any idea Jos? Thank you very much for your nice attention
    Warmnest regards,
    Vijay

  • Hard awt problem.

    Introduction:
    An applet opens a modal java.awt.Dialog. The dialog contains a grid for displaying data. When the dialog is opened a separate thread is fetching data from the server. When the data arrives it is displayed in the grid in the dialog. The grid adds a scrollbar to itself whenever required (if the number of rows to be displayed is greater than the number of rows that fit inside the visible part of the grid).
    The code for adding/ removing the scrollbar is in the doLayout() method of the Grid.
    Problem:
    When I call invalidate() or validate() on the grid in the modal dialog the call hangs until the modal dialog returns from it�s setVisible() method. Why ???! It seems to be impossible to trigger a refresh of the layout of the grid programmatically. If I do not refresh the layout the scrollbar will only get added if I resize the window or in any other way make the system trigger a refresh of the layout. When I use the same Grid in any Container that is not a modal dialog there is no problem at all.
    What is the reason for this behavior, and how do I solve the problem?
    Ragnvald

    Thanks Luke, but that doesn�t work for me.
    This is an awt- applet, supposed to run on IE without signing or any additional downloading. That implies java 1.1.8 only. awt and no swing. And all the security restrictions apply as well.
    There must be a workaround!!!!
    The swing you provided has it�s equivalent in awt://1.1.8:
    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event);
    //and 1.2:
    Toolkit.getEventQueue().postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));The problem is the applet restriction. I get an exception:
    SecurityException at getSystemEventQueue
    There has got to be another solution!
    Ragnvald.

Maybe you are looking for