Applet Swing question

It's been a couple of years since I wrote any code in Java and I've hit a snag that I can't seem to solve.
The application will be an applet with a swing GUI. I need to pop up a modal log in dialog before the user can do anything. The problem is I can't seem to find a way to have a legal parent argument for the JDialog constructor. My choices seem to be a Frame, Dialog or Window objects which seem to map directly to JFrame, JDialog and JWindow. The problem is my applet doesn't have any of those and I seem to be having some issues adding any of them to the applet. Am I missing something or what?

The application will be an applet with a swing GUI.I hope that's a JApplet.
The problem is I can't seem to find a way to have a legal parent argument for the JDialog constructor.I don't do applets, but have you tried with a null argument? You'll need to cast the null to any of Dialog, Frame or window to disambiguation.
luck, db

Similar Messages

  • Applet / Swing - I'm new in applets

    Hi,
    I need to program applet project, but I know only swing.
    Am I have to lern about applet before, or start to create a swing program and then to change to a applet ?
    what is the difference between Applet / Swing?
    What I have to change in the my swing program to be Applet?
    the connecting is same to the database? (JDBC)
    Thanks.

    Jar file is made when you are creating a desktop application.
    it is like setup file which extract the more than one class file
    but in webapplication u need to store class files in webserver and have to create html file
    <applet code="file.class" width=300 height=300>
    </applet>
    no need to create jar file for web application and applet is used to create webapplicaton

  • Easy swing question for Java friends

    Hi could somebody test this short application and tell me why the "DRAW LINE" button doesnt draw a line as I expected?
    thank you very much!
    Circuitos.java:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.URL;
    import java.awt.geom.*;
    public class Circuitos extends JApplet {
         protected JButton btnRect;
         protected Terreno terreno;
         private boolean inAnApplet = true;
         //Hack to avoid ugly message about system event access check.
         public Circuitos() {
              this(true);
         public Circuitos(boolean inAnApplet) {
            this.inAnApplet = inAnApplet;
              if (inAnApplet) {
                   getRootPane().putClientProperty("defeatSystemEventQueueCheck",Boolean.TRUE);
         public void init() {
              setContentPane(makeContentPane());
         public Container makeContentPane() {
              btnRect = new JButton("DRAW LINE");
          btnRect.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                terreno.pintarTramo();
              terreno = new Terreno();
              JPanel panel = new JPanel();
              panel.setLayout(new BorderLayout());
              panel.add("North",btnRect);
              panel.add("Center",terreno);
              return panel;
         public static void main(String[] args) {
            JFrame frame = new JFrame("Dise�o de Circuitos");
              frame.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
              Circuitos applet = new Circuitos(false);
              frame.setContentPane(applet.makeContentPane());
              frame.pack();
              frame.setVisible(true);
    }Terreno.java:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.geom.*;
    public class Terreno extends JPanel {
         Graphics2D g2;
         public Terreno() {
              setBackground(Color.red);
              setPreferredSize(new Dimension(500,500));
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
          g2 = (Graphics2D) g;
          g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);    
         public void pintarTramo () {     
              Point2D.Double start   = new Point2D.Double(250,250);
              Point2D.Double end     = new Point2D.Double(250,285);
              g2.draw(new Line2D.Double(start,end));            
    }

    I don't think the date I became a member has anything to do with it. Yes, I signed up a year ago to ask a question or two when I didn't know anything. It wasn't until recently have I started to use this forum again, only to try and help people as well as ask my questions. It took me a year to get to this point to where I can actually answer questions instead of just asking. So don't be silly and judge a person based on their profile.
    Secondly, I agree with you, the search utility is great. I use it all the time and usually I'll find my answers, but if I don't is it such a pain in the butt for you to see the same problem posted again?? I know how much you want people to use the resources available before wasting forum space with duplicate questions, but it's not going to happen. Some people are not as patient and you being a butt about it won't stop it.
    My point in general is that there are nice ways to help people and even rude ways, and your comments at times come across rude to me, even condescending. You have a lot of knowledge, therefore certain things seem trivial to you... but try to understand where some of the new people are coming from. The Swing tutorial is extremely helpful but if you don't understand the concept of programming or java that well... then it can be overwhelming and you don't know where to start. It's a huge tutorial and when people are stuck they just want an answer to their one question. Most figure it's easier to ask someone who already knows instead of reading an entire tutorial to get their answer.
    I've learned by both methods, by taking the time to research it myself and by asking a lot of questions. I have the time. Some don't. Please realize that not everyone is like you and they will continue to ask whether you like it or not. You have a choice, either help them or not.

  • Applet interaction questions

    Howdy.
    I'm generating a map in an applet using a library based on swing classes.
    I need to be able to:
    -- query the db on the host server from within the applet to alter the map;
    -- save a snapshot of the map to the server (I've got code that saves a snapshot, but I need to be able to save that on the host server);
    -- if possible, receive messages from javascript controls on the browser page where the applet resides, and respond to them.
    It seems like I may need to sign the applet, but I'm not trying to do anything on the client machine; just to interact with the host server.
    Can someone point me in the right direction? I've been out of the java world for a bit, so all the details are slow coming back...
    Thanks much.

    Hi,
    I have some questions regarding to the
    HttpURLConnection implementation used in Applet.
    1. Is the connection made when I do
    URL.openConnection or when I flush/close the
    OutputStream?The local resources are taken when the openCOnnection is called. The request is made to the server when the getInputStream getContent getResponseCode or the one of the other input methods is called.
    2. Will the binaray data in content be chunked if I
    set the Content-Type to application/octet-stream
    along with Content-Length?Don't know.
    >
    3. After the OutputStream been closed can I still use
    the Connection for read?Yup (note you will have to do this to actually send the request to the server...)
    >
    4. Is it possible for me to lose any data in the Http
    request I send through the HttpURLConnection?Not sure, but my thought has always been any data sent across HTTP can be lost en route. There will be some effort from the server to recover lost packets, but I do not know the details...
    >
    Thanks,
    Michael

  • Basic swing question

    I just started looking at swing yesterday because I want to provide a GUI to replace a command line utility we use. I've basically finished it but have a quick question about form - I will get some literature later but would like to get a feel from the people here. If you have a JFrame with a few JPanels each which contain some other components, what is the best practice for variable declaration? Should I just declare the variables locally or should I make them instance variables? The reason I ask is that I have a button that submits a message but that message is dependant on check boxes, etc. from from the frame. If I declare them at the method level I then have to start passing them around whereas if I declare them as instance variables I can access them very easily BUT this may not be good form.
    For example:
    my class is SendMessageToo so in the main method I have a line like:
    final SendMessageToo smt = new SendMessageToo();
    now all the instance variables that I have can be accessed my the methods simply using smt.methodOne(), etc. Does that seem OK or is it just pure crap? :-)

    Thanks, that was something that crossed my mind before I just made eveything an instance variable. It was during that process that I thought, do these all need to be instance variables? Then I thought, SHOULD they all be instance variables. At that point my brain imploded so I came here. :)

  • Simple applet jar question

    I'm sure this is an easy question, but how do you access subdirectories in your applet's jar file?
    For instance the contents of MyApplet.jar jar would be:
    * META-INF
    * images
    * net
    Say the main class is MyApplet.class in net/mydomain/myproject
    How in the main class would I get at images/MyImage.jpg?
    Obviously I did not get this code to work:
    ImageIcon upIcon = new ImageIcon("images/MyImage.jpg");
    Thanks alot!

    Actually now I am using:
    ImageIcon upIcon = new ImageIcon(MyApplet.class.getResource("/images/MyImage.jpg"));
    This way the 'absolute' resource is found (becuase the resource name starts with a '/').
    This seems to be the best way to do it.

  • 2 swing questions: JScrollPane and displaying pictures

    I'm building a GUI for a toy application I have written, I have two questions:
    1-The main window is inherited from JFrame, There is a JTabbedPane attached to it, and a JPanel as the first tab of the tabbed pane. There are so many jcomponents in this JPanel, this makes it too big for small resolution computers (below 1024 * 768), I would like to add this JPanel to a JScrollPane to make it behave like a text area, I've done it but it didn't work, obviously there is something I'm missing.
    2-My application calls another program to create some images at runtime which will be displayed in the other tabs, after calling the program and creating the image, I get the filename of the image. What is the best way to display this image?
    I have tried JLabel's but they don't update their pictures for some reason after it has been changed.
    Thanx in advance.

    Updated and tested code, hopefully this will help.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    public class ImagePanel extends JPanel {
      private String imageFilename = null;
      private Image image = null;
      private Toolkit toolkit = null;
      public ImagePanel() {
        super();
        toolkit = Toolkit.getDefaultToolkit();
      public void setImageFilename(String filename) {
        imageFilename = filename;
        try {
          image = toolkit.createImage(imageFilename);
          setPreferredSize(new Dimension(image.getWidth(this), image.getHeight(this)));
          repaint();
        } catch (Exception e) {
          e.printStackTrace();
          imageFilename = null;
          image = null;
      public Dimension getPreferredSize() {
           if (image == null) return new Dimension(0, 0);
           else return new Dimension(image.getWidth(this), image.getHeight(this));
      protected void paintComponent(Graphics g) {
           Insets insets = getInsets();
           g.setColor(Color.white);
           g.fillRect(0,0, insets.left + getWidth(), insets.top + getHeight());
        if (image != null) {
          g.drawImage(image, insets.top, insets.left, this);
      public void reloadImage() {
           if (imageFilename != null) {
          try {
            image = toolkit.createImage(imageFilename);
            repaint();
          } catch (Exception e) {
            imageFilename = null;
            image = null;
      public static void main(String args[]) {
           JFrame frame = new JFrame();
           frame.addWindowListener(
                new WindowAdapter() {
                     public void windowClosing(WindowEvent we) {
                          System.exit(0);     
           frame.setSize(600, 400);
           JPanel parentPanel = new JPanel();
           parentPanel.setLayout(new GridLayout(1,1));
           JTabbedPane tabPane = new JTabbedPane();
           ImagePanel imagePanel = new ImagePanel();
           JScrollPane scrollPane = new JScrollPane(imagePanel);
           imagePanel.setImageFilename("C:\\dell\\drivers\\R27748\\mrmfiles\\image015.jpg");
           parentPanel.add(scrollPane);
           tabPane.addTab("Tab 1", parentPanel);
           frame.getContentPane().add(tabPane);
           frame.show();
    }

  • Applet installation question

    I am trying to install an applet using a non default
    applet AID. I am using the:
    register(buffer, aid_offset, length);
    Questions:
    Is the java card OS made so you can istall a base applet (package and applet download). Then later install
    more applets with just an applet create apdu command sent to the applet manger?
    [Applet package mask]
    [Applet1] (register())
    [Applet2] installed using above register function
    Constuctor for test applet:
    private TesApplet(byte buffer[],short offset,byte length) {
    if (buffer[offset] == (byte)0) {
    register();
    }else {
         register(buffer, (short)(offset+1) ,
    (byte)(buffer [offset]));
    } // end of the constructor

    In order to answer the original question:
    Yes, you can load a package and install several applets from it which means to create and register applet instances based on one or more applet classes in the package.
    Each applet instance needs a unique AID. If you do not provide AID data to the register method the applet class AID is used. Therefore you can only use the "register()" call once. But your code shows that you got that point already.

  • Applet viewer question

    Well here is my first question of what promises to be many. Nice to meet you all. Here goes:
    While doing the first applet in "Your first cup of Java", I run the applet by typing:
    appletviewer Hello.html
    The applet runs in the applet viewer and looks just like the picure says it should. But I also get this warning in the command prompt:
    Warning: Can't read AppletViewer properties file: C:\WINNT\Profiles\PURCHASER\.h
    otjava\properties Using defaults.
    Anybody know what the problem is there?
    Thanks.

    I wouldn't worry about it, I get the same errors using the computers at Uni. It's never stopped me anyway. I'm not sure what causes it, something to do with WinNT/2000 and profiles/users.
    Cheers,
    Radish21

  • Applet size question

    <applet code="file.class" height=400 width=300>
    </applet>
    This is my html file related to a generic "file.java".
    If I wanted that size to remain unaltered while the applet is running (basically if I want to fix the height and width of the applet, so that once it is displayed I cannot resize the window), I guess there is an instruction to handle this... Is there?
    Tnx

    The Java applet is an embedded object in your HTML page. This means that Java does not have direct controll over the browser window. In other words: there's no easy way to make Java stop people from resizing the browser window. There are two solutions for your 'problem'.
    You could make your applet pop up a Java window (either AWT or Swing). Java has full controll over its own windows, so that will allow you to allow and disallow users any particular action. The downside is that -especially when using Swing- this is going to increase the filesize of your applet (and when using Swing, you also need to make sure visitors have the Swing libraries).
    The other solution is making JavaScript pop up a child browser window in which you load the HTML page containing your applet. You can make JavaScript prevent people from resizing the child window.

  • Are there any Applet/Swing Case Studies

    We're trying to decide whether to change our company's OLTP product's UI from being HTML/JavaScript to Swing (applet or use Web Start for web based app). Is there anyone that uses Swing for their entire front end for a product that is accessed over the internet (not an intranet).
    Is development slower for Swing than HTML/JS; is app start-up and jar download too slow; are there proxy issues that are difficult to overcome? I'd appreciate any input that would help in this decision.
    Thanks,
    John

    We can incorporate Swings in Web Applications using Applets i.e Servlets /JSP.
    The pros are the Applets which are swing based download for the first time to the client side. If the user made any changes to these changes only those pages which are changed will be download which are cached.
    Concerns:
    If the cache is not updating properly once the applets are stored then the updations will not reflect in the web-page.
    Sufficient memory should be allocated for the Java - Cache memory.
    To overcome this drawbacks we can use JSF which is serve side component level scripting.
    -- Swaroop

  • Concurrency/Swing question

    This question feels like it should be simple but i am stuck - tried to search for the answer/explanation but just get even more stuck ( i am a newbi):
    Have a class that creates a object of another class that implements a javax.swing.JFrame. What i want to do is suspend the creating object while the use works with the form. When the user clicks a button in the form the waiting object should be awaken and able too access the data from the form. I.E.
    ��public class Ui extends javax.swing.JFrame {
         logic calling;
         public Ui(logic my){
              calling = my;
         private void ButtonMouseClicked(java.awt.event.MouseEvent evt){
              my.notify();
    public class logic implements Runnable {
    public void logic(){
         Ui a = new Ui();
         try{
              wait();
         catch(InterruptedException e){
         // Collect data from Ui object a
    }Maybe this post should be made to swing forum instead
    Any help will be greatly appreciated

    No that's not what I am looking for.
    What I want is a way for a swing object (JFrame) to be able too alert (after receiving a user action)��the thread that created it, that there is data in the graphics object to be fetched. ( While the user is playing with the graphics object (Ui) the creating thread (logic) is waiting - too not waste CPU cycles ). That is alerting a thread from a method that runs on a EventDispatchThread.

  • Four Java Applet signing questions

    hi all;
    I'd like to ask a few quick questions about applet signing. As you know there is a "Security Warning" Gray Alert box that appears when the user tries to load your signed applet.
    1. When the alert window asks someone to accept the signed applet, is it possible to some how capture the Yes or No button click event by javascript or something like that ? I noticed that the Yes and No Response seems to be saved in an in-memory cookie? Is it possible to figure out wht the person clicked ?
    2. Is it possible to keep that "Security Warning" Alert box on top so that the user will not be able to accidentally ignore it (it goes under the browser and stays there).
    3. Is there some way to inspect the PC to determine weather your applet loaded properly - apart from seeing a properly working applet ? For example , If I want to make sure it is being cached properly.
    4. When a new version of the applet is available on the server ? how does the browser know to download something ? is that something I would code for manually or would is this automatically handled behind the scenes.
    Thanks in advance
    Stephen

    I can only reply to nr 1 but looking at java.security.AccessControl there is a method called checkPermission() you can use.

  • Applet/Swing user inactivity detection

    Hello,
    I need some advise on the issue, of detecting user inactivity on my applet.
    My current scenario is, my applet is hosted from a jsp page on the client machine, the applet contains a lot swing components (many jframes).
    I want to somehow detect the user inactivity on that page hosting the applet.
    Say for example if the user doesnt perform any action (like a mouse click) on the main applet or any of the child jframes spawned from it, for say 15 mins. I want to close the applet and the jframe saying Session Timeout.
    Or other than this is there any way for applet to deal with session parameters to perform the timeouts, when no user activity takes place, on the JSP holding the applet.
    Hope i am clear enough in my scenario.
    Please advise.
    Thanks,

    >
    I need some advise on the issue, of detecting user inactivity on my applet. >Why are you deploying an applet, rather than a webstart based application? I ask this especially since...
    >
    My current scenario is, my applet is hosted from a jsp page on the client machine, the applet contains a lot swing components (many jframes). >The entire app. sounds as though it is more based around free floating JFrames anyway.
    I want to somehow detect the user inactivity on that page hosting the applet. Forget 'the page', since this can all be done within the applet or 'main GUI component' (should you decide to convert it to a JFrame).
    The basic way outlined by the other tqwo responders would be the way to approach it. You app. needs to
    a) Detect activity, and note the time.
    b) Keep a timer running to check if the lastActivityTime has reached the limit, then..
    c) Here we come to a bit of a tricky part... It is easy to detect 'activity' on a button or menu item that causes an event. You might put the code to handle the update of the timer into the event handler, but consider a JTextArea. An app. has a slew of buttons anf menu items, plus a number of JTextArea's for entering 'details'. Normally a JTextArea would not have an actionlistener, and would often not have any special handling on the KeyListener, so to avoid having to put a listener on every conceivable component that might hava 'activity', I suggest that at the end of the '15 minutes' you pop a modal JDialog itself with a 15 second 'you are about to be logged out' warning - and force the user to dismiss it in order not to be logged out.
    d) When the user is logged out, you might indicate that by either removing all the components and replacing them with a message, or simply disabling all controls but the 'x' button (or something along those lines).
    For the 'timer', there are a number of classes which might be used, from creating your own class that implements Runnable, through using a Swing based Timer to run the separate 'logout check' thread.

  • Applet persistance question (basic?)

    All:
    Forgive the ignorance, but I am not a Java programmer at all... but am looking for some info.
    What is the scope of a (untrusted) java applet in regards to IE browser sessions? For instance, if a web page initiates an applet load, does the applet stay in memory and continue to run after the user navigates away from the original page?
    We are trying to find out if it is possible for a page to load a particular applet that records the URL string of IE browser windows, and have this applet persist throughout the user's browser session, even if they leave the original page, and if they open new browser windows. Is this possible, or is it just crazy?
    Thanks for any help!
    phong

    We are trying to find out if it is possible for a page
    to load a particular applet that records the URL
    string of IE browser windows, and have this applet
    persist throughout the user's browser session, even if
    they leave the original page, and if they open new
    browser windows. Is this possible, or is it just
    crazy?And then make the user crazy trying to download anti spyware and adware and stuff. The question is why do you want the applet to be running once the user has left the page and would you ask for his permission to do so. Just as there is a law for the telemarketing guys there should be another one for these spyware guys who want to run there own agenda on the clients machine without his concent.

Maybe you are looking for

  • My aperture library won't open - it's stored on an external R6 pegasus drive?

    Have been through the various other threads and followed most of the ideas - repair disk permissions, plist delete, rebuild database. The application works ok and when it is not trying to access the library stored on the pegasus it works fine - I gue

  • InDesign CS6 crashing when exporting as a PDF (not font problem)

    I have attempted exporting my PDF with all different kinds of settings. It's only an 8 page document. It has about 15 low res jpgs in it. I used a stock Adobe font.There are a several hyperlinks in the file but, mostly it is just text. I have no idea

  • Where on your site can I find out the history of Firefox versions, when they became available for upgrade/upload?

    A custom application within our company used to work using Firefox however in July we were alerted that the application was not working properly when combined with Firefox. I would like to know when you updated your versions of Firefox starting with

  • Filtering by file size

    Hi, I was *so* hoping that we'd finally be able to filter (or create a Smart Collection) based upon file size. There are many reasons why this would be useful but the thing that trips me up every once in a while is that I'll forget to flatten my laye

  • Translate in vc

    hallow i have a function module where it bring me a table with data . in the rfc i used a translate(like text-003) and it work in r3 well (i try it when  i logon  the same langu that i translate it translate it well in rfc i check it) my problem is w