
-----------------------------------
Ashi_Mashi2
Thu Dec 29, 2005 10:56 am

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

-----------------------------------
Ashi_Mashi2
Fri Dec 30, 2005 9:07 pm


-----------------------------------
ok..can someone plz tell me what's wrong with this code?..thx


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
Sat Dec 31, 2005 12:58 am


-----------------------------------
extend java.awt.Canvas and ovrride paint(Graphics g) and not paintComponent(Graphics g)

-----------------------------------
Ashi_Mashi2
Sat Dec 31, 2005 11:42 am


-----------------------------------
thanks...do you mean like this:


private class PaintComponenet extends java.awt.Canvas 
    {
        public void paint (Graphics g)
        {
            g.drawOval (50, 50, 100, 100);
        }
    }

it still does not work :cry:

-----------------------------------
rizzix
Sat Dec 31, 2005 7:23 pm


-----------------------------------
add the component to BorderLayout.CENTER
Also, do not add unnecessary containers (in this case the extra JPanel).
