Results 1 to 3 of 3
  1. #1
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default Createing a class within a method.

    Java Code:
    public JPanel getQuizPanel() {
    		QuizPanel quizPanel = new QuizPanel();
    
    		class QuizPanel extends JPanel {
    			public void paintComponent(Graphics g) {
    				super.paintComponent(g);
    				Graphics2D g2 = (Graphics2D)g;
    
    				g2.setBackground(new Color(50, 20, 10));
    
    			}
    		}
    }
    Why do I have an error here?
    Java Code:
     QuizPanel quizPanel= new QuizPanel();

  2. #2
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default Re: Createing a class within a method.

    I searched the net and found nothing but then it dawned on me that perhaps the class hasn't been created yet according to the stack in memory.
    So I instantiated QuizPanel after the class creation and it worked.

    Thank you.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default Re: Createing a class within a method.

    Why do I have an error here?
    When you get errors, please copy the full text and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 5
    Last Post: 07-12-2012, 08:44 PM
  2. Replies: 8
    Last Post: 04-18-2012, 04:58 PM
  3. Replies: 0
    Last Post: 12-07-2011, 11:55 AM
  4. Replies: 1
    Last Post: 10-17-2011, 01:00 AM
  5. Replies: 5
    Last Post: 01-26-2011, 06:38 PM

Posting Permissions

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