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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:33:45+00:00 2026-06-13T13:33:45+00:00

I have tried my best to read around on the topic but I cannot

  • 0

I have tried my best to read around on the topic but I cannot find/understand how to apply the answers to my piece code (and those I have applied don’t work)

I have used an example from “Ivor Horton’s Beginning Java 2 JDK book” and it is the first time I’m using repaint() but it doesn’t seem to work unless I resize the window. It tries to repaint but leaves the screen blank.

Here’s the code please let me know if there is something I’m doing wrong.

public class CurveDrawings extends JFrame{
public CurveDrawings (String title){
    setTitle(title);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    pane = new CurvePane();                     //Create pane containing curves
    Container content = getContentPane();       //Get the content pane

    //Add the pane containing the curves to the content pane for the applet
    content.add(pane);

    MouseHandler handler = new MouseHandler();
    pane.addMouseListener(handler);
    pane.addMouseMotionListener(handler);
}

//Class defining pane on which to draw
class CurvePane extends JComponent{
    public CurvePane(){
        quadCurve = new QuadCurve2D.Double(
            startQ.x, startQ.y, control.x, control.y, endQ.x, endQ.y
        );

        cubicCurve = new CubicCurve2D.Double(
            startC.x, startC.y, controlStart.x, controlStart.y,
            controlEnd.x, controlEnd.y, endC.x, endC.y
        );
    }
}

class Marker{//not needed for my problem}

class MouseHandler extends MouseInputAdapter{
    public void mousePressed(MouseEvent e){
        if(ctrlQuad.contains(e.getX(),e.getY())){
            selected = ctrlQuad;}
        else if(ctrlCubic1.contains(e.getX(),e.getY())){
            selected = ctrlCubic1;}
        else if(ctrlCubic2.contains(e.getX(),e.getY())){
            selected = ctrlCubic2;}
    }


    public void mouseReleased (MouseEvent e){
        selected = null;
    }

    public void mouseDragged (MouseEvent e){
        System.out.println("DRAGGED");
        if(selected != null){
            //Set the marker to current cursor position
            selected.setLocation(e.getX(),e.getY());
            pane.validate();
            pane.repaint();
        }
    }

    Marker selected = null;
}

    public void paint (Graphics g){
        Graphics2D g2D = (Graphics2D)g;         //Get a 2D device context
    //Code to draw each component
    }



//Points for quadratic curve

//Points for cubic curve

//More unnecessary code}

Incase it is any help here’s the ‘Launcher’ class for the application

Thanks in advance.

  • 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-13T13:33:46+00:00Added an answer on June 13, 2026 at 1:33 pm

    You will need to call

    super.paint(g);
    

    in your paint method in your CurveDrawings class to avail of the painting functionality already provided in the JFrame super class.

    Note, the standard way of using custom painting in Swing is to use custom components that are based on javax.swing.JComponent that use and override paintComponent. This approach would leverage Swing’s optimized painting model.

    See: Performing Custom Painting

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

Sidebar

Related Questions

I have tried my best to understand a very similar StackOverflow question , but
I have tried to read up on the subject but when I try to
I have tried to do research on this topic, but have not found an
Have tried to find solutions for this and can't really come up with anything.
I have tried searching over the internet about this problem but not able to
I have tried many permutations but they all don't seems to work well. Am
I have tried everything in the book and EVERYTHING I could find on how
I have tried almost all the techniques to apply sticky footer to my site
I want to read plain/text from an Https server. I have tried various codes
What are the best practices for language(localization) in Umbraco? We have tried to add

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.