Results 1 to 2 of 2
  1. #1
    Heat is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Default Problem with painting 2 components from different classes

    I want to make a simple Table Tennis game. I have 2 drawing classes. 1st should draw oval and 2nd rectangle. But second class, which should draw rectangle doesn't work and if i use it together with oval class, then oval doesn't appear too.

    Java Code:
    public static void main(String[] args) throws InterruptedException
    	
    {
    		
    	Intro i = new Intro();
    	Pall pall = new Pall();
    	Laud laud = new Laud();
    	i.frameID().add(pall); // this adds oval
    	i.frameID().add(laud); // this adds rectangle
    	i.frameID().pack();
    	i.frameID().setSize(400, 400);
    		
    }
    Part which draws oval
    Java Code:
    
    public void paint(Graphics g)
    {
           super.paint(g);
    	Graphics2D g2d = (Graphics2D) g;
    	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    	RenderingHints.VALUE_ANTIALIAS_ON);
    	g2d.fillOval(x, y, 30, 30);
    }
    Part which draws rectangle

    Java Code:
    public void Vanamees(Graphics g)
    {
    	super.paint(g);
    	Graphics2D g2d = (Graphics2D) g;
    	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    	RenderingHints.VALUE_ANTIALIAS_ON);
    	g2d.fillRect(20, 20, 30, 30);
    		
    		
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,780
    Rep Power
    5

    Default Re: Problem with painting 2 components from different classes

    Please submit an Short, Self Contained, Correct Example that demonstrates the problem. And make certain it
    is compilable and will run. The supplied code is not sufficient to offer any help. Also, you should be using Swing.
    If you are, then you should be using paintComponent and not paint.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Using swing components on multiple classes
    By Jkey in forum AWT / Swing
    Replies: 6
    Last Post: 06-08-2013, 01:37 PM
  2. question on arguments for painting components
    By jazzermonty in forum AWT / Swing
    Replies: 4
    Last Post: 02-22-2012, 10:37 PM
  3. Painting Problem!
    By Jcbconway in forum Advanced Java
    Replies: 3
    Last Post: 11-17-2010, 04:14 AM
  4. Swing components vs. custom painting
    By Cruncher in forum New To Java
    Replies: 6
    Last Post: 05-06-2010, 07:16 AM
  5. painting problem
    By hannes in forum New To Java
    Replies: 3
    Last Post: 01-17-2010, 11:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •