Hi I wanted to draw a field like this photo which I have attached. I would appreciate your help. I have wrote so much now: for (int x = 2; x < 12; x++) { for (int y = 2; y <= 12; y++) { g.drawRect(40*x, 40*y, 40, 40); } } ![a61a6705a7f76105f8ebab3b38dd9dcd](/attachments/large/3/a61a6705a7f76105f8ebab3b38dd9dcd.jpg "a61a6705a7f76105f8ebab3b38dd9dcd")

Member Avatar
Member Avatar
+0 forum 3

Heya guys, i have been trying to make this very famous ball game using java swing. although the primary code ihave used is from this link [[Click Here](http://www.edu4java.com/en/game/game6.html)](null)but been trying to modify it to make it look less complex..But everytime i run it it gives me following error: Exception in thread "main" java.lang.NullPointerException Exception in thread "main" java.lang.NullPointerException at ballGame.Ball.collision(mainGame.java:209) at ballGame.Ball.move(mainGame.java:196) at ballGame.mainGame.main(mainGame.java:65) so, plz can anybody help me with this?? package ballGame; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JButton; …

Member Avatar
Member Avatar
+0 forum 9

Hi everyone, i need your help.. I want to draw a circle,square and rectangle on Jframe on a click of a button.. This program was asked in my test paper, i couldn't get it right though bt i wanna know what my mistake is.. Plz help me.. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class CRS extends JFrame implements ActionListener { JButton b1,b2,b3; Graphics g; Container con; public CRS() { super("Draw Circle in JFrame"); con=getContentPane(); con.setLayout(new FlowLayout()); b1=new JButton("Circle"); b2=new JButton("Rectangle"); b3=new JButton("Square"); con.add(b1); con.add(b2); con.add(b3); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); } public void Circle() { g.drawOval(50,50,100,100); } public void Rectangle() { …

Member Avatar
Member Avatar
+0 forum 1

Hello good day. I am trying to figure out if it is at all possible for me to do but I want to access the area that is outside the JScrollPane's view when my JFrame is resized. Let me explain; I have a LayeredPanewith two layers within a JscrollPane. The Second layer's visible content is off to one side so that it looks like a dock. When I click it, it slides left, on to the screen and vice versa when clicked again. This works well as long the window is maximized. However once the JFrame resizes (shrinks), this second …

Member Avatar
Member Avatar
+0 forum 3

So im making an RPG. For collision detection, I thought I would do it like this: 1. Read text file containing collision data. 2. Iterate through the list using nested for loops. 3. When a value of 1 occurs (denoting an inpassable tile) add a rectangle to list 'badTiles', where the x and y pos of the rectangle is the x and y value from the nested for loop times the tile width and height. 4. Now that all bad tiles are stored in a list of rectangles, we can check for collision. 5. In player class, perform a foreach …

Member Avatar
Member Avatar
+0 forum 9

I am trying to find an area center of various types of rectagles. (Center of gravity and midpoint of 4 ertices never work so please think in different way) Please see this image: http://img22.imageshack.us/img22/7881/rectangles.jpg I have to position of red dot ` Point vertices[4]; Point areaCenter; ` I have to find areaCenter so (nearly) area(areaCenter, vertices[0], vertices[1]) = area(areaCenter, vertices[1], vertices[2]) = area(areaCenter, vertices[2], vertices[3]) = area(areaCenter, vertices[3], vertices[0]) I tried many different ways to find the mid point but none of them covered every types of rectangles. Can any1 give me some idea?

Member Avatar
Member Avatar
+0 forum 2

Hi again and thanks in advance ! Last question ! I have to create a class called polygon (not normal) that has in private the number of sides and the length of each side and in public that has 2 constructors (the one has as variables the number and each length (how is that possible), getlength (perimeter) , setpolygon , getedge (of a k side) . Also then i have to make a subclass called rectangle that has constructor with length,height getlength again ,getarea ... What does rectangle inherits from polygon ? Here's the code of the polygon class but …

Member Avatar
Member Avatar
+1 forum 2

[I]Create a program called, Containment, that accepts three command line arguments, a file that contains a list of shapes, and a pair of numbers the specifies the (x,y) coordinates for a point. The program should print out the list of shapes, and a true/false value that indicates if the point is contained in the shape. The shapes file contains one shape per line. An example of the file with all the possible shapes is: rect "r1" 20.0 5.0 50.0 25.0 ellipse "e1" 0.0 0.0 5.0 3.0 polygon "p1" 20.0 0.0 40.0 0.0 40.0 20.0 20.0 20.0 There are three possible …

Member Avatar
Member Avatar
+0 forum 8

I'm trying to create a filled and unfilled rectangle class. I can easily create the filled, but the unfilled one is giving me a little difficulty. Whats going on? [CODE] void Rectangle::drawrec() { if (filled == true) { for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { cout << "*"; } cout << endl; } } else { for (int row = 0 ; row < height; row++) { for (int col = 0 ; col < width ; col++) { if (height != width) cout << " * …

Member Avatar
Member Avatar
+0 forum 1

Hello people I have a JFrame which container is a JPanel: can you give me a piece of code that shows how to create a grid of rectangles ? I need this information for my poject Thank you

Member Avatar
Member Avatar
+0 forum 4

Hi I am trying to make a program that prints a snooker board on the screen. I am trying to print the different parts on top of each other. So far all I am able to do is print the background. when i try to print the cloth on top of that only the cloth prints. Here is the code: [CODE]package table; import javax.swing.*; import java.awt.*; public class Table_drawer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setSize(800, 450); frame.setTitle("Snooker"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Background background = new Background(); Cloth cloth = new Cloth(); frame.add(background); frame.add(cloth); frame.setVisible(true); …

Member Avatar
Member Avatar
+0 forum 3

Hey guys! I am new at Class and object things. Before introducing the object oriented issues my life was easier! I wrote these codes here: /*--------------------------------------------------------------------------------------- Source File: OOP4.Henri.cpp Program name: Object Oriented program, Assignment 4 Author: Hassan Aghaei Baradaran (Henri) Compiler: Bloodshd Dev-C++ 4.9.9.2 Purpose: To define and demonstrate a class representing a Rectangle -----------------------------------------------------------------------------------------*/ #include <stdlib.h> // system pause #include <iostream> // input output #include <string> // to use string class #include <iterator> // used for line_maker function #include <sstream> // used for line_maer function using namespace std; class Rectangle // CLASS DEFINITION { private: int height; // …

Member Avatar
Member Avatar
+0 forum 10

Hi, I want to draw some rectangles with the same size and different colors by using an array but don´t know exactly how to do it in the for-loop. Thanks for help! [CODE]class Figure { private: int **figur; int row,col; public: Figure() : row(5), col(20){ } void allocate_place(int r, int c) { this->figur = new int *[r]; for (int i=0; i < r; i++) this->figur [i] = new int [c]; this->row = r; this->col = c; } void drawing_figure(BITMAP *buffer) { for (int i=0; i < this->row; i++) { for (int j=0; j < this->col; j++) { //rectfill(buffer, fig1x, fig1y, …

Member Avatar
+0 forum 0

Hi, I want to draw some rectangles with the same size and different colors by using an array but don´t know exactly how to do it in the for-loop. [CODE]class Figure { private: int **figur; int row,col; public: Figure() : row(5), col(20){ } void allocate_place(int r, int c) { this->figur = new int *[r]; for (int i=0; i < r; i++) this->figur [i] = new int [c]; this->row = r; this->col = c; } void drawing_figure(BITMAP *buffer) { for (int i=0; i < this->row; i++) { for (int j=0; j < this->col; j++) { //rectfill(buffer, fig1x, fig1y, fig1x+30, fig1y+30, makecol(0, …

Member Avatar
+0 forum 0

I recently made a switch to SDL as a cross platform alternative to directly accessing DirectX or OpenGL. In an attempt to port a section of my game framework, I encounter logic errors that (to me) make absolutely no sense. In this snippet, a sprite is simply a wrapper class for an image and a collection of rectangles that makeup sub-images. [CODE] // sprite.h class Sprite { private: SDL_Surface* surface; SDL_Rect* frames; public: SDL_Surface* GetSurface(); SDL_Rect* GetFrame(int index); Sprite(SDL_Surface* surface, SDL_Rect frames[]); ~Sprite(); }; [/CODE] [CODE] // sprite.cpp SDL_Surface* Sprite::GetSurface() { return surface; } SDL_Rect* Sprite::GetFrame(int index) { if (frames …

Member Avatar
Member Avatar
+0 forum 1

Python programming can have its lighter moments. Here we use one of those moments to draw an optical illusion using the Tkinter canvas to draw a rectangle, some lines and circles.

Member Avatar
+2 forum 0

The End.