Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Having trouble with Rectangle2d

  1. #1
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default [SOLVED]Having trouble with Rectangle2d

    Hello, Gravity Games here! Recently, I've been playing apps on my new Android Galaxy Player, and have been having a lot of fun, which motivated me to start developing android apps. Apparently, android apps are coded in Java, so I made the decision o finally move up from game maker and start using Java. I was following a YouTube tutorial in Java game coding, and everything was going swell, until I got to the point of rendering a rectangle. Here's the code I have in the file that's giving me trouble.

    package main.cww.gravitygames;
     
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.geom.Rectangle2D;
     
    import javax.swing.*;
     
    public class Ac extends JPanel{
    	public int characterWidth=12;
    	public int characterHeight=20;
    	public Rectangle character;
     
     
    	public boolean objectsDefined=false;
     
    	public Ac() {
    		setBackground(Color.BLACK);
     
    		defineObjects();
    	}
        public void defineObjects() {
        	character = new Rectangle((Aa.width/2) - (characterWidth/2), (Aa.height/2) - (characterHeight/2), characterWidth, characterHeight);
     
        	objectsDefined=true;
        }
     
    	public void paintComponent(Graphics g) {
            	super.paintComponent(g);
     
            	if(objectsDefined){
            		g.setColor(Color.WHITE);
            		g.fillRect(character.x, character.y, character.width, character.height);
            	}
            }
    }

    Help is REALLY appreciated, I've been trying 2 days to fix this but to no avail.

    EDIT: ...okay? I had originally used Rectangle, but I changed it to Rectangle2d at the request of Eclipse, then I hover over Rectangle2d and it requests a change to Rectangle. When I tried running it again, it somehow worked... is it just me, or is Eclipse just weird sometimes?...
    Last edited by Gravity Games; May 2nd, 2012 at 03:13 PM. Reason: ...somehow the problem fixed itself...


Similar Threads

  1. BlueJ trouble or program trouble (Combining Arraylists)
    By star12345645 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 11th, 2012, 01:15 PM
  2. [SOLVED] having a little trouble
    By XSmoky in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 6th, 2011, 08:48 PM
  3. Having trouble with if, else if, else if...
    By thetallguy in forum Loops & Control Statements
    Replies: 1
    Last Post: October 24th, 2011, 11:28 PM
  4. Having trouble returning the right out put.
    By byako in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 27th, 2011, 12:49 AM
  5. trouble with GUI
    By MrHardRock in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 7th, 2011, 04:00 PM