4 Replies Latest reply: Dec 29, 2011 9:27 AM by 881879 RSS

    How to pass a value from a JApplet to a JDialog?

    881879
      Hello, I'm having problems with sending a value from a JApplet so I can use it on a JDialog, I'm doing it in this way:

      JApplet:

      *public JComponent makeTextPanel(ImageIcon img, ImageIcon img2, final int width1, final int height1, final int width2, final int height2, final String pageId_1, final String pageId_2) {*
      JPanel panel = new JPanel(false);
      JLabel filler = new JLabel();
      filler.setIcon(img);

      Border border = BorderFactory.createLineBorder(Color.DARK_GRAY);
      filler.setBorder(border);

      filler.setSize(width1, height1);
      filler.setBounds(panel.getWidth()/2, panel.getHeight(), width1, height1);

      filler.setHorizontalAlignment(JLabel.CENTER);

      *filler.addMouseListener(new java.awt.event.MouseAdapter() {*
      *@Override*
      *public void mouseClicked(java.awt.event.MouseEvent evt){*
      rotation_component jd1 = new rotation_component((JFrame)test.getParent(), true);
      jd1.setPageCode(pageId_1);
      jd1.setSize(width1, height1);
      jd1.setVisible(true);
      *}*
      *});*

      panel.setLayout(new GridLayout(1, 2));

      panel.add(filler);

      return panel;
      *}*

      JDialog:

      public String pageCode = "";

      *public String getPageCode() {*
      return pageCode;
      *}*

      *public void setPageCode(String pageCode) {*
      this.pageCode = pageCode;
      *}*

      I'm creating dynamic TabbedPanes, and by using this method, I'm sending all the parameters to create it, this part works fine, but here:

      rotation_component jd1 = new rotation_component((JFrame)test.getParent(), true);
      jd1.setPageCode(pageId_1);

      I'm creating an instance of my JDialog (rotation_component) and then applying the String passed as parameter in the method, into the setPageCode() on JDialog, but it returns blank, I don't know what else to do, I can't call the pageId_1 from the declaration variable because it's an String Array and I'm only passing the one I need here, any advice would be appreciated ,thanks!!

      Edited by: saman0suke on 28-dic-2011 14:34

      Edited by: saman0suke on 28-dic-2011 14:35

      Edited by: saman0suke on 28-dic-2011 14:35
        • 1. Re: How to pass a value from a JApplet to a JDialog?
          Jörg
          Hello,

          1. Please surround any posted code by code tags ({ code } without blanks) for better readability.
          2. I can see nothing wrong in your passing parameter pageId_1. As it is returned blank (by getPageCode() I suppose), I would check whether it is not already blank in makeTextPanel(...) and whether it is "visible" in mouseClicked(...).
          3. If these checks are ok, I think there is a good chance that you find the error while preparing an SSCCE. If not, please post it.
          • 2. Re: How to pass a value from a JApplet to a JDialog?
            881879
            Well, I did make sure that I was receiving the code, so I created a JPane to be displayed right at the click of the element, and It did show me the correct value, something I've noticed, If I try to send a parameter into the method makeTextPanel to the JDialog, does not work, but If I take a public variable declared right at the top, It can receive the value, but I can not see a reason why I can't receive a value sent as a parameter into the MouseListener, any idea? I will check the code again, but right now, I'm out of ideas, thanks!

            EDIT: Did not know about the code tag, sorry.

            Edited by: saman0suke on 28-dic-2011 20:35
            • 3. Re: How to pass a value from a JApplet to a JDialog?
              Jörg
              No need to feel sorry if it is the first time, but the permanent posts at the top of the thread list are there for a purpose.
              Also, it would be nice to mark questions as "answered" once you found or were given a solution.
              For the rest refer to point 3 of my previous post.
              • 4. Re: How to pass a value from a JApplet to a JDialog?
                881879
                I finally was able to do it, I declared a public static String on JApplet (Let's say JFrame1) and at the moment of creation o each individual JComponent I assigned to it the value that I passed as a parameter, then on the JDialog I instantiated JFrame1 and assigned value from public static one to a public String on JDialog Form, so I was able to retrieve the value, I guess the trick resides on declaring the variable as STATIC, however, I don't know why it did not work just as PUBLIC, thanks anyway :D