Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Graphics in GUI?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Ashi_Mashi2




PostPosted: 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
Sponsor
sponsor
Ashi_Mashi2




PostPosted: 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




PostPosted: 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




PostPosted: 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 Crying or Very sad
rizzix




PostPosted: 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).
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: