Solved

error in code (cannot resolve symbol-method getContentPane()

Posted on 2004-03-28
6
733 Views
Last Modified: 2010-03-31
Get this error in code (cannot resolve symbol-method getContentPane()

this.getContentPane().add(p1, BorderLayout.CENTER);

 I made it easy to fine it has all the space between it and other code


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

public class Kempos extends JPanel
{ // Opens class

    public Kempos()
    {
        super();

        Font f1 = new Font("Courier New", Font.BOLD, 15);

        JPanel p1 = new JPanel();
        JPanel p2 = new JPanel();
        JPanel p3 = new JPanel();
        JPanel p4 = new JPanel();
        JPanel p5 = new JPanel();
        JPanel p6 = new JPanel();

        final JButton b1 = new JButton("G1");
        final JButton b2 = new JButton("G2");
        final JButton b3 = new JButton("G3");
        final JButton b4 = new JButton("G4");
        final JButton b5 = new JButton("G5");
        final JButton b6 = new JButton("G6");
        final JButton b7 = new JButton("G7");
        final JButton b8 = new JButton("G8");

        final JButton b9 = new JButton("Restart");
        final JButton b0 = new JButton("   Exit    ");

        b9.setMnemonic('R'); b0.setMnemonic('E');

        final JLabel l1 = new JLabel();
        l1.setBorder(BorderFactory.createLineBorder(Color.yellow));

        p1.setBorder(BorderFactory.createLoweredBevelBorder());
        p4.setBorder(BorderFactory.createLoweredBevelBorder());
        p4.setBackground(Color.blue);

        p1.setLayout(new GridLayout(1,2));
        p1.add(p2); p1.add(p3);

        p2.setLayout(new GridLayout(1,1));
        p2.add(p4);

        p4.setLayout(new GridLayout(3,3));
        p4.add(b1); p4.add(b2); p4.add(b3);
        p4.add(b4); p4.add(l1); p4.add(b5);
        p4.add(b6); p4.add(b7); p4.add(b8);

        p5.setLayout(new GridLayout(5,1));
        p5.add(new JLabel("Name 1\n"));
        p5.add(new JLabel("Name 2"));
        p5.add(new JLabel("Name 3"));
        p5.add(new JLabel("Name 4"));
        p5.add(new JLabel("Name 5"));
 
        p3.setLayout(new GridLayout(1,3));
        p3.add(new JPanel()); p3.add(p5);
        p3.add(new JPanel());

        p6.add(b9); p6.add(b0);




        this.getRootPane().setDefaultButton(b9);
        this.getContentPane().add(p1, BorderLayout.CENTER);
        this.getContentPane().add(p6, BorderLayout.SOUTH);






        this.setResizable(false);
        this.setSize(800, 600);
        this.setVisible(true);

        // Add your action listener here . . .
        b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G1       ");
        b1.setText("");
        b1.setEnabled(false);
        }
        });

        b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G2       ");
        b2.setText("");
        b2.setEnabled(false);
        }
        });

        b3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G3       ");
        b3.setText("");
        b3.setEnabled(false);
        }
        });

        b4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G4       ");
        b4.setText("");
        b4.setEnabled(false);
        }
        });

        b5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G5       ");
        b5.setText("");
        b5.setEnabled(false);
        }
        });

        b6.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G6       ");
        b6.setText("");
        b6.setEnabled(false);
        }
        });

        b7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G7       ");
        b7.setText("");
        b7.setEnabled(false);
        }
        });

        b8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G8       ");
        b8.setText("");
        b8.setEnabled(false);
        }
        });

        b9.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("");

        b1.setText("G1");
        b2.setText("G2");
        b3.setText("G3");
        b4.setText("G4");
        b5.setText("G5");
        b6.setText("G6");
        b7.setText("G7");
        b8.setText("G8");

        b1.setEnabled(true);
        b2.setEnabled(true);
        b3.setEnabled(true);
        b4.setEnabled(true);
        b5.setEnabled(true);
        b6.setEnabled(true);
        b7.setEnabled(true);
        b8.setEnabled(true);
        }
        });

        b0.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        System.exit(0);
        }
        });
    }
}
0
Comment
Question by:Drop_of_Rain
  • 4
6 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 10701555
This should be just basic try to read the documentation of Java :

Baically, this is the problem, because this declared for JFrame :

this.getRootPane().setDefaultButton(b9);
this.getContentPane().add(p1, BorderLayout.CENTER);
this.getContentPane().add(p6, BorderLayout.SOUTH);
this.setResizable(false);
this.setSize(800, 600);
this.setVisible(true);

So remove that and replace that with :

getRootPane().setDefaultButton(b9);
add(p1, BorderLayout.CENTER);
add(p6, BorderLayout.SOUTH);

