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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:41+00:00 2026-05-25T14:23:41+00:00

I am currently learning java, I understand the concepts except Graphics which as a

  • 0

I am currently learning java, I understand the concepts except Graphics which as a programmer is totally new to me. Quite frankly it is driving my around the bend. My example should in theory make a circle appear at the press of a Button.

Using print methods to debug I keep finding that the Button correctly called all the methods and creates a new circle c object but in the newNode().drawCircle() repaint() is never called and hence the new object not drawn. WHY IS THIS and can someone help me get this darn circle to appear!! Some may notice I resorted to using this example to try and help resolve the problem http://leepoint.net/notes-java/examples/graphics/circles/circles.html .

This was meant to be the start of a Network graphing program which i PRESUMED would be easy…except for displaying the nodes when created…i.e the circle!

This code now works so i hope it can help people with a similar problem, as i know this is a common java assignment 🙂

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
///////////////////////////////////////////////////////////////////////
public class NetGrapher
{

public static void main(String[] args){
final JFrame frame = new JFrame ("NetGrapher");
frame.getContentPane().add(new NewNode()); /////delete line
final NewNode newNode = new NewNode();
///// Revision after answer, add, frame.getContentPane().add(newNode); (erase the above    frame.getContent)


JPanel buttonPanel = new JPanel();
JButton button = new JButton ("New Node");
button.addActionListener(new ActionListener( ){
    public void actionPerformed( ActionEvent e) {
    System.out.println( "Button Pressed");
    newNode.drawCircle();
    }
});

buttonPanel.add(button);
frame.add(buttonPanel, BorderLayout.SOUTH);

frame.setSize(600,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

}
//////////////////////////////////////////////////////////////////////
class NewNode extends JComponent
{

public ArrayList<Circle> _circles = new ArrayList<Circle>();

public void paintComponent(Graphics g){
g.setColor(Color.WHITE);
g.fillRect(0, 0, 600, 600);

System.out.println( "RePaint");
    for ( Circle c : _circles){
System.out.println( "Each C");
    g.setColor(Color.BLACK);
    c.draw(g);
    }
}

public void drawCircle(){

System.out.println( "drawCircle Implemented");
Circle c = new Circle(100, 100, 100, 100);
_circles.add(c);
repaint();
}

}

/////////////////////////////////////////////////////////////////////
class Circle
{
int x, y, z, a;

Circle (int _x, int _y, int _z, int _a){
this.x = _x;  
this.y = _y;
this.z = _z;
this.a = _a;
}

public void draw(Graphics g){

System.out.println( "Called In Draw Method");
g.setColor(Color.BLACK);
g.fillOval(x, y, z, a);
}

}
  • 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-25T14:23:42+00:00Added an answer on May 25, 2026 at 2:23 pm

    You are using two different instances of NewNode

    frame.getContentPane().add(new NewNode());
    final NewNode newNode = new NewNode();
    

    In your action listener you’re calling newNode.drawCircle() on newNode which was not added to a content pane.

    BTW have you noticed that you’ve got two Circle classes, where the first does some strange things (like adding a new circle into _circles which it cannot access)?

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

Sidebar

Related Questions

I am currently learning about basic networking in java. I have been playing around
I'm currently learning Haskell, Which language (F# or Haskell) do you prefer for programming
I’m currently learning the Java Collections API and feel I have a good understanding
I'm PHP-programmer, but I'm extremely interested in learning Java. So I decided to change
I currently learning about scrum and want to learn from experienced professionals in the
So I am currently learning C++ and decided to make a program that tests
I'm currently learning the APIs related to Intel's parallelization libraries such as TBB, MKL
I'm learning XML, currently of Wikibooks, but that is kinda huge and not oversee-able...
Im in the process of learning asp.net 3.5, currently on webparts and co. Ive
I'm learning about text processing in Java for a class and the example in

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.