Seticon

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #16
    Originally posted by soty
    thank you
    You're welcome; what is your source code at lines 32 ... 40? What the heck,
    show it all so we can see what's wrong.

    kind regards,

    Jos

    Comment

    • soty
      New Member
      • Mar 2008
      • 25

      #17
      Originally posted by JosAH
      You're welcome; what is your source code at lines 32 ... 40? What the heck,
      show it all so we can see what's wrong.

      kind regards,

      Jos





      import java.awt.*;
      import java.applet.*;
      import java.awt.event. ActionListener;
      import javax.swing.Ico n;
      import javax.swing.Ima geIcon;
      import javax.swing.JTe xtPane;


      public class vendmachine extends Applet
      {
      Color Armygreen = new Color(120, 100, 50);

      Panel panel1 = new Panel();
      Label header = new Label("WELCOME TO UJU'S VENDING MACHINE");


      Panel panel2 = new Panel();
      Button chip = new Button();
      Button cookie = new Button();
      Button walnut = new Button();
      Button mintGum = new Button();
      Button lifesaver = new Button();
      Button popcorn = new Button();
      Button nacho = new Button();
      Button mandm = new Button();
      Button mixednut = new Button();

      this is line 30 chip.setIcon(ne w ImageIcon("chip s1.gif"));
      mintGum.setIcon (new ImageIcon("mint Gum.gif"));
      nacho.setIcon(n ew ImageIcon("nach os.gif"));
      cookie.setIcon( new ImageIcon("cook ies.gif"));
      lifesaver.setIc on(new ImageIcon("life saver.gif"));
      mandm.setIcon(n ew ImageIcon("m_m. gif"));
      walnut.setIcon( new ImageIcon("waln ut.gif"));
      popcorn.setIcon (new ImageIcon("popc orn.gif"));
      this is line 40 mixednut.setIco n(new ImageIcon("mixf ruit.gif"));




      Panel panel3 = new Panel();
      JTextPane mytextArea = new JTextPane();



      Panel panel4 = new Panel();


      Panel panel5 = new Panel();



      public void init()
      {
      setSize(400, 420);
      setLayout(new BorderLayout()) ;


      add(panel1);
      add(panel1, BorderLayout.NO RTH);
      panel1.add(head er);
      panel1.setPrefe rredSize(new Dimension(400,5 0));
      panel1.setBackg round(Color.GRA Y);



      add(panel2);
      add(panel2, BorderLayout.WE ST);
      panel2.setPrefe rredSize(new Dimension(270 , 50));
      panel2.add(chip );
      panel2.add(cook ie);
      panel2.add(waln ut);
      panel2.add(mint Gum);
      panel2.add(life saver);
      panel2.add(popc orn);
      panel2.add(nach o);
      panel2.add(mand m);
      panel2.add(mixe dnut);
      panel2.setBackg round(Color.BLU E);



      /* add(panel3);
      add(panel3,Bord erLayout.CENTER );
      // panel3.add(myte xtArea);
      panel3.setPrefe rredSize(new Dimension(400,1 00));
      // mytextArea.setB ackground(Color .PINK);
      panel3.setBackg round(Color.CYA N);*/



      add(panel4);
      add(panel4,Bord erLayout.SOUTH) ;
      panel4.setPrefe rredSize(new Dimension(400,1 00));
      panel4.setBackg round(Color.RED );



      add(panel5);
      add(panel5,Bord erLayout.CENTER );
      panel5.setPrefe rredSize(new Dimension(400,1 00));
      panel5.setBackg round(Color.GRE EN);




      }



      }

      Comment

      • soty
        New Member
        • Mar 2008
        • 25

        #18
        Originally posted by JosAH
        You're welcome; what is your source code at lines 32 ... 40? What the heck,
        show it all so we can see what's wrong.

        kind regards,

        Jos


        i posted everything. and i'm reposting it with the line 30 to 40 indicated in bold.

        thank you.


        import java.awt.*;
        import java.applet.*;
        import java.awt.event. ActionListener;
        import javax.swing.Ico n;
        import javax.swing.Ima geIcon;
        import javax.swing.JTe xtPane;


        public class vendmachine extends Applet
        {
        Color Armygreen = new Color(120, 100, 50);

        Panel panel1 = new Panel();
        Label header = new Label("WELCOME TO UJU'S VENDING MACHINE");


        Panel panel2 = new Panel();
        Button chip = new Button();
        Button cookie = new Button();
        Button walnut = new Button();
        Button mintGum = new Button();
        Button lifesaver = new Button();
        Button popcorn = new Button();
        Button nacho = new Button();
        Button mandm = new Button();
        Button mixednut = new Button();

        this is line 30 chip.setIcon(ne w ImageIcon("chip s1.gif"));
        mintGum.setIcon (new ImageIcon("mint Gum.gif"));
        nacho.setIcon(n ew ImageIcon("nach os.gif"));
        cookie.setIcon( new ImageIcon("cook ies.gif"));
        lifesaver.setIc on(new ImageIcon("life saver.gif"));
        mandm.setIcon(n ew ImageIcon("m_m. gif"));
        walnut.setIcon( new ImageIcon("waln ut.gif"));
        popcorn.setIcon (new ImageIcon("popc orn.gif"));
        this is line 40 mixednut.setIco n(new ImageIcon("mixf ruit.gif"));




        Panel panel3 = new Panel();
        JTextPane mytextArea = new JTextPane();



        Panel panel4 = new Panel();


        Panel panel5 = new Panel();



        public void init()
        {
        setSize(400, 420);
        setLayout(new BorderLayout()) ;


        add(panel1);
        add(panel1, BorderLayout.NO RTH);
        panel1.add(head er);
        panel1.setPrefe rredSize(new Dimension(400,5 0));
        panel1.setBackg round(Color.GRA Y);



        add(panel2);
        add(panel2, BorderLayout.WE ST);
        panel2.setPrefe rredSize(new Dimension(270 , 50));
        panel2.add(chip );
        panel2.add(cook ie);
        panel2.add(waln ut);
        panel2.add(mint Gum);
        panel2.add(life saver);
        panel2.add(popc orn);
        panel2.add(nach o);
        panel2.add(mand m);
        panel2.add(mixe dnut);
        panel2.setBackg round(Color.BLU E);



        /* add(panel3);
        add(panel3,Bord erLayout.CENTER );
        // panel3.add(myte xtArea);
        panel3.setPrefe rredSize(new Dimension(400,1 00));
        // mytextArea.setB ackground(Color .PINK);
        panel3.setBackg round(Color.CYA N);*/



        add(panel4);
        add(panel4,Bord erLayout.SOUTH) ;
        panel4.setPrefe rredSize(new Dimension(400,1 00));
        panel4.setBackg round(Color.RED );



        add(panel5);
        add(panel5,Bord erLayout.CENTER );
        panel5.setPrefe rredSize(new Dimension(400,1 00));
        panel5.setBackg round(Color.GRE EN);




        }



        }

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #19
          Now I see: move those lines 30 ... 40 to your initialization method. You can't
          put statements outside of any method (which you did). Only initialization
          expressions are allowed there.

          kind regards,

          Jos

          Comment

          • soty
            New Member
            • Mar 2008
            • 25

            #20
            Originally posted by JosAH
            Now I see: move those lines 30 ... 40 to your initialization method. You can't
            put statements outside of any method (which you did). Only initialization
            expressions are allowed there.

            kind regards,

            Jos

            i dont understand wat u meant by initialization method.

            Comment

            • Laharl
              Recognized Expert Contributor
              • Sep 2007
              • 849

              #21
              Put them in the function 'public void init() '. init is short for initialize here.

              Comment

              • soty
                New Member
                • Mar 2008
                • 25

                #22
                Originally posted by Laharl
                Put them in the function 'public void init() '. init is short for initialize here.

                ok i jus changed it and i av a new error. which is below



                thank you




                init:
                deps-jar:
                Compiling 1 source file to /Users/ask4soteria/NetBeansProject s/vendmachine/build/classes
                /Users/ask4soteria/NetBeansProject s/vendmachine/src/vendmachine.jav a:55: cannot find symbol
                symbol : method setIcon(javax.s wing.ImageIcon)
                location: class java.awt.Button
                mintGum.setIcon (new ImageIcon("mint Gum.gif"));
                /Users/ask4soteria/NetBeansProject s/vendmachine/src/vendmachine.jav a:56: cannot find symbol
                symbol : method setIcon(javax.s wing.ImageIcon)
                location: class java.awt.Button
                nacho.setIcon(n ew ImageIcon("nach os.gif"));
                /Users/ask4soteria/NetBeansProject s/vendmachine/src/vendmachine.jav a:57: cannot find symbol
                symbol : method setIcon(javax.s wing.ImageIcon)
                location: class java.awt.Button
                cookie.setIcon( new ImageIcon("cook ies.gif"));
                /Users/ask4soteria/NetBeansProject s/vendmachine/src/vendmachine.jav a:58: cannot find symbol
                symbol : method setIcon(javax.s wing.ImageIcon)
                location: class java.awt.Button
                lifesaver.setIc on(new ImageIcon("life saver.gif"));
                /Users/ask4soteria/NetBeansProject s/vendmachine/src/vendmachine.jav a:59: cannot find symbol
                symbol : method setIcon(javax.s wing.ImageIcon)
                location: class java.awt.Button
                mandm.setIcon(n ew ImageIcon("m_m. gif"));
                /Users/ask4soteria/NetBeansProject s/vendmachine/src/vendmachine.jav a:60: cannot find symbol
                symbol : method setIcon(javax.s wing.ImageIcon)
                location: class java.awt.Button
                walnut.setIcon( new ImageIcon("waln ut.gif"));
                /Users/ask4soteria/NetBeansProject s/vendmachine/src/vendmachine.jav a:61: cannot find symbol
                symbol : method setIcon(javax.s wing.ImageIcon)
                location: class java.awt.Button
                popcorn.setIcon (new ImageIcon("popc orn.gif"));
                /Users/ask4soteria/NetBeansProject s/vendmachine/src/vendmachine.jav a:62: cannot find symbol
                symbol : method setIcon(javax.s wing.ImageIcon)
                location: class java.awt.Button
                mixednut.setIco n(new ImageIcon("mixf ruit.gif"));
                8 errors
                BUILD FAILED (total time: 0 seconds)

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #23
                  This is where r035198x's remark comes in again (see reply #11). You are using
                  Buttons while you should be using JButtons, The first are AWT components
                  and the latter are Swing components. You should only use the first or the second
                  but never mix them. I advise to just use Swing components, so use JButtons.

                  kind regards,

                  Jos

                  Comment

                  • soty
                    New Member
                    • Mar 2008
                    • 25

                    #24
                    Originally posted by JosAH
                    This is where r035198x's remark comes in again (see reply #11). You are using
                    Buttons while you should be using JButtons, The first are AWT components
                    and the latter are Swing components. You should only use the first or the second
                    but never mix them. I advise to just use Swing components, so use JButtons.

                    kind regards,

                    Jos

                    thanks a lot for clarifying the difference btw button and jbutton.

                    the error has been solved.

                    .....uhmmm i av another question.

                    my pictures are not show on the buttons. can u tell me wat the problem is?

                    Thank you.

                    Comment

                    • Laharl
                      Recognized Expert Contributor
                      • Sep 2007
                      • 849

                      #25
                      Are the pictures in the same folder as the code? If not, you need to give a more complete filepath. I believe that unless you give it a relative filepath (it's contained in folders that are subfolders of the folder with the code, you must give an absolute filepath (the entire path from either / or the directory name under Windows (C:\\, for example)). If that doesn't help, post some code so we can check that.

                      Comment

                      • soty
                        New Member
                        • Mar 2008
                        • 25

                        #26
                        Originally posted by Laharl
                        Are the pictures in the same folder as the code? If not, you need to give a more complete filepath. I believe that unless you give it a relative filepath (it's contained in folders that are subfolders of the folder with the code, you must give an absolute filepath (the entire path from either / or the directory name under Windows (C:\\, for example)). If that doesn't help, post some code so we can check that.

                        the pictures are in the same folder wif the source file.

                        this is the code

                        thank you








                        [CODE=java] import java.awt.*;
                        import java.applet.*;
                        import java.awt.event. ActionListener;
                        import javax.swing.Ico n;
                        import javax.swing.Ima geIcon;
                        import javax.swing.JBu tton;
                        import javax.swing.JTe xtPane;


                        public class vendmachine extends Applet
                        {
                        Color Armygreen = new Color(120, 100, 50);

                        Panel panel1 = new Panel();
                        Label header = new Label("WELCOME TO UJU'S VENDING MACHINE");


                        Panel panel2 = new Panel();
                        JButton chip = new JButton();
                        JButton cookie = new JButton();
                        JButton walnut = new JButton();
                        JButton mintGum = new JButton();
                        JButton lifesaver = new JButton();
                        JButton popcorn = new JButton();
                        JButton nacho = new JButton();
                        JButton mandm = new JButton();
                        JButton mixednut = new JButton();







                        Panel panel3 = new Panel();
                        JTextPane mytextArea = new JTextPane();



                        Panel panel4 = new Panel();


                        Panel panel5 = new Panel();



                        public void init()
                        {


                        chip.setIcon(ne w ImageIcon("mint Gum.gif"));
                        mintGum.setIcon (new ImageIcon("mint Gum.gif"));
                        nacho.setIcon(n ew ImageIcon("nach os.gif"));
                        cookie.setIcon( new ImageIcon("cook ies.gif"));
                        lifesaver.setIc on(new ImageIcon("life saver.gif"));
                        mandm.setIcon(n ew ImageIcon("m_m. gif"));
                        walnut.setIcon( new ImageIcon("waln ut.gif"));
                        popcorn.setIcon (new ImageIcon("popc orn.gif"));
                        mixednut.setIco n(new ImageIcon("mixf ruit.gif"));



                        setSize(400, 420);
                        setLayout(new BorderLayout()) ;


                        add(panel1);
                        add(panel1, BorderLayout.NO RTH);
                        panel1.add(head er);
                        panel1.setPrefe rredSize(new Dimension(400,5 0));
                        panel1.setBackg round(Color.GRA Y);



                        add(panel2);
                        add(panel2, BorderLayout.WE ST);
                        panel2.setPrefe rredSize(new Dimension(270 , 50));
                        panel2.add(chip );
                        panel2.add(cook ie);
                        panel2.add(waln ut);
                        panel2.add(mint Gum);
                        panel2.add(life saver);
                        panel2.add(popc orn);
                        panel2.add(nach o);
                        panel2.add(mand m);
                        panel2.add(mixe dnut);
                        panel2.setBackg round(Color.BLU E);



                        /* add(panel3);
                        add(panel3,Bord erLayout.CENTER );
                        // panel3.add(myte xtArea);
                        panel3.setPrefe rredSize(new Dimension(400,1 00));
                        // mytextArea.setB ackground(Color .PINK);
                        panel3.setBackg round(Color.CYA N);*/



                        add(panel4);
                        add(panel4,Bord erLayout.SOUTH) ;
                        panel4.setPrefe rredSize(new Dimension(400,1 00));
                        panel4.setBackg round(Color.RED );



                        add(panel5);
                        add(panel5,Bord erLayout.CENTER );
                        panel5.setPrefe rredSize(new Dimension(400,1 00));
                        panel5.setBackg round(Color.GRE EN);




                        }



                        }[/CODE]
                        Last edited by r035198x; Mar 25 '08, 07:36 AM. Reason: Added code tags, please don't forget them next time.

                        Comment

                        • Laharl
                          Recognized Expert Contributor
                          • Sep 2007
                          • 849

                          #27
                          You're still mixing AWT and Swing...use javax.swing.JPa nel rather than java.awt.Panel. That's all I see that might cause this...

                          Comment

                          • soty
                            New Member
                            • Mar 2008
                            • 25

                            #28
                            Originally posted by Laharl
                            You're still mixing AWT and Swing...use javax.swing.JPa nel rather than java.awt.Panel. That's all I see that might cause this...


                            thanks.

                            ok av changed evrything from label , panel to Jlabel ,Jpanel but my pics r still not showing on the button. i'm gonna repost ma code so u look at it. thank you.






                            Code:
                            import java.awt.*;
                            import java.applet.*;
                            //import java.awt.event.ActionListener;*/
                            import javax.swing.ImageIcon;
                            import javax.swing.JButton;
                            import javax.swing.JLabel;
                            import javax.swing.JTextPane;
                            import javax.swing.JPanel;
                            
                            
                            public class vendmachine extends Applet
                            {
                            	Color Armygreen = new Color(120, 100, 50);
                                    
                                    JPanel panel1 = new JPanel();
                                    JLabel header = new JLabel("WELCOME TO UJU'S VENDING MACHINE");
                                    
                                    
                                    JPanel panel2 = new JPanel();
                                    JButton chip = new JButton();
                                    JButton cookie = new JButton();
                                    JButton walnut = new JButton();
                                    JButton mintGum = new JButton();
                                    JButton lifesaver = new JButton();
                                    JButton popcorn = new JButton();
                                    JButton nacho = new JButton();
                                    JButton mandm = new JButton();
                                    JButton mixednut = new JButton();
                                    
                                   
                                    
                                    
                                    
                                    
                                    
                                    JPanel panel3 = new JPanel();
                                    JTextPane mytextArea = new JTextPane();
                                    
                                    
                                    
                                    JPanel panel4 = new JPanel();
                                    
                                    
                                    JPanel panel5 = new JPanel();
                                    
                                    
                                    
                                    public void init() 
                                    {
                                        
                                        
                                        chip.setIcon(new ImageIcon("mintGum.gif"));
                                        mintGum.setIcon(new ImageIcon("mintGum.gif"));
                                        nacho.setIcon(new ImageIcon("nachos.gif"));
                                        cookie.setIcon(new ImageIcon("cookies.gif"));
                                        lifesaver.setIcon(new ImageIcon("lifesaver.gif"));
                                        mandm.setIcon(new ImageIcon("m_m.gif"));
                                        walnut.setIcon(new ImageIcon("walnut.gif"));
                                        popcorn.setIcon(new ImageIcon("popcorn.gif"));
                                        mixednut.setIcon(new ImageIcon("mixfruit.gif"));
                                        
                                        
                                        
                            		setSize(400, 420);
                            		setLayout(new BorderLayout());
                                            
                                            
                                            add(panel1);
                                            add(panel1, BorderLayout.NORTH);
                                            panel1.add(header);
                                            panel1.setPreferredSize(new Dimension(400,50));
                                            panel1.setBackground(Color.GRAY);
                                            
                                            
                                            
                                            add(panel2);
                                            add(panel2, BorderLayout.WEST);
                                            panel2.setPreferredSize(new Dimension(270 , 50));
                                            panel2.add(chip);
                                            panel2.add(cookie);
                                            panel2.add(walnut);
                                            panel2.add(mintGum);
                                            panel2.add(lifesaver);
                                            panel2.add(popcorn);
                                            panel2.add(nacho);
                                            panel2.add(mandm);
                                            panel2.add(mixednut);
                                            panel2.setBackground(Color.BLUE);
                                            
                                            
                                            
                                           /* add(panel3);
                                            add(panel3,BorderLayout.CENTER);
                                           // panel3.add(mytextArea);
                                            panel3.setPreferredSize(new Dimension(400,100));
                                           // mytextArea.setBackground(Color.PINK);
                                            panel3.setBackground(Color.CYAN);*/
                                            
                                            
                                            
                                            add(panel4);
                                            add(panel4,BorderLayout.SOUTH);
                                            panel4.setPreferredSize(new Dimension(400,100));
                                            panel4.setBackground(Color.RED);
                                            
                                            
                                            
                                            add(panel5);
                                            add(panel5,BorderLayout.CENTER);
                                            panel5.setPreferredSize(new Dimension(400,100));
                                            panel5.setBackground(Color.GREEN);
                                            
                                            
                                            
                                            
                                    }
                                    
                            
                            	
                            }

                            Comment

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #29
                              That code doesn't compile: you forgot right curly brackets. Use the System.out.prin tln()
                              method to show whether or not the ImageIcon could actually find the file; if you
                              know that then we can look at your code again.

                              kind regards,

                              Jos

                              Comment

                              • soty
                                New Member
                                • Mar 2008
                                • 25

                                #30
                                Originally posted by JosAH
                                That code doesn't compile: you forgot right curly brackets. Use the System.out.prin tln()
                                method to show whether or not the ImageIcon could actually find the file; if you
                                know that then we can look at your code again.

                                kind regards,

                                Jos

                                hi i covered the init () curly bracket and the class curly bracket. so which of the curly bracket where u asking me about?

                                thanks you

                                Comment

                                Working...