Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Imane BEN MOUSSA


I am trying to draw rectangle2d, circle2d , line2D,point2D onto a pane. My program will compile
and run but when i press any button does not seem to get drawn. When the program
is run the program frame opens up, but I cannot see any thing on the
pane except button.
Any help would be appreciated.
Sincerely,
Imane
Posted
Comments
Richard MacCutchan 8-Apr-11 8:04am    
Try showing some of your code; it's impossible to guess what your program is doing or not doing.

1 solution

It's difficult to tell from your question how you're trying to draw the lines and circles so I am not sure if this is going to help you, but here's a sample app that does draw stuff:

Java
package com.test;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JFrame;
public class Program extends JFrame {
	
	public Program() {
		setSize(320, 200);
		setBackground(Color.WHITE);
		setForeground(Color.WHITE);
	}
	
	@Override
	public void paint(Graphics g) {
		Graphics2D graphics = (Graphics2D) g;
		// Draw red rectangle
		graphics.setPaint(Color.RED);
		Rectangle2D.Double rectangle = new 
                   Rectangle2D.Double(64, 64, 60, 30);
		graphics.drawRect((int)rectangle.x, (int)rectangle.y, 
                   (int)rectangle.width, (int)rectangle.height);

		// Draw green circle
		graphics.setPaint(Color.GREEN);
		
		graphics.drawArc(120, 120, 32, 32, 0, 360);
	}
	
	public static void main(String[] args) throws Exception  {
		Program program = new Program();
		program.setVisible(true);
		
		System.in.read();
		
	}
}


Hope this helps,
Fredrik Bornander
 
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