Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Color.*;

public class Circle extends JPanel{
	
	public void point(Graphics g){
		setSize(500,500);
		g.drawOval(100, 100, 100, 100); 
	}
	
	public static void main (String [] args){
		JFrame MainFrame = new JFrame();
		MainFrame.setSize(600, 600);
		Circle CirclePanel = new Circle();
		MainFrame.add(CirclePanel);
		MainFrame.setVisible(true);
	}
}


What I have tried:

Jpanel come up blank no circle

using Eclipse for Java
Posted
Updated 21-Sep-18 21:55pm
v2

OK, so follow your Main method code. At no point do you ever call the point method and pass it Graphics context to draw on.
 
Share this answer
 
Comments
Member 13993502 21-Sep-18 21:37pm    
If i changed it to rectangle besides the word circle to rectangle any else id have to change
Dave Kreskowiak 21-Sep-18 22:58pm    
It doesn't matter what you change the shape to. You never call the point() method and that's where all of your drawing code is!

I don't know Java, so I really can't tell you the exact code to create a Graphics object for the surface you want to draw on. But, once you do that and you call the point method passing in the Graphics object you create, it'll draw your shape.
Richard MacCutchan 22-Sep-18 4:31am    
See my answer below.
Member 13993502 21-Sep-18 23:52pm    
What I meant is the code for rectangle the same as the one i used for circle. do I just change circle to rectangle or are there other changes i need to make.
Java
public void point(Graphics g){

This is a simple spelling mistake. This method should be called paint with an a, not point.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900