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

  • Home
  • SEARCH
  • 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 6775675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:56:05+00:00 2026-05-26T15:56:05+00:00

I have a problem with drawing a polygon in Java applet. I don’t understand

  • 0

I have a problem with drawing a polygon in Java applet. I don’t understand what is wrong with this code. I have a class called DrawPoly that contains:

import java.awt.*;
import java.awt.geom.Point2D;
import java.applet.Applet;
import java.util.Vector;

public class DrawPoly extends Applet{
Polygon poly;
public void init(Graphics g){

        Polygon poly=new Polygon();
        poly.addPoint(60,100);

}
public void paint(Graphics g)
{
    Graphics2D gg;
    gg=(Graphics2D) g;
     System.out.println("number is"+ poly.npoints);
    }
 }

I don’t understand why the following code doesn’t work. I would like to create a global polygon, initialize it in init, and then do some 2D transformations such as rotation in paint. What am I missing? I only added one point to see if the initializations are corect. I don’t want to initialize the polygon in paint(), because i may want to use repaint() and the polygon would be initialized every time i call repaint(). If you could please help me out. Thanks a lot.

  • 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-05-26T15:56:06+00:00Added an answer on May 26, 2026 at 3:56 pm

    DrawPoly Applet

    /* <applet code='DrawPoly' width=200 height=110></applet> */
    import java.awt.*;
    import java.applet.Applet;
    
    public class DrawPoly extends Applet {
    
        Polygon poly;
    
        // init(Graphics) is not an applet method
        //public void init(Graphics g){
        @Override
        public void init() {
            // this declaration is creating a variable local
            // to the init() method
            //Polygon poly=new Polygon();
            poly=new Polygon();
            poly.addPoint(60,100);
            // at least add a 2nd point!
            poly.addPoint(160,60);
        }
    
        public void paint(Graphics g) {
            Graphics2D gg;
            gg=(Graphics2D) g;
            System.out.println("number is"+ poly.npoints);
            // the Polygon is never painted!
            gg.setColor(Color.BLACK);
            gg.drawPolygon(poly);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a problem drawing something quickly in .NET. I don't think that any
Good day, I have weird problem with drawing image. Code and pictures say more
I have a problem interoperating between system.drawing and WPF. To simplify this question I've
I have a problem with my game here. I kind of don't understand how
I have this problem while drawing a square in canvas, made out of two
I am working on kind of drawing program but I have a problem with
I have a complex SQL problem in MS SQL Server, and in drawing on
I have this problem that when there is an OpenGL application I am working
I have a problem with performance of my code under Windows Forms. Have a

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.