#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Passing a variable


    Would someone please tell me the error of my ways ?


    I am successfully passing a variable from one class to another. BUT when I attempt to access that PUBLIC variable, I am receiving a null. The fact that I am returning a null makes no sense to me.

    The following code returns eventIcon1 successfully.
    Code:
    public class JFrame4 extends javax.swing.JFrame {
    
       // String eventIcon1;
       public String eventIcon1; // = "firedept.png";
        Insets ins = getInsets();
    
        /** Creates new form JFrame4 */
        public JFrame4() {
                    initComponents();
    
        }
    
        public JFrame4 (String theEventIcon) {
            String eventIcon1 = theEventIcon;
            System.out.println("The eventIcon passed into JFrame4 is " + theEventIcon
                    + " And this is given to this eventIcon as " + eventIcon1);
        }

    This bit of code does not.

    Code:
      public void update (Graphics g) {
            paint(g);
        }
    
        public void paint (Graphics g) {
            super.paint(g);
            Toolkit tool = Toolkit.getDefaultToolkit();
            Image img = tool.getImage(eventIcon1);
            System.out.println("The eventIcon in JFrame4 is: " + eventIcon1);
            //g.drawString("ice", 450, 450);
    //        if (img != null) {
            
            g.drawImage(img, 350, 190, this);
        }
    The output:
    Code:
    The eventIcon passed into JFrame4 is firedept.png And this is given to this eventIcon as firedept.png
    The eventIcon passed to JFrame4 is : firedept.png
    The eventIcon in JFrame4 is: null
    The eventIcon in JFrame4 is: null


    Any insight would be appreciated.

    Thanks,

    DaneCom
  2. #2
  3. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    380
    By declaring eventIcon1 again inside your constructor as a local variable, you are effectively shadowing the instance variable eventIcon1. So there is never any value assigned to the instance (public) variable eventIcon1.
    If you change it to:
    java Code:
        public JFrame4 (String theEventIcon) {
            eventIcon1 = theEventIcon;
            ...
    by simply removing the "String" bit it should work.

    I suggest some Googling on variable scope in java

    Comments on this post

    • generatedname agrees
    • danecom agrees
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0
    Originally Posted by wsa1971
    By declaring eventIcon1 again inside your constructor as a local variable, you are effectively shadowing the instance variable eventIcon1. So there is never any value assigned to the instance (public) variable eventIcon1.
    If you change it to:
    java Code:
        public JFrame4 (String theEventIcon) {
            eventIcon1 = theEventIcon;
            ...
    by simply removing the "String" bit it should work.

    I suggest some Googling on variable scope in java
    That makes sense.

    Unfortunately, that did not correct the issue.
    Code:
    public class JFrame4 extends javax.swing.JFrame {
    
       // String eventIcon1;
        public String eventIcon1; // = "firedept.png";
        Insets ins = getInsets();
    
        /** Creates new form JFrame4 */
        public JFrame4() {
                    initComponents();
    
        }
    
        public JFrame4 (String theEventIcon) {
            eventIcon1 = theEventIcon;
            System.out.println("The eventIcon passed into JFrame4 is " + theEventIcon
                    + " And this is given to this eventIcon as " + eventIcon1);
        }

    Code:
    public void update (Graphics g) {
            paint(g);
        }
    
        public void paint (Graphics g) {
            super.paint(g);
            Toolkit tool = Toolkit.getDefaultToolkit();
            Image img = tool.getImage(eventIcon1);
            System.out.println("The eventIcon in JFrame4 is: " + eventIcon1);
            //g.drawString("ice", 450, 450);
    //        if (img != null) {
            
            g.drawImage(img, 350, 190, this);
        }
    The output:

    Code:
    The eventIcon passed into JFrame4 is hailsm.png And this is given to this eventIcon as hailsm.png
    The eventIcon passed to JFrame4 is : hailsm.png
    The eventIcon in JFrame4 is: null
    The eventIcon in JFrame4 is: null
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0
    Originally Posted by wsa1971
    By declaring eventIcon1 again inside your constructor as a local variable, you are effectively shadowing the instance variable eventIcon1. So there is never any value assigned to the instance (public) variable eventIcon1.
    If you change it to:
    java Code:
        public JFrame4 (String theEventIcon) {
            eventIcon1 = theEventIcon;
            ...
    by simply removing the "String" bit it should work.

    I suggest some Googling on variable scope in java
    Thanks for the link for variable scope. That did the trick! One word: static.

    Thanks for taking the time to share your insight.
    Code:
    public class JFrame4 extends javax.swing.JFrame {
    
       // String eventIcon1;
        static  String eventIcon1; // = "firedept.png";
        Insets ins = getInsets();
    Have a great day,

    DaneCom
  8. #5
  9. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    380
    The code we have seen from you so far does not explain this behavior.
    Several things could be wrong:
    1. There is another instance of JFrame4 that is constructed with the parameterless constructor
    2. Some code between the constructor and the update method is called that assigns null to eventIcon1
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  10. #6
  11. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    380
    Judging by your "solution" I would guess there is another instance of JFrame4 constructed (option 1 in my previous post).

    I'd advise you to remove the static solution and fix this.

    Comments on this post

    • ishnid agrees
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0
    Originally Posted by wsa1971
    Judging by your "solution" I would guess there is another instance of JFrame4 constructed (option 1 in my previous post).

    I'd advise you to remove the static solution and fix this.
    Yes, I did overload the constructor:
    Code:
    public class JFrame4 extends javax.swing.JFrame {
    
       // String eventIcon1;
        static String eventIcon1; // = "firedept.png";
        Insets ins = getInsets();
    
        /** Creates new form JFrame4 */
        public JFrame4() {
                    initComponents();
    
        }
    
        public JFrame4 (String theEventIcon) {
            eventIcon1 = theEventIcon;
            System.out.println("The eventIcon passed into JFrame4 is " + theEventIcon
                    + " And this is given to this eventIcon as " + eventIcon1);
        }
    But why is that a bad thing

    Also, the variable eventIcon1 is not be set as null anywhere in the code.

    Code:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            JFrame3 frame_3 = new JFrame3();
            frame_3.setVisible(true);
            dispose();
        }
    
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            JFrame f = new fileChooser2();
            f.setBounds(300, 300, 300, 125);
            f.setBackground(Color.gray);
            f.setVisible(true);
            f.setDefaultCloseOperation(
            WindowConstants.DISPOSE_ON_CLOSE);
            dispose();
        }
    
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            System.exit(0);
        }
    
    //    public void eventIcon1( String eventIconS) {
    //        String eventIcon = eventIconS;
    //        System.out.println("The eventIcon in JFrame4 is: " + eventIcon +
    //                " In the pass to string method.");
    //        repaint();
    //
    //    }
    
        public void update (Graphics g) {
            paint(g);
        }
    
        public void paint (Graphics g) {
            super.paint(g);
            Toolkit tool = Toolkit.getDefaultToolkit();
            Image img = tool.getImage(eventIcon1);
            System.out.println("The eventIcon in JFrame4 is: " + eventIcon1);
            //g.drawString("ice", 450, 450);
    //        if (img != null) {
            
            g.drawImage(img, 350, 190, this);
        }
    Once again, I appreciate any insight you have to offer and/or better ways to code this program.

    Thanks,

    DaneCom
  14. #8
  15. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    380
    It would help if you post the code where you construct a JFrame4 instance (or several instances).
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0
    Originally Posted by wsa1971
    It would help if you post the code where you construct a JFrame4 instance (or several instances).

    And here you go...

    Code:
    /*
     * JFrame4.java
     
     */
    
    package kmlcreator;
    
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Insets;
    import java.awt.Toolkit;
    import javax.swing.JFrame;
    import javax.swing.WindowConstants;
    
    public class JFrame4 extends javax.swing.JFrame {
    
       // String eventIcon1;
        static String eventIcon1; // = "firedept.png";
        Insets ins = getInsets();
    
        /** Creates new form JFrame4 */
        public JFrame4() {
                    initComponents();
    
        }
    
        public JFrame4 (String theEventIcon) {
            eventIcon1 = theEventIcon;
            System.out.println("The eventIcon passed into JFrame4 is " + theEventIcon
                    + " And this is given to this eventIcon as " + eventIcon1);
        }
    //
    //  public JFrame4(String eventIconString) {
    //        eventIcon = eventIconString;
    //        initComponents();
    //    }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jPanel1.setBackground(new java.awt.Color(153, 153, 153));
            jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Final Phase", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tempus Sans ITC", 0, 36))); // NOI18N
    
            jLabel1.setText("You chose the filename as:");
    
            jLabel2.setText("You chose the type of event to be:");
    
            jButton1.setFont(new java.awt.Font("Tempus Sans ITC", 0, 16)); // NOI18N
            jButton1.setText("Back");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
    
            jButton2.setFont(new java.awt.Font("Tempus Sans ITC", 0, 16)); // NOI18N
            jButton2.setText("Finish");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
    
            jButton3.setFont(new java.awt.Font("Tempus Sans ITC", 0, 16)); // NOI18N
            jButton3.setText("Cancel");
            jButton3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton3ActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(43, 43, 43)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 253, Short.MAX_VALUE)
                            .addComponent(jButton2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton3)
                            .addGap(209, 209, 209))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2))
                            .addContainerGap(444, Short.MAX_VALUE))))
            );
    
            jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton3});
    
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(39, 39, 39)
                    .addComponent(jLabel1)
                    .addGap(39, 39, 39)
                    .addComponent(jLabel2)
                    .addGap(82, 82, 82)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(jButton2)
                        .addComponent(jButton3))
                    .addContainerGap(225, Short.MAX_VALUE))
            );
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            JFrame3 frame_3 = new JFrame3();
            frame_3.setVisible(true);
            dispose();
        }
    
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            JFrame f = new fileChooser2();
            f.setBounds(300, 300, 300, 125);
            f.setBackground(Color.gray);
            f.setVisible(true);
            f.setDefaultCloseOperation(
            WindowConstants.DISPOSE_ON_CLOSE);
            dispose();
        }
    
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            System.exit(0);
        }
    
    //    public void eventIcon1( String eventIconS) {
    //        String eventIcon = eventIconS;
    //        System.out.println("The eventIcon in JFrame4 is: " + eventIcon +
    //                " In the pass to string method.");
    //        repaint();
    //
    //    }
    
        public void update (Graphics g) {
            paint(g);
        }
    
        public void paint (Graphics g) {
            super.paint(g);
            Toolkit tool = Toolkit.getDefaultToolkit();
            Image img = tool.getImage(eventIcon1);
            System.out.println("The eventIcon in JFrame4 is: " + eventIcon1);
            //g.drawString("ice", 450, 450);
    //        if (img != null) {
            
            g.drawImage(img, 350, 190, this);
        }
    
        
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new JFrame4().setVisible(true);
    
                }
            });
        }
    
       
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JPanel jPanel1;
       
    
    }
    In an attempt to become a better programmer, I welcome your constructive criticism.

    Thanks in advance,

    DaneCom
  18. #10
  19. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    380
    Originally Posted by danecom
    But why is that a bad thing [/highlight]
    You misunderstood, overloading the constructor is not the problem here.

    The piece of code you provided gives me:
    Code:
    The eventIcon in JFrame4 is: null
    The eventIcon in JFrame4 is: null
    So my guess is that there is another piece of code.

    Purely hypothetical...

    What I think is going wrong is that you first construct a JFrame4 with something like this:
    java Code:
    JFrame4 jf4 = new JFrame4("firedept.png");
    and then later on you do something like this:
    java Code:
    new JFrame4().setVisible(true);
    What happens is that you first construct a JFrame4 instance jf4. This instance is (probably) never used, because later on you construct another instance with the 'empty' constructor.
    By removing the first construct and replacing the second bit of code with something like
    java Code:
    new JFrame4("firedept.png").setVisible(true);
    Your problem is solved and you don't need the static eventIcon1.
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0
    Originally Posted by wsa1971
    You misunderstood, overloading the constructor is not the problem here.

    The piece of code you provided gives me:
    Code:
    The eventIcon in JFrame4 is: null
    The eventIcon in JFrame4 is: null
    So my guess is that there is another piece of code.

    Purely hypothetical...

    What I think is going wrong is that you first construct a JFrame4 with something like this:
    java Code:
    JFrame4 jf4 = new JFrame4("firedept.png");
    and then later on you do something like this:
    java Code:
    new JFrame4().setVisible(true);
    What happens is that you first construct a JFrame4 instance jf4. This instance is (probably) never used, because later on you construct another instance with the 'empty' constructor.
    By removing the first construct and replacing the second bit of code with something like
    java Code:
    new JFrame4("firedept.png").setVisible(true);
    Your problem is solved and you don't need the static eventIcon1.
    First off, thanks for all your time and assistance.

    You are correct, sort of...

    In my initial post, I state I am attempting to pass a variable from one class to the next. And you are correct in your assumption it looks like this:
    Code:
    package kmlcreator;
    
    
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Insets;
    import java.awt.MediaTracker;
    import java.awt.Toolkit;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    
    public class JFrame3 extends javax.swing.JFrame {
            
            String eventIcon = "firedept.png";
    
    
        public JFrame3() {
            initComponents();
    
        }
    
     private void jLabel10MouseClicked(java.awt.event.MouseEvent evt) {                                      
            // TODO add your handling code here:
            eventType = fire;
            eventIcon = fireIcon;
            repaint();
            System.out.println("Fire");
            System.out.println(ins);
    
        }
    Code:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
           //Pass the eventIcon variable when the user selects the next button.
            JFrame4 frame_4 = new JFrame4();
            frame_4.setVisible(true);
            JFrame4 imageIcon = new JFrame4(eventIcon);
            System.out.println("The eventIcon passed to JFrame4 is : " + eventIcon);
    //         imageIcon.eventIcon1(eventIcon);
    //         JFrame4 imgIcon = new JFrame4();
    //        imgIcon.update(g);
            dispose();
        }
    public void update (Graphics g) {
            paint(g);
    //        JFrame4 imgIcon = new JFrame4();
    //        imgIcon.update(g);
        }
    
        public void paint(Graphics g) {
            super.paint(g);
            Toolkit tool = Toolkit.getDefaultToolkit();
            Image img = tool.getImage(eventIcon);
          //  System.out.println(eventIcon);
            //g.drawString("ice", 450, 450);
    //        if (img != null) {
            g.drawImage(img, 425, 425, this);

    Code:
     public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new JFrame3().setVisible(true);
    //                AwtImage ai = new AwtImage;
    
                }
            });
        }
    
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel10;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel jPanel1;

    I have four JFrame files that perform a function of selecting different inputs and then displaying them.

    The eventIcon is a String and is selected in JFrame3 and then passed to JFrame4.

    The code for JFrame3 is over 500 lines, if you wish I can post all of it - but it does successfully pass the variable eventIcon as presently coded to JFrame4.

    ONLY the paint method, in JFrame4, will not acknowledge the variable with classifying it as static.

    Although, this is not for a grade and I am not making any $$ off of it, I would REALLY like to make sure I code this and other programs properly.

    Your insight is appreciated,

    DaneCom
  22. #12
  23. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    380
    This:
    java Code:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            ...
            JFrame4 frame_4 = new JFrame4();
            frame_4.setVisible(true);
            JFrame4 imageIcon = new JFrame4(eventIcon);
            ...
    }
    is where your problem is. Though I don't think that this is the code you referred to in your initial post.
    The JFrame4 instance frame_4 is constructed without the icon String. The instance imageIcon is constructed with the icon String. The one being displayed is frame_4, while imageIcon is never used.

    Comments on this post

    • danecom agrees
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0
    Originally Posted by wsa1971
    This:
    java Code:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            ...
            JFrame4 frame_4 = new JFrame4();
            frame_4.setVisible(true);
            JFrame4 imageIcon = new JFrame4(eventIcon);
            ...
    }
    is where your problem is. Though I don't think that this is the code you referred to in your initial post.
    The JFrame4 instance frame_4 is constructed without the icon String. The instance imageIcon is constructed with the icon String. The one being displayed is frame_4, while imageIcon is never used.
    Thanks again for the input.

    I added the following:
    Code:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            JFrame4 frame_4 = new JFrame4();
            frame_4.setVisible(true);
            JFrame4 imageIcon = new JFrame4();
            System.out.println("The eventIcon passed to JFrame4 is : " + eventIcon);
             imageIcon.JFrame4_eventIcon(eventIcon);
    //         JFrame4 imgIcon = new JFrame4();
    //        imgIcon.update(g);
            dispose();
        }
    But I still receive the following results without using the static modifier:

    This statement is created in JFrame3:
    The eventIcon passed to JFrame4 is : firedept.png

    These statements are created in JFrame4:
    The eventIcon passed into JFrame4 is firedept.png And this is given to this eventIcon as firedept.png
    The eventIcon in JFrame4 is: null

    SO...I am back to square 1. DaneCom
  26. #14
  27. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    380
    Instead of adding code, you should omit (certain) code. I am almost sure that this will work:
    java Code:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
       JFrame4 frame_4 = new JFrame4(eventIcon);
       frame_4.setVisible(true);
       dispose();
    }
    If I were you I would clean up my code a bit. Remove all unnecessary stuff so you can focus on the issues. Your current MO keeps on adding more and more lines that either do nothing, or introduce more unexpected behavior.
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0
    Originally Posted by wsa1971
    Instead of adding code, you should omit (certain) code. I am almost sure that this will work:
    java Code:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
       JFrame4 frame_4 = new JFrame4(eventIcon);
       frame_4.setVisible(true);
       dispose();
    }
    If I were you I would clean up my code a bit. Remove all unnecessary stuff so you can focus on the issues. Your current MO keeps on adding more and more lines that either do nothing, or introduce more unexpected behavior.
    Thanks for your assistance,

    DaneCom

IMN logo majestic logo threadwatch logo seochat tools logo