| Graphics in GUI? 
 
	 
	
		| Author | Message |   
		| Ashi_Mashi2 
 
 
 
 
 | 
			
				|  Posted: Thu Dec 29, 2005 10:56 am    Post subject: Graphics in GUI? |  |   
				| 
 |  
				| I want to make a Graphing calculator..so, I should somehow implement a Graphics object into GUI. Does anyone have any ideas? I researched a little, found a paintComponent method....dont know how it works or how to implement it...thanks a lot
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| Ashi_Mashi2 
 
 
 
 
 | 
			
				|  Posted: Fri Dec 30, 2005 9:07 pm    Post subject: (No subject) |  |   
				| 
 |  
				| ok..can someone plz tell me what's wrong with this code?..thx 
 
 	  | code: |  	  | 
import java.awt.*;
 import javax.swing.*;
 
 public class GraphTest
 {
 public static void main (String[] args)
 {
 new GraphTest ();
 }
 
 
 public GraphTest ()
 {
 JFrame f = new JFrame ("Grpahing Test");
 f.setDefaultCloseOperation (3);
 Container c = f.getContentPane ();
 c.setLayout (new BorderLayout ());
 JPanel p = new JPanel ();
 p.add (new PaintComponenet ());
 c.add (p, BorderLayout.NORTH);
 f.setSize (200, 200);
 f.show ();
 }
 
 
 private class PaintComponenet extends JComponent
 {
 public void paintComponent (Graphics g)
 {
 g.drawOval (50, 50, 100, 100);
 }
 }
 }
 
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| rizzix 
 
 
 
 
 | 
			
				|  Posted: Sat Dec 31, 2005 12:58 am    Post subject: (No subject) |  |   
				| 
 |  
				| extend java.awt.Canvas and ovrride paint(Graphics g) and not paintComponent(Graphics g) |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Ashi_Mashi2 
 
 
 
 
 | 
			
				|  Posted: Sat Dec 31, 2005 11:42 am    Post subject: (No subject) |  |   
				| 
 |  
				| thanks...do you mean like this: 
 
 	  | code: |  	  | 
private class PaintComponenet extends java.awt.Canvas
 {
 public void paint (Graphics g)
 {
 g.drawOval (50, 50, 100, 100);
 }
 }
 
 | 
 it still does not work
  |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| rizzix 
 
 
 
 
 | 
			
				|  Posted: Sat Dec 31, 2005 7:23 pm    Post subject: (No subject) |  |   
				| 
 |  
				| add the component to BorderLayout.CENTER Also, do not add unnecessary containers (in this case the extra JPanel).
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |