Results 1 to 4 of 4
  1. #1
    Luftwaffle is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default getContentFrame problems

    Hey all, I have this simple GUI I've been working on and it is driving me absolutely bananas! Every thing's worked out except for this one single bug, the compiler keeps telling me it can't find getContentPane, I don't know how to fix this.

    Java Code:
     import java.lang.*;
    import java.awt.*;
    import java.applet.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.JFrame;
    import java.awt.Component; 
    
    public class Add_Subtract_2 extends Applet {
        
            private int WIDTH=300;
            private int HEIGHT=100;
            private int value;
            private JLabel centerLabel;
             private JButton Add, Subtract;
             private Container cp;
           
        
            //-----------------------------------------------------------------------
            // Sets up GUI
            //-----------------------------------------------------------------------
        public void init() {
            value=50;
            
            Add= new JButton("Add");
            Add.addActionListener (new AddListener());
            
            Subtract= new JButton("Subtract");
            Subtract.addActionListener (new SubtractListener());
            
            centerLabel= new JLabel("The value is " + Integer.toString(value) );
            
            Container cp = getContentPane();
            cp.setBackground(Color.cyan);
            cp.setLayout(new FlowLayout());
            cp.add(Add);
            cp.add(centerLabel);
            cp.add(Subtract);
            
            setSize(WIDTH,HEIGHT);
            
        }
        
                
        //Listeners for action events
        
            private class AddListener implements ActionListener
            {
                public void actionPerformed(ActionEvent event)
                {
                    value++;
                    centerLabel.setText("The value is " + Integer.toString(value));
                    repaint();
                
                }
            }
            
            private class SubtractListener implements ActionListener
            {
                public void actionPerformed(ActionEvent event)
                {
                    value--;
                    centerLabel.setText("The value is " + Integer.toString(value));
                    repaint();
                }
                
            }
    
        
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: getContentFrame problems

    Your class extends java.awt.Applet, not javax.swing.JApplet, and Applets don't have contentPanes. I suggest that you use the latter, JApplet, not the former, Applet.

  3. #3
    Luftwaffle is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: getContentFrame problems

    Thank You

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: getContentFrame problems

    You're welcome! And welcome to java-forums.org!

Similar Threads

  1. need help with several problems
    By tidus1103 in forum New To Java
    Replies: 4
    Last Post: 03-11-2011, 01:10 AM
  2. Problems getting value from map
    By hendrieke H smit in forum New To Java
    Replies: 2
    Last Post: 02-07-2011, 08:40 PM
  3. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 11:12 AM
  4. having problems
    By pinkdiamondgail in forum New To Java
    Replies: 6
    Last Post: 02-06-2009, 11:35 PM
  5. Problems in JSP : Need help
    By raj4u in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-07-2008, 10:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •