Using Datagrams - X And Y Coordinates / Send Back And Forth In One String

Feb 15, 2014

Ok, so I am relatively new to datagrams etc. I have three projects set up right now: Client, Client2, and Server, which all interact with each other to send coordinates of player1 and player2 back and forth (X, Y, this is in 2D space not 3D). I have everything set up perfectly except for one problem: I can only send the X coordinate back and forth for each player. I am getting the weirdest error, a parsing error. The way I communicate is I have everything sent back and forth in one string. Then I use the .split() function to turn that string into an array that contains the x and y coordinates. I've done several tests and to no avail. Here's my code:

Server:

Java Code:

package theGame;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import javax.swing.JOptionPane;
public class Main {
static String p1X;
static String p1Y;

[Code] ....

Lines 177 on Client1 and 172 on client2 are where the debugger is saying that I parsed wrong.

Also, if your are going to test this you will need to have the LWJGL libraries in your build path.

View Replies


ADVERTISEMENT

How To Send User Back To Login Page After A Specific Idle Timeout

Sep 29, 2014

I want to send user back to the Login page after idle time of 10 secs. If user clicks again on screen before 10 secs are over, time will automatically reset to new 10 sec and so on...

I want to use the same timeout on multiple pages.

View Replies View Related

Converting A SecretKey To String And Back Again

Feb 13, 2014

I'm using the class below to encrypt and decrypt data in my program. It works rather well with the exception that I can't for the mind of me get the recreation of the key to work. When the program runs the first time, it creates a key and saves it to Data.txt. This part works fine, and there are no errors, the encryption and decryption works until I reload the program and it tries to recreate the key using the String in the .txt.

read = loadFile.readline();
byte[] data = read.getBytes("UTF-8");
key = new SecretKeySpec(data, 0, data.length, "PBEWithMD5AndDES");

I've looked at:
java - convert Byte Array to Secret Key - Stack Overflow
java - Converted secret key into bytes, how to convert it back to secrect key? - Stack Overflow

and a number of other sites which didn't work, both of these however suggested the key = new SecretKeySpec. The actual key became: "[B@79fe3f51". Whereas the recreated key became: "[B@3e1d1648".So they are close, but not the same.I create the original key like this:

key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);

Encryption.java:

public class Encryption { 
public Cipher dcipher, ecipher; 
// Responsible for setting, initializing this object's encrypter and
// decrypter Chipher instances
Encryption(String passPhrase) {
 
[code]....

View Replies View Related

Converting Strings To XML And Back To String

Mar 3, 2014

I'm stuck with the following error message when i try to convert a String to XML and back to a String.
 
Exception in thread "main" org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
    at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(Unknown Source)
    at com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(Unknown Source)
    at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(Unknown Source)
    at com.innovatrail.consulting.xml.XMLTEST2.main(XMLTEST2.java:66)
 
Below is  my Java code snippet: The code syntactically correct except line 66. If you comment out line 66 in the source code, everything works just fine. The XML representation of my input string is denoted by INPUT 1 and that of my output string is denoted by OUTPUT 2.
 
package com.Test.xml;
 
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;

[Code] ....
 
INPUT 1:

<Collection>
<BookList>
  <Book>
    <Title>Wonder Man
    </Title>
    <Author>John Smith
    </Author>
    <Category>Fiction

[Code] .....
 
OUTPUT 2:

<Collection>
  <Book>
    <Title>Wonder Man</Title>
    <Author>John Smith</Author>
    <Category>Fiction</Category>

[Code] ....

View Replies View Related

Read String To List (Integer) And Back

Feb 14, 2014

I am looking for a good and reliable library to read a string to construct a list of Integers, Doubles, Booleans, etc. This library should be robust enough to handle faulty input from an inexperienced user.

Example:

input: "1, 2, 3, 4"
output List<Integer> [1, 2, 3, 4]

input: "1, 2, 3.6, 4"
output List<Double> [1.0, 2.0, 3.6, 4.0]

input: "true, true, false"
output List<Boolean> [true, true, false]

input: "[1, 2, 3]"
output List<Integer> [1, 2, 3]

input: "(1, 2, 3)"
output List<Integer> [1, 2, 3]

It would be really nice if such a library would already exist.

View Replies View Related

How To Get All Points In X And Y Coordinates Of Arc

Jul 4, 2014

I am planning a race simulator car and I have a problem to get the x and y coordinates from the graph (or circuit). I explain the problem better. If I for example, drawing an arc using the library DRAW2D how do I get all the points in x and y coordinates of that arc?

View Replies View Related

Properties Of A Triangle - X And Y Coordinates

Oct 29, 2014

A triangle is defined by the x- and y- coordinates of its three corner points. Compute the following the following properties of a given triangle: the lengths of all sides, the angles at all corners, the perimeter and the area. The program must prompt a user for the point coordinates. I have created a class Triangle and a class TriangleSimulator, I am stuck and can't figure out why my program won't run correctly.

import java.util.Scanner;
public class Triangle {
Scanner in = new Scanner(System.in);
private int x1;
private int x2;
private int x3;

[Code] ....

View Replies View Related

JavaFX Get Coordinates From Path?

May 8, 2014

I'm working on a project right now in JavaFX, and got stuck. I am drawing a path consisting of CubicCurveTo's and I wonder if there's any way to get the X and Y coordinates from certain parts of that path.

Imagine following a curve (path) with a pencil slowly, and every second you take note the X and Y coordinate. I mean I'm not interested in the control points or start and end points, but the points "in between", preferably at a certain interval.

I've searched for many things online, but have trouble knowing exactly which words to search for. "Paths" often bring up file paths, traversing, coordinates etc. all fail to give me any good results.

I tried to be as specific I could, and I don't think my current code is of any interest in this matter.

(The point of it all is that the path should simulate the path a person walks, and I will store the coordinates in a database for every second).

View Replies View Related

Point Coordinates - X Y Pair

May 8, 2014

What are the x- and y-coordinates of the Points referred to as p1, p2, and p3 after the following code executes? Give your answer as an x-y pair such as (0, 0). Recall that Points and other objects use reference semantics.

PHP Code:

Point p1 = new Point();
p1.x = 17;
p1.y = 9;
Point p2 = new Point();
p2.x = 4;
p2.y = -1;
Point p3 = p2;
p1.translate(3, 1);
p2.x = 50;
p3.translate(-4, 5); mh_sh_highlight_all('php');

P1:

P2:

P3:

My guesses were: P1:(20,10) //Correct

P2:(50,-1) //Incorrect

P3:(0,4) //Incorrect

View Replies View Related

How To Get Coordinates Of Transparent Area In Image

Mar 25, 2015

How to find coordinates of transparent area in the image. I working on .png image which has transparent background and transparent area in the middle of the image. The transparent area in the middle look a like ellipse, so i want to find coordinate of top, bottom, left, and right of that area. I am using opencv.

I have tried to find pixels and from result that i got, i understand that pixel with rgb that equal to 255.0 255.0 255.0 is transparent. what i have in my mind is, if rgb with value that equal to 255 255 255 detected, i will put 1 into arraylist named transparent, and if it not equal to 255 255 255 i will put 0 into the list. So when i look into the list, if there is 1 0 or 0 1 it means that border between transparent area and colored area or vice versa. But, how to know if that border is between transparent area in the middle of image and the image, and not between background and the image. Am i doing this correctly?

Here snippet of code.

Mat imgMask = Highgui.imread(imgfile);
double[] pixels = new double[3];
System.out.println("channel " + imgMask);
for(int x = 0; x < imgMask.cols(); x++) {
for(int y = 0; y < imgMask.rows(); y++) {
pixels = imgMask.get(y, x);

[Code] .....

View Replies View Related

How To Plot Geographic Coordinates In Java

Apr 3, 2014

-7984749.593824852,5368675.690126911 -7984392.035620423,5367570.791302501 -7983220.843257783,5366848.500158152 -7982343.534350842,5364796.5795687605 -7980293.251969412,5363408.488192292 -7980621.978425723,5361760.555707421 -7979175.604281852,5359233.088002191 -7977402.284793513,5358332.850725802 -7976513.843937492,5357665.108234091 -7976472.321767421,5357241.582554582 -7974834.812057852,5357842.933691362 -7973351.925120993,5354420.819505452 -7973743.435770122,5354147.992005592 -7973309.512395002,5352911.428583422 -7973639.9086436825,5352740.575552852 -7972698.034432082,5350359.050518452 -7972255.539456172,5350294.883494262 -7971909.001881332,5349519.720176511 -7970907.683061652,5349775.605440161 -7970575.617020612,5348986.585139751 -7970013.342272613,5349482.445545332 -7969898.683197102,5350177.703443532 -7968337.649977702,5350328.647515352 -7967111.243147633,5351652.264468962 -7966171.150047882,5351373.1018466605 -7966125.286417683,5352115.720678982 -7964626.258154663,5351707.120082232 -7955765.449326492,5345109.379313592 -7954159.443032822,5343966.704795052 -7942364.363746833,5335522.893249432 -7929990.868386692,5326092.063381992

View Replies View Related

How To Draw Points With Coordinates From Database

Jul 23, 2014

I extracted columns from database and made calculations inside while loop. I know i need to make array to get from it coordinates for points. I want to draw them in interface created in another class but i have black hole and don't know how to get datas from while loop to array which is below.

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

Point With X And Y Coordinates - Display Difference Between Them

Apr 26, 2014

//Design/write a class named MyPoint to represent a point with x and y coordinates. The class should contain:

//->Two variables, x and y, that represent the coordinates
//->A no-arg constructor that creates a point (0,0)
//->A constructor that constructs a point with specified coordinates
//->Two getter (accessor) methods for the variables x and y
//-> A method named distance that returns the distance from a point to another point of the MyPoint type
//-> A method named distance that returns the distance from a point to another point with specified x and y coordinates.
//Draw the UML Diagram for the class. Implement the class. Write a test program that creates two points (0,0) and (10, 30.5) and displays the distance between them.

I have written the program but not I have to do it with user input ....

class MyPoint {
private double x;
private double y;
public double getx()
{
return x;
}
public double gety()

[Code] ....

View Replies View Related

Code Is Used To Find Coordinates Of Image

Jan 27, 2015

The code is used to find coordinates of an image and i cannot understand how it works.

for (int y = 0; y < height; y += 2) {
for (int x = 0; x < width; x += 2) {
int px1 = secureRandom.nextInt(4);
int px2 = secureRandom.nextInt(4);
while (px1 == px2)
px2 = secureRandom.nextInt(4);

int px1x = (px1 < 2) ? px1 : px1 - 2;
int px1y = (px1 < 2) ? 0 : 1;
int px2x = (px2 < 2) ? px2 : px2 - 2;
int px2y = (px2 < 2) ? 0 : 1;

View Replies View Related

Buffered Image COORDINATES OUT OF BOUNDS Error

Oct 31, 2014

I am writing a java program that takes a FROM image, a TO image, and a ratio (this is a slide bar in the GUI). Here's my code:
Java Code:

public static BufferedImage rollUp (BufferedImage from,
BufferedImage to,
double ratio) {
BufferedImage finalBufferedImage = new BufferedImage(from.getWidth(),
from.getHeight(),
from.getType());
int packedColor = 0;
for (int r = 0; r < from.getHeight(); ++r) {
for (int c = 0; c < from.getWidth() ; ++c) {

[code]...

So from 0 to 1 (ratio is a double between 0 and 1) the image will "roll up". The effect works completely in the GUI, but the console freaks out at about 0.33 ratio.. This program runs for testing in a class Main and uses a class Splittinimage.. this method is in class TwixPix. When the main class is run, a box pops up with a combo box and a slider. You pick an effect (in this case, roll up) and then slide the slider to set the ratio. The image below those two things performs the effect that was selected. Imagine a PowerPoint presentation slide effect.

View Replies View Related

Coordinates Are Inside Of A Right Triangle On Imaginary Coordinate Plane

May 24, 2014

I'm having a random x and y coordinate generate and I need to check if the coordinates are inside of a right triangle on this imaginary coordinate plane.

View Replies View Related

Transferring Coordinates From Design Program To Array In Java?

Mar 6, 2015

The idea I'd like to present, concerns the correction of "designer" drawings - those done by the design consultants - against "site/construction" drawings - them being used on site by the workers to build the project itself.

This is normally a laborious process, involving being sat at a desk with two large folders, checking each detail and measurement against the design drawing.What I'd like to present is an idea, where the co-ordinates of the design or "mother" drawing, are transferred into a usable Java program, and they could be then used to ensure correct dimensions have been applied by the the sub-contractors in their "construction" drawings.Like I said, this can normally be a process of days for a site engineer to check - process known as "QA, quality assurance".

Basically, I just need to make a presentation of having a genuine interest in Software Design and Development. It could be applied in a range of areas in terms of construction site application - checking drawings, writing up work orders, dig orders etc - but the principle of having the co-ordinates of the mother or "design" drawing scanned into an array in Java as a means to output those site drawings/orders etc, applies to each potential application.

So - in short - and not looking for crystal clear detail, just general pointers - what programs or methods could transfer a plethora of co-ordinates from a design program like Auto-Cad, to a Java program, where I assume I would then be using a program containing a complex series of loops to ensure the correctness of the derived "construction" drawings; derived from the "mother" or designer drawings, that is.

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

Enter Radius Of Bounding Circle And Display Coordinates Of Five Corner Points On Pentagon

May 29, 2014

(Corner point coordinates) Suppose a pentagon is centered at (0, 0) with one point at the 0 o’clock position. Write a program that prompts the user to enter the radius of the bounding circle of a pentagon and displays the coordinates of the five corner points on the pentagon. Here is a sample run:

Enter the radius of the bounding circle: 100
The coordinates of five points on the pentagon are
(95.1057, 30.9017)
(0.000132679, 100)
(-95.1056, 30.9019)
(-58.7788, -80.9015)
(58.7782, -80.902)

What we know , we know both the radius of the circle(user inputted) and the side of the pentagon from formula (double side = 2 * radius * Math.sin(Math.PI/5)) .We also know that one point is (0 .100) Also i know that the distance between 2 points is Math.sqrt(Math.pow(x1 - x2 ,2) - Math.pow(y1 -y2 ,2)) .

There might be other ways to solve it but this is my best bet trough i dont remember how to solve linear equations of the form x^2 + y^2 = - radius and radius ^2 = x^2 + (y - 100) ^ 2..

The solution i found is using the radius from the center to the point we want to find out and using the radius to the point we already know ( 0 .100) but i have to solve that damn equation first ...

View Replies View Related

How To Get Object From Panel Back Across To GUI

Jul 6, 2014

I've been putting together an addressbook and try to work on some idea but I have hit a bit of a wal early on, and Im sure the problem is easy to resolve, I just can't get the old brain to do it.At present I have 5 classes

PersonDetailsAdressDetailsAddressBookAddressBookGUIEnterDetailsPanel

I have taken EnterDetailsPanel out of the main GUI code, as I plan, or had planned on using additional JPanels for the other options of the application until I got stuck. What I want the EnterDetails panel to do, which it does so far is to have the user enter all of their information and when the button is pressed it will then create a PersonDetails object and here is where my problem is. how to get the object from the panel back across to the GUI which initalises the AddressBook class in the constructor and add it to the List via an addDetails() method.

If I create a quick method in the AddressBookGUI class I can add the object to the List fine, I'm guessing this is because I have created a new instance of the AddressBook in here already via the constructor, however if I add an AddressBook reference in the EnterDetailsPanel I get a nullpointerexception for the opposite because it's not been created in there.These are what most of the classes do so far.

PersonDetails has a reference to the AddressDetails and holds all information for that person.AddressBook contains a List that accepts PersonDetails and has methods to add/remove the person.AddressBookGUI creates a new instance of the AddressBook class along with the general gui things. EnterDetailsPanel is added to JTabbedPane in the GUI class and allows the user to enter their details and submit those via a button which will then create a new PersonDetails object that I am trying to get added to the AddressBook class List

View Replies View Related

How To Get Information Back From A Different Method

Nov 12, 2014

I am trying to figure out how to get information back from a different method.

Basically I want to write a program to create a car, but I want to be able to add features based on user our put (V6 versus V8, Color choice, etc), but I want each one to be broken out into their own method but I am unsure of how to call from the main method and return the variable (engineSize = V8, color = blue, etc).

View Replies View Related

JSP :: Disable Back Button When Logout

Apr 19, 2014

I have a website which requires login. After I enter username and password and click login button, a new page is loaded. In that page I have a username in the right up corner. When the user clicks logout button, Session.Clear() method is called and also Response.Redirect(" to login page "). It works OK, but the problem appears when I then click Back button in the browser. It gets me back to previous page with the username in the right up corner. Insted, I would like to show message asking user to enter password again so he can login properly.

What should i do at client side???

View Replies View Related

Swing/AWT/SWT :: Looping Back To JOptionPane

Apr 28, 2014

how to have an application restart if the user inputs an incorrect integer in a JOptionPane question? I know how to do it with the Scanner class but nothing I do seems to work. This is the beginning of my code:

import javax.swing.JOptionPane;
public class Pay {
public static void main(String[] args) {
String level = JOptionPane.showInputDialog("Please select your skill level: 1, 2, or 3");
int levelPick = Integer.parseInt(level);

[code]...

View Replies View Related

JRE :: Date Shifting 1 Day Back On 1 Of Many Systems

Feb 24, 2014

This piece of java software I am responsible for is running throughout numerous locations in my country, there is only 1 location which has trouble with the dates being displayed incorrectly, birthdates of clients are displayed as a day earlier. It seems pretty safe to say it is a problem on their end... But still, they're asking me for an explanation as to why java would treat a date differently in this rare case.

The date (a birthdate) comes from an oracle database, it is a date without a time (trunced date). It enters the application as a member of the client-class, it is NOT being set or changed after that. It goes through several layers in the application, then ends up in a GUI class which unwraps it from the "client"-object and puts a SimpleDateFormat (new SimpleDateFormat("dd-MM-yyyy")) on it. My first and only hunch was the timezone settings, but that seems to be OK!

View Replies View Related

JSF :: Reset Values In Back Form Bean

Jun 3, 2014

When we have a jsf form to store clients in a ddbb for example and the backing bean is in session scope.... Lets think of a user that requests 3 times the xhtml view with the form to store 3 clients.

1) If we dont reset the backing bean each time the form is processed, he would see the values he sent beforea and it doesnt have much sense, right?

2) Here there is an example of clearing form after submitting : [URL] ...... Clearing the form after submititng is a common practice for the reason of the statement 1, right?

3 ) What is the best or normal approach to reset values in a form? when the user requests it or done automatically by the application after processing a form?

4) Are there known issues about resetting or not resetting the values in a form bean?

View Replies View Related







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