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 6665759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:45:25+00:00 2026-05-26T02:45:25+00:00

I have a design project and I’m supposed to draw zigzags in Java, using

  • 0

I have a design project and I’m supposed to draw zigzags in Java, using my mouse. First of all, I’m using MouseListener and in mouseClicked method, I gather all the points that the user clicks:

 public void mouseClicked(MouseEvent e){
    if(isAbleToDraw){
    corners[points]=e.getPoint();
        points++;
        repaint();
    }
 }

Here I use a boolean “isAbleToDraw” to check whether the user clicked “draw” or “stop drawing” buttons.
And then, I draw the zigzags like this:

 super.paintComponent(graph);
 Graphics2D g = (Graphics2D) graph;
 g.drawLine(corners[i].x, corners[i].y, corners[i+1].x, corners[i+1].y);

Finally, the problem is, when I clicked on “stop drawing” button after drawing a zigzag, and then after clicking the “draw” button again, it keeps drawing the lines from the last point it left. In other words, I can’t draw 2 different seperate zigzags.

Any idea about how to solve the issue?

  • 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-26T02:45:26+00:00Added an answer on May 26, 2026 at 2:45 am

    If you want the user to be able to draw more than one zig-zag and see them both on the screen, then you could use a Collection of point arrays. Each time the user clicks the “draw” button, you add a new array to the collection and make that new array the active array. In your mouseClicked, you can add the points that the user clicks to active point array and when you paint the component, rather than just drawing the one zig-zag, iterate through the collection of arrays and draw them all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java project that I'm trying to implement with a model-view-controller design.
I have an OS design project with some subprojects, I would like to try
I have recently been assigned a CSS & design project that's in a CakePHP
For a university mid-term project I have to design a configurable processor, to write
I have been looking into MVVM design patterns with WPF for a project. I
I'm starting a personal project, so I have at the moment complete architectural/design control.
I have been working through projects involving packages that do all the web design
I have a design idea for a large project at work and I think
I am currently working on a project where I have to design / implement
Intro We have a project to design and implement this semester. For our project,

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.