Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:21:05+00:00 2026-06-01T23:21:05+00:00

I’m a beginner when it comes to Java and I’m following the instructions from

  • 0

I’m a beginner when it comes to Java and I’m following the instructions from a book. I am going to create a FigurePanel with the following code:

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

 public class TestFigurePanel extends JFrame{
    public TestFigurePanel() {
         setLayout(new GridLayout(2, 3, 5, 5));
         add(new FigurePanel(FigurePanel.LINE));
    }
}

But at the “add(new FigurePanel(FigurePanel.LINE));” I get the following error:

“Cannot find symbol:

Symbol: class FigurePanel

class: TestFigurePanel”

I would be very happy if someone good inform me of what is causing this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:21:07+00:00Added an answer on June 1, 2026 at 11:21 pm

    Add this class in your package:

    import java.awt.*;
    
    import javax.swing.JPanel;
    
    
    
    public class FigurePanel extends JPanel {
    
    // Define constants
    public static final int LINE = 1;
    
    public static final int RECTANGLE = 2;
    
    public static final int ROUND_RECTANGLE = 3;
    
    public static final int OVAL = 4;
    
    private int type = 1;
    
    private boolean filled;
    
    /** Construct a default FigurePanel */
    
    public FigurePanel() {
    
    }
    
    /** Construct a FigurePanel with the specified type */
    
    public FigurePanel(int type) {
    
    this.type = type;
    
    }
    
    
    
    /** Construct a FigurePanel with the specified type and filled */
    
    public FigurePanel(int type, boolean filled) {
    
    this.type = type;
    
    this.filled = filled;
    
    }
    
    
    
    /** Draw a figure on the panel */
    
    public void paintComponent(Graphics g) {
    
    super.paintComponent(g);
    
    
    
    // Get the appropriate size for the figure
    int width = getSize().width;
    
    int height = getSize().height;
    
    
    
    switch (type) {
    
      case LINE: // Display two cross lines
        g.setColor(Color.BLACK);
    
        g.drawLine(10, 10, width - 10, height - 10);
    
        g.drawLine(width - 10, 10, 10, height - 10);
    
        break;
    
      case RECTANGLE: // Display a rectangle
        g.setColor(Color.BLUE);
    
        if (filled)
    
          g.fillRect((int)(0.1 * width), (int)(0.1 * height),
    
            (int)(0.8 * width), (int)(0.8 * height));
    
        else
    
          g.drawRect((int)(0.1 * width), (int)(0.1 * height),
    
            (int)(0.8 * width), (int)(0.8 * height));
    
        break;
    
      case ROUND_RECTANGLE: // Display a round-cornered rectangle
        g.setColor(Color.RED);
    
        if (filled)
    
          g.fillRoundRect((int)(0.1 * width), (int)(0.1 * height),
    
            (int)(0.8 * width), (int)(0.8 * height), 20, 20);
    
        else
    
          g.drawRoundRect((int)(0.1 * width), (int)(0.1 * height),
    
            (int)(0.8 * width), (int)(0.8 * height), 20, 20);
    
        break;
    
      case OVAL: // Display an oval
        g.setColor(Color.BLACK);
    
        if (filled)
    
          g.fillOval((int)(0.1 * width), (int)(0.1 * height),
    
            (int)(0.8 * width), (int)(0.8 * height));
    
        else
    
          g.drawOval((int)(0.1 * width), (int)(0.1 * height),
    
            (int)(0.8 * width), (int)(0.8 * height));
    
    }
    
    }
    
    
    
      /** Set a new figure type */
    
      public void setType(int type) {
    
      this.type = type;
    
      repaint();
    
    }
    
    
    
    /** Return figure type */
    
    public int getType() {
    
    return type;
    
    }
    
    
    
    /** Set a new filled property */
    
    public void setFilled(boolean filled) {
    
      this.filled = filled;
    
      repaint();
    
    }
    
    
    
    /** Check if the figure is filled */
    
    public boolean isFilled() {
    
    return filled;
    
    }
    
    
    
    /** Specify preferred size */
    
    public Dimension getPreferredSize() {
    
    return new Dimension(80, 80);
    
    }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.