Hope that helps . . .
Javatm
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10701560
Kempos extends JFrame

Will solve your problem.


Regards,
Muruga
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10701613
> Kempos extends JFrame
> Will solve your problem.

Essentially (s)he Told me to create it to JPanel because what we originally have was
JFrame, so basically she needs it to be in JPanel.

Hope that helps . . .
Javatm
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 15

Accepted Solution

by:
Javatm earned 175 total points
ID: 10701619
So it will be like this :

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

public class Kempos extends JPanel
{ // Opens class

    public Kempos()
    {
        super();

        Font f1 = new Font("Courier New", Font.BOLD, 15);

        JPanel p1 = new JPanel();
        JPanel p2 = new JPanel();
        JPanel p3 = new JPanel();
        JPanel p4 = new JPanel();
        JPanel p5 = new JPanel();
        JPanel p6 = new JPanel();

        final JButton b1 = new JButton("G1");
        final JButton b2 = new JButton("G2");
        final JButton b3 = new JButton("G3");
        final JButton b4 = new JButton("G4");
        final JButton b5 = new JButton("G5");
        final JButton b6 = new JButton("G6");
        final JButton b7 = new JButton("G7");
        final JButton b8 = new JButton("G8");

        final JButton b9 = new JButton("Restart");
        final JButton b0 = new JButton("   Exit    ");

        b9.setMnemonic('R'); b0.setMnemonic('E');

        final JLabel l1 = new JLabel();
        l1.setBorder(BorderFactory.createLineBorder(Color.yellow));

        p1.setBorder(BorderFactory.createLoweredBevelBorder());
        p4.setBorder(BorderFactory.createLoweredBevelBorder());
        p4.setBackground(Color.blue);

        p1.setLayout(new GridLayout(1,2));
        p1.add(p2); p1.add(p3);

        p2.setLayout(new GridLayout(1,1));
        p2.add(p4);

        p4.setLayout(new GridLayout(3,3));
        p4.add(b1); p4.add(b2); p4.add(b3);
        p4.add(b4); p4.add(l1); p4.add(b5);
        p4.add(b6); p4.add(b7); p4.add(b8);

        p5.setLayout(new GridLayout(5,1));
        p5.add(new JLabel("Name 1\n"));
        p5.add(new JLabel("Name 2"));
        p5.add(new JLabel("Name 3"));
        p5.add(new JLabel("Name 4"));
        p5.add(new JLabel("Name 5"));
 
        p3.setLayout(new GridLayout(1,3));
        p3.add(new JPanel()); p3.add(p5);
        p3.add(new JPanel());

        p6.add(b9); p6.add(b0);

        getRootPane().setDefaultButton(b9);
        add(p1, BorderLayout.CENTER);
        add(p6, BorderLayout.SOUTH);

        // Add your action listener here . . .
        b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G1       ");
        b1.setText("");
        b1.setEnabled(false);
        }
        });

        b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G2       ");
        b2.setText("");
        b2.setEnabled(false);
        }
        });

        b3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G3       ");
        b3.setText("");
        b3.setEnabled(false);
        }
        });

        b4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G4       ");
        b4.setText("");
        b4.setEnabled(false);
        }
        });

        b5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G5       ");
        b5.setText("");
        b5.setEnabled(false);
        }
        });

        b6.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G6       ");
        b6.setText("");
        b6.setEnabled(false);
        }
        });

        b7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G7       ");
        b7.setText("");
        b7.setEnabled(false);
        }
        });

        b8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G8       ");
        b8.setText("");
        b8.setEnabled(false);
        }
        });

        b9.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("");

        b1.setText("G1");
        b2.setText("G2");
        b3.setText("G3");
        b4.setText("G4");
        b5.setText("G5");
        b6.setText("G6");
        b7.setText("G7");
        b8.setText("G8");

        b1.setEnabled(true);
        b2.setEnabled(true);
        b3.setEnabled(true);
        b4.setEnabled(true);
        b5.setEnabled(true);
        b6.setEnabled(true);
        b7.setEnabled(true);
        b8.setEnabled(true);
        }
        });

        b0.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        System.exit(0);
        }
        });
    }
}
0
 

Author Comment

by:Drop_of_Rain
ID: 10701666
Yes it was basic but it was right under my nose. So was this but when you brought it to my attention I noticed it. Thanks fot the eye opener. Duh so I didn't need the last comment you made.

Thanks for all the help.

        this.setResizable(false);
        this.setSize(800, 600);
        this.setVisible(true);
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10701741
http://www.freewebs.com/cube-j

Always glad to help . . .
Friend : Javatm
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 29
factorial example 4 47
eclipse buid path vs tomcat lib path 10 34
Selenium docs api java index 3 48
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question