Drawing A Square In Quadrant I Grid - Axis Not Display Properly

Feb 3, 2015

Currently, I am trying to create a program that draws a square anywhere in a 15x15 Quadrant I (Coordinate plane) grid. I am stuck on trying to get the axes displaying correctly. This is the code I have thus far:

import java.util.Scanner;
public class Question2square {
public static void main(String[] args) {
// Axis variables
int yAxismin = 0;
int yAxismax = 15;

[Code] ....

Unfortunately, instead of drawing the 'L' shaped axes I desire, it displays an 'r' shape instead. I'm trying to figure out how to display the axis properly. I tried flipping the for loops but that didn't work. I don't see what else could be inhibiting this.

View Replies


ADVERTISEMENT

Diamond In A Square Grid Of Dots

Nov 14, 2014

I am new to java and i am trying to make a Java application which prints a diamond in a square grid of dots whose side length is input to the application.When you run the code is should be like this:

..*..
.*.*.
*...*
.*.*.
..*..

My java code print this:

..*..
.***.
*****
.***.
..*..

Here is my code:

class Main {
public static void main(String args[]) {
System.out.println("#Enter size of Diamond :");
int longestRow = BIO.getInt();
for(int row=1 ; row<=longestRow ; ++row)

[Code] .....

View Replies View Related

Print Table (array) Where Have X Axis And Y Axis?

Apr 12, 2015

I want to print a table (array) where I have an X axis and a Y axis. 16x11. My code is as follows:

int Windchill [] [] = new int [16][11];
{
{60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0, -5, -10, -15} //X
{0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50} //Y
};

The code doesn't work even though it's similar to

int Windchill [][] =
{
{60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0, -5, -10, -15}, //X
{0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50}, //Y
};

if I remember correctly, the 2 are correct just written in different ways.

and I want it to print like this

{60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0, -5, -10, -15},
{ 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
5, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
10, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
20, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
25, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
30, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
35, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
40, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
45, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,
50, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0,}

where 0 is null (for now). I want to fill those in with a formula later, but I don't hardcoding them one by one is the most "efficient" way to do it

View Replies View Related

How To Attach OpenGL Display To JFrame And Dispose Off It Properly

Nov 12, 2014

How can i attach the OpenGl display to a JFrame and so that when i close the JFrame is destroys the display? Here is my code so far:

package test.core;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.WindowAdapter;

[Code] .....

I had the opengl display attach to the JFrame before i did the runnable. But after adding the runnable the display now shows up the same size as my screen size. I have tried rearranging the

canvas.setSize();
and the
frame.setSize();

but nothing changes the opengl display is still the same size and when i try to close the JFrame first rather then close the display first i get this error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: From thread Thread[AWT-EventQueue-0,6,main]: Thread[main,5,main] already has the context current

which points me to my

Display.destroy();

which im guessing is telling me that i am not properly disposing the display? How to attach the opengl display to the JFrame and fix the error above?

View Replies View Related

Creating Cursor For A Game That Moves Square By Square - Removing Trailing Images

Aug 31, 2014

I'm trying to create a cursor for a game that moves square by square. While it will move to the next square, though, it leaves the image of the previous cursor on the last square it was on.

As a visual explanation, this is what the program looks like on launch:

This is what it's suppose to look like after you press the right arrow key once (made by forcibly changing launch coordinates):

And this is what it actually looks like after you press the right arrow key once:

Here is the code for the program:

package cursortest;
import javax.swing.*;
import java.awt.*;
import javax.imageio.*;
import java.io.*;
import java.awt.event.*;
public class CursorTest extends JPanel implements KeyListener{

[Code] ......

I'm fully aware that I could just use g.clearRect on the area and remove it for sure, but I know for a fact I shouldn't have to as I have another program I made a long time ago that tried to do something similar without needing to resort to that.

View Replies View Related

How To Compare Square Of The Square Root Of Any Number

Feb 20, 2014

How would I compare the square of the square root of any number. The difference in these values is due to the rounding error in Java.

Example: Enter number 2

The answer I should get is: 2.000000000000004
Round off error: -4.440892

View Replies View Related

Moving Object In Y Axis

Jul 10, 2014

I just have one problem with a "car" program in java. The objective is to move the car in the direction it is facing. Moving forward in the normal position (when the angle is zero) means moving in the x-axis. Choosing to turn the car function (for example: 90 ) and then using the forward function should move up or down the car in the y-axis. However the y-axis is not working.

Car2 Demo.rar
JPGMoveforwardfunction.jpg

View Replies View Related

Pong Game - Y Axis Collision Detection

Jan 28, 2014

I have made a "Pong" game and how to check if the ball has hit the top or the bottom of a paddle, however I do know how to check if it has hit the left or right side:

Java Code:

if((BALL.getX() >= LEFT_BAT.getX() && BALL.getX() <= LEFT_BAT.getX() + LEFT_BAT.getWidth()
&& BALL.getY() >= LEFT_BAT.getY() && BALL.getY() <= LEFT_BAT.getY() + LEFT_BAT.getHeight())
&& (BALL.getX() >= RIGHT_BAT.getX() && BALL.getX() <= RIGHT_BAT.getX() + RIGHT_BAT.getWidth()
&& BALL.getY() >= RIGHT_BAT.getY() && BALL.getY() <= RIGHT_BAT.getY() + RIGHT_BAT.getHeight())){
BALL.increaseDX();
BALL.setDX(-BALL.getDX());
} mh_sh_highlight_all('java');

It seems as though I would use the same code for checking the top or bottom.

View Replies View Related

JavaFX 2.0 :: Chart Axis Changing Color

Mar 20, 2015

I'm struggling to change the colour of the X and Y axis. I can change the colour of the ticks and the tick labels in CSS... But not the axis themselves.

View Replies View Related

JavaFX 2.0 :: Panel Effect - Rotation Along Its Y Axis

Dec 14, 2014

I have a UI widget, like a table view for example, displaying real-time data. This table can be configured - so it has many properties. The way I would like to do so, is to have a small 'configure button', once clicked, would rotate the entire table along its y axis, and display another panel with checkboxes etc... So effectively, the hidden properties panel is revealed by rotation.

View Replies View Related

Which Axis To Increment / Decrement With Inclusion Of Speed Variable

Jan 30, 2015

if I move object A to one area of the screen I want object B to to move to object A's location but I also want object B to move at a fixed speed (movement variable). How do I go about doing this? Both the x and y coordinates of object B would need to know the coordinates of object A to calculate the distance between the two and to determine how much of which axis to increment/decrement (if that makes sense?) with the inclusion of the speed variable.In other words I'm just trying to create a homing object.

View Replies View Related

Swing/AWT/SWT :: Java2D Graph Plotting - Divide X And Y Axis With Frequencies

May 29, 2014

I am using Java 2D API to implement Graph plotting. I am able to transform and scale the origin upright.

Now, I need to divide the x & y axes with frequencies (Ex: On Y-axis: 0 10 20 30 40 etc ..) and then plot points (Ex: [34, 54] etc) accordingly.

Which methods to use or way out to make this implementation?

View Replies View Related

Vector Math - Calculate Equation Of A Plane That Would Rely On All Axis

Jan 27, 2014

I am running into some trouble with Line-Plane intersection, my method works, provided I am perpendicular to the plane I want to intersect. This is caused be the plane equation (with my given x, y, and z coordinates, the equation is -Z - 1 = 0). So the equation is only relying on the Z value of anything inputted. Is there another way to calculate the equation of a plane that would rely on all axis? Here is my current code:

Java Code:

Vector3f A = new Vector3f(0, 0, -1);
Vector3f B = new Vector3f(0, 1, -1);
Vector3f C = new Vector3f(1, 1, -1);

Vector3f v1 = new Vector3f(B.x - A.x, B.y - A.y, B.z - A.z);
Vector3f v2 = new Vector3f(C.x - A.x, C.y - A.y, C.z - A.z);

float[] i = new float[]{v1.x, v2.x};
float[] j = new float[]{v1.y, v2.y};
float[] k = new float[]{v1.z, v2.z};

[Code] ....

View Replies View Related

Calculate Distance Between Two Coordinates And Determine How Much Of Which Axis To Increment / Decrement

Feb 1, 2015

Basically I'm looking for a way to make one object follow another. For example, if I move object A to one area of the screen I want object B to to move to object A's location but I also want object B to move at a fixed speed (movement variable). How do I go about doing this?

Both the x and y coordinates of object B would need to know the coordinates of object A to calculate the distance between the two and to determine how much of which axis to increment/decrement (if that makes sense?) with the inclusion of the speed variable. In other words I'm just trying to create a homing object.

View Replies View Related

JavaFX 2.0 :: BarChart Axis Tick-labels Missing With JDK1.8

Jul 10, 2014

Currently I try to integrate a JavaFX BarChart into my existing Java application. Therefore I need a BufferedImage of my BarChart, so that I can render that snapshot on a Graphics instance.
 
I adapted the existing BarChartSample.java (Chart Sample | JavaFX Tutorials and Documentation) and removed all animations. The code itselfs works fine but I identified one problem -> my TickLabels are missing
 
The TickLabels are visible If I use JDK 1.7u51 but if I change to JDK 1.8u05.... than the stlye of my BarChart will be changed and my tick labels are not visible.
 
Did I missed something or is that a bug?
 
using JDK 1.7u51
[URL] .....
 
using JDK 1.8u05
[URL] .....
 
My adapted code is the following:

package barchartsample;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

[Code] .....

View Replies View Related

Grid Bag Layout / Constraints

Jan 13, 2015

I am making a basic calculator using SWING.I want my JTextField to stretch across the top, above my buttons. All I can seem to get is it be the same size as one of my buttons.

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

[code]...

View Replies View Related

Grid Layout Implementation

Mar 13, 2014

How to implement GridLayout. In my applet, I want to make a grid of 2 rows and 2 columns. In each grid I want to add a Label and a TextField. I want the background to be red.

So my code would be?

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class GridLayoutApplet extends Applet implements ActionListener{
// construct components
Label fNameLabel = new Label("First Name");
TextField fNameField = new TextField(20);

[Code] .....

I have read about panels and frames but, it is all confusing to me. How can you add a label and a TextField to one square of the grid?

View Replies View Related

Check Around Cell In Grid

Nov 22, 2014

I am currently trying to write a method for checking to see if an "agent" in a cell (place in a 2d array) is satisfied. So, the assignment is a 2D array that can have a blank space, an O, or a X as a character that fills a particular space. An agent is satisfied if it has similar characters around it in a percentage that is higher than the threshold. For example, if the threshold was 60% and a cell that had an X in it, had 3 X's around it and 2 O's, then it would be satisfied because 3/5>=60%. For my code, I tried using if and else statements to isolate circumstances in the corner of the grid, the edges, and everything in between.

public static boolean isSatisfied(char[][] tissue, int row, int col, int threshold){
char check= tissue[row][col];
if (check==' '){
return true;
}
else{
int countx = 0;
int count = 0;

[Code] ....

View Replies View Related

Calculator Grid Layouts

Aug 19, 2014

So I'm making a calculator using JFrame and that stuff and I need figuring out the GridLayouts. I'm not doing this for homework or anything just for fun. I don't need all the grid layouts.

View Replies View Related

Binary Search - Get To Int X Int Y In A Grid That Is N By N

Sep 15, 2014

The point is to use a binary search to determine how many steps it would take to get to int X, int Y in a grid that is N by N. Picture a parking lot that is square and your car is at (x,y). You can honk your horn from your key to determine the direction of the car. I need to return the amount of steps to get to the car. You can't step diagonally. I am currently getting an error that causes an infinite loop and I can't fix it.

public class ParkingLot {
public int search(int N, int X, int Y) {
int minX = 0, maxY = N, minY = 0, maxX = N;
int num = 0;
int curX, curY;
int newCurX, newCurY;
curX = (minX + maxX)/2;
curY = (minY + maxY)/2;
while (curX != X || curY != Y)

[code]....

View Replies View Related

How To Make Grid For Battlefield Game

May 27, 2015

I wanted to know which RAD TOOL should I use to make the grid. I used the label but it's not interesting like the game *. I m starting to make the game and can't think how to make the grid.

Thought of using the buttons but can't add image to it.

what should I use to make the grid.

* what I did earlier Is place 9 label in grid form (just to test) and nine buttons one for each. When u click a button, image is shown in respective label... But it doesn't feel like u r playing game..

View Replies View Related

Can't Change GridWorld Grid During Runtime

Jun 5, 2014

I have a question about updating a grid during runtime in GridWorld. I'm making a game called Flood-It (basically, you click on squares to change their color and attempt to get all of the squares the same color in the grid) and I'm having trouble with changing the grid size. I made my own world class, called CellWorld.

import info.gridworld.actor.*;
import java.util.ArrayList;
import info.gridworld.grid.Location;
import java.awt.Color;
import javax.swing.JOptionPane;

[code]...

Now, let me narrow down the issue. It is in the runner class:

world.setGrid(new BoundedGrid<Actor>(world.getLength(),world.getWidth()));

Whenever a user wants to change the grid size after playing the game, this is supposed to set the grid to the new updated size, but it never changes in the actual game, i.e. the user just won a 2x2 game, attempts to change the size to 10x10, but the grid stays 2x2. By debug testing, I can say for certain that everything else works, such as the maxStepCalc and loading the grid. The only issue is the new grid not showing up.

View Replies View Related

RTS Game - Grid System And Tilt?

Mar 28, 2014

I am making a RTS game in Pure Java, and no libraries. So pretty much I want a constructor like so

Java Code: new Grid(40, 40) mh_sh_highlight_all('java');

That will create a 40x40 grid of a certain size per cell. Then I would like to fill the empty cells, and also be able to place things on top of them.

Also, I would like a tilt similar to Clash of Clans. How do I do this?

View Replies View Related

JLabel To Grid Layout On A Panel

Nov 19, 2014

Is it possible to put Jlabels in to a grid Layout on a Panel in a Jinternal frame

View Replies View Related

Code To Move Object In Grid

Aug 22, 2014

Working with some code that displays the random movement of an object such as Move 1: (0,1) Move 2: (10,99)?

I need these methods in the class

void initialize( int xPos, int yPos)
void moveLeft()
void moveRight()
void moveUp()
void moveDown()
int getXPosition()
int getYPosition()

View Replies View Related

How To Create Coordinates In Two-dimensional Grid

Mar 16, 2015

how to create coordinates in a two-dimensional grid, in the end it shall look like A5, F6 and so on. The aim is to place 3 DotComs in this grid by coincidence. To do this one uses two arrays. One array represents one DotCom, the other represents the grid's size, in this case 49 (7x7).The code ends like this:

ArrayList<String> alphaCells = new ArrayList<String>();
...
int x = 0;
int row = 0;
int column = 0;
while (x<comSize) {
grid[coords[x]] = 1; // mark master grid points as used
row = (int)(coords[x] / gridLength);
column = coords[x] % gridLength;
temp = String.valueOf(alphabet.charAt(column));
alphaCells.add(temp.concat(Integer.toString(row));
x++;
}
return alphaCells;
}

why row and column are calculated like this. Furthermore I don't understand why the column is used to generate a character, because columns are marked with numbers and rows are marked with characters.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved