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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:45:39+00:00 2026-06-02T16:45:39+00:00

I have an assignment to create a paint program in Java. I have managed

  • 0

I have an assignment to create a paint program in Java. I have managed to create something but not exactly what I wanted.

My problem is that I cannot create a JFrame in my IDE(NetBeans 7.0.1) from the options that the IDE gives me, and call the paint classes correctly.

To be more specific I want to press a button from one panel(ex. Panel1) and paint in Panel2,in the same frame.

That’s the calling of the class:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    PaintFlower102 f = new PaintFlower102();
}

Part of Class:

    super("Drag to Paint");
    getContentPane().add(new Label ("Click and Drag"),BorderLayout.SOUTH);
    // add(new JButton("Brush 20"),BorderLayout.NORTH);
    addMouseMotionListener( new MouseMotionAdapter() {

        @Override
        public void mouseDragged(MouseEvent event) {
            xval=event.getX();
            yval=event.getY();
            repaint();
        }
    });

    setSize(500, 500);
    setVisible(true);
    setDefaultCloseOperation(PaintFlower102.DISPOSE_ON_CLOSE);
}

public void paint(Graphics g) {      
    g.fillOval(xval, yval, 10, 10);   
}

The problem is that if I do not put the extend JFrame in the class this doesn’t work. And if I do, it creates a new frame in which I can draw.

  • 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-02T16:45:41+00:00Added an answer on June 2, 2026 at 4:45 pm

    Suggestions:

    • Don’t ever paint directly in a JFrame except under rare circumstances of absolute need (this isn’t one of them).
    • Instead paint in a JPanel or JComponent or other derivative of JComponent.
    • Paint in the class’s paintComponent(Graphics g) method, not in paint(Graphics g).
    • Read the Java tutorials on this as it’s all explained well there. Check out Trail: 2D Graphics and Performing Custom Painting.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a school assignment I have to create a C++ program that will create
I was given the assignment to create a program that performs basic set operations.
I have done a homework assignment, here is the problem statement: Your program should
Continuing on this problem , but I'll reiterate: For a homework assignment I have
I have been trying to create a Main program that calls another program, sending
I have an assignment to create a GUI using MATLAB GUIDE and am having
I have an assignment to create a secure communication between 2 people with a
I have a small assignment in C. I am trying to create an array
I have assignment to work on producer and consumer problem by use thread and
I have an assignment for school, and I'm not sure how the teacher wants

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.