Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:00:51+00:00 2026-06-05T00:00:51+00:00

//I am trying to create a basic race car in java. I made a

  • 0

//I am trying to create a basic race car in java. I made a rectangle for the body and now I am trying to make a triangle for the front. I looked online for code on creating a triangle but none of it looks like it is in the format as I have for the rectangle I have below. I got most of this code from “Video Game Programming for the Evil Genius” as a reference and now we are encouraged to create our own vehicle, but rectangles are the only shapes explained. I did copy the code from the rectangle to triangle expecting one to overlap the other, just so that I knew it worked, but it’s not. Would anyone be able to explain to me how to make a triangle and possibly a circle? Also is there anyway of doing this without having to create another class?

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class Vehicle extends JFrame

 {
    final int WIDTH = 900; int HEIGHT = 650;

    Rectangle p1Body = new Rectangle(WIDTH/9,HEIGHT/2, WIDTH/30,WIDTH/30);
    Triangle p1Front = new Triangle(WIDTH/9,HEIGHT/2, WIDTH/30,WIDTH/30);

    Rectangle p2Body = new Rectangle(((WIDTH/9)+((int)((WIDTH/9)*1.5)/2)),(HEIGHT/2)+ 
    (HEIGHT/10),WIDTH/30,WIDTH/30);


public Vehicle()
    {
        super("Radical Racing");
        setSize(WIDTH,HEIGHT);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);

}
public void paint(Graphics g)
{
    super.paint(g);

    g.setColor(Color.DARK_GRAY);
    g.fillRect(0,0,WIDTH,HEIGHT);

    g.setColor(Color.BLUE);

    g.fill3DRect(p1Body.x,p1Body.y,p1Body.width,p1Body.height,true);
    g.setColor(Color.BLUE);
    g.fill3D(p1Front.x,p1Front.y,p1Front.width,p1Front.height,true);


    g.setColor(Color.red);

    g.fill3DRect(p2Body.x,p2Body.y,p2Body.width,p2Body.height,true);

}


public static void main(String[]args)
    {
        new Vehicle();
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:00:53+00:00Added an answer on June 5, 2026 at 12:00 am

    Triangle can be done using Path2D(.Double) circle can be done using Ellipse2D(.Double)

    BTW, you might want to think about combining all of these shapes into one using Area – http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Area.html. Area is very useful for manipulating shapes & testing if they contain a point etc.

    Check out Graphics2D.draw (or fill) (Shape)

    http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2D.html#draw(java.awt.Shape)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a basic Pacman game in C++ (I'll use Java syntax
Right now I'm trying to create a basic tic tac toe game. Before I
I'm trying to create a 'skeleton' framework of sorts for a basic java app.
I am trying to create a basic depth first search based web crawler. Here
I'm trying to create a basic version of this example in CoffeeScript: http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/ .
I am trying to create a basic pricing table. The table can be of
I'm trying to create a basic shopping cart, having an issue with the product
I'm trying to create a basic database trigger that conditionally deletes rows from database1.table1
Question I'm trying to create a basic wxWidgets program with a text entry box,
I am trying to create my own basic form validation without having to resort

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.