An Experiment using Swings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crossroadsk
    New Member
    • Nov 2006
    • 30

    An Experiment using Swings

    I have implemented the following code :
    -----------------------------------------------------------------------------------------------------------------
    import javax.swing.*;
    import java.awt.*;

    public class FileChooseDemo{
    public static void main(String args[])
    {
    JFileChooser chooser = new JFileChooser();
    chooser.showOpe nDialog(new JFrame());
    }
    }
    ------------------------------------------------------------------------------------------------------------------
    But my problem is that i want to implement the same with help of an applet so that i can use it in a browser , can anyone help me solve that and i've already written some code but it is not working........ ...check this modified code below:

    import javax.swing.*;
    import java.awt.*;

    public class FileChooseDemo extends JApplet{

    public void init(){
    JFileChooser chooser = new JFileChooser();
    chooser.showOpe nDialog(new JFrame());
    }

    public static void main(String args[])
    {
    javax.swing.Swi ngUtilities.inv okeLater(new Runnable() {
    public void run() {
    init();
    }
    });
    }
    }

    }

    /* <applet code="FileChoos eDemo.class" height=400 width=400></applet>*/

    help me please!
    Last edited by crossroadsk; Nov 8 '06, 07:38 AM. Reason: code modification
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by crossroadsk
    I have implemented the following code :
    -----------------------------------------------------------------------------------------------------------------
    import javax.swing.*;
    import java.awt.*;

    public class FileChooseDemo{
    public static void main(String args[])
    {
    JFileChooser chooser = new JFileChooser();
    chooser.showOpe nDialog(new JFrame());
    }
    }
    ------------------------------------------------------------------------------------------------------------------
    But my problem is that i want to implement the same with help of an applet so that i can use it in a browser , can anyone help me solve that and i've already written some code but it is not working........ ...check this modified code below:

    import javax.swing.*;
    import java.awt.*;

    public class FileChooseDemo extends JApplet{

    public void init(){
    JFileChooser chooser = new JFileChooser();
    chooser.showOpe nDialog(new JFrame());
    }

    public static void main(String args[])
    {
    javax.swing.Swi ngUtilities.inv okeLater(new Runnable() {
    public void run() {
    init();
    }
    });
    }
    }

    }

    /* <applet code="FileChoos eDemo.class" height=400 width=400></applet>*/

    help me please!
    What do you mean it is not working. You need to be more clear. While you are at it, you might want to look at applets and security.

    Comment

    • crossroadsk
      New Member
      • Nov 2006
      • 30

      #3
      Originally posted by r035198x
      What do you mean it is not working. You need to be more clear. While you are at it, you might want to look at applets and security.
      I mean will it work with an applet or not?

      First of all i want to clarify whether we could implement "JFileChoos er" with applet or not?

      Second ,if yes then how to implement that ?

      Do my code make any sense ?

      Comment

      • crossroadsk
        New Member
        • Nov 2006
        • 30

        #4
        Problem solved but there is another problem......

        the code in applet is not executing on my machine ... but it's fine on my colleagues machine .....

        i'm using jdk1.4.1 and the other machine is running jdk1.6.0

        the modified code is like this

        import javax.swing.*;
        import java.awt.*;
        import java.applet.*;
        import java.awt.event. *;
        import javax.swing.fil echooser.*;
        public class FileChooseDemo extends JApplet implements ActionListener
        {
        //JPanel p;
        JButton b1;
        JFileChooser chooser;
        public void init(){

        b1 = new JButton("vachay ");
        add(b1);
        b1.addActionLis tener(this);
        }

        public void actionPerformed (ActionEvent ae)
        {
        chooser = new JFileChooser();
        if(ae.getSource ().equals(b1))
        {
        chooser.showOpe nDialog(FileCho oseDemo.this);
        }
        }
        }



        /* <applet code="FileChoos eDemo.class" height=400 width=400></applet>*/

        can u explain what could be the problem?

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by crossroadsk
          Problem solved but there is another problem......

          the code in applet is not executing on my machine ... but it's fine on my colleagues machine .....

          i'm using jdk1.4.1 and the other machine is running jdk1.6.0

          the modified code is like this

          import javax.swing.*;
          import java.awt.*;
          import java.applet.*;
          import java.awt.event. *;
          import javax.swing.fil echooser.*;
          public class FileChooseDemo extends JApplet implements ActionListener
          {
          //JPanel p;
          JButton b1;
          JFileChooser chooser;
          public void init(){

          b1 = new JButton("vachay ");
          add(b1);
          b1.addActionLis tener(this);
          }

          public void actionPerformed (ActionEvent ae)
          {
          chooser = new JFileChooser();
          if(ae.getSource ().equals(b1))
          {
          chooser.showOpe nDialog(FileCho oseDemo.this);
          }
          }
          }



          /* <applet code="FileChoos eDemo.class" height=400 width=400></applet>*/

          can u explain what could be the problem?
          When adding things to JFrames or Applets in 1.4, you use
          getContentPane( ).add(item);
          instead of just add

          Comment

          • crossroadsk
            New Member
            • Nov 2006
            • 30

            #6
            i already did that and after that i'm not able to handle event .. i.e., when i click the button

            Comment

            Working...