Click here to Skip to main content
15,886,815 members
Home / Discussions / Java
   

Java

 
QuestionError Trapping this statement Pin
Member 135080347-Nov-17 2:59
Member 135080347-Nov-17 2:59 
AnswerRe: Error Trapping this statement Pin
Richard MacCutchan7-Nov-17 3:31
mveRichard MacCutchan7-Nov-17 3:31 
GeneralRe: Error Trapping this statement Pin
Member 135080347-Nov-17 5:28
Member 135080347-Nov-17 5:28 
GeneralRe: Error Trapping this statement Pin
Richard MacCutchan7-Nov-17 6:56
mveRichard MacCutchan7-Nov-17 6:56 
GeneralRe: Error Trapping this statement Pin
Member 135080347-Nov-17 7:23
Member 135080347-Nov-17 7:23 
AnswerRe: Error Trapping this statement Pin
jschell8-Nov-17 7:29
jschell8-Nov-17 7:29 
AnswerRe: Error Trapping this statement Pin
ZurdoDev8-Nov-17 7:44
professionalZurdoDev8-Nov-17 7:44 
QuestionPlacing 2DArray Values into x, y locations Pin
Member 135019553-Nov-17 7:35
Member 135019553-Nov-17 7:35 
Hello! I'm having a bit of trouble with 2-dimensional arrays. Currently, I am using netBeans 8.0.

I don't believe I need a loop to do what I'm trying to achieve, but nonetheless I'm stuck. Here is the code for reference:
Java
<pre>
package nb.test.gamepackagev1;
import edu.sjcny.gpv1.*;
import java.awt.Color;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Homework4 extends DrawableAdapter
{   static Homework4 ge = new Homework4(); 

    static Character[][] parade = new Character[4][2];    

    static int[][] aNum = new int[4][2];
    static GameBoard gb = new GameBoard(ge, "Homework 4 by Sam Tahiri");
    public static void main(String[] args) throws IOException
    {
        showGameBoard(gb);
       
        int newX, newY;
        for (int i = 0; i < parade.length; i++) {
            parade[i][0] = new Character[4][2];
            newX = aNum[i][0];
            newY = aNum[i][1];
            parade[i][0].setX(newX);
            parade[i][1].setY(newY);
        }        
        readArray();
        
    }
    
    public static void readArray() throws IOException {
        File fileObj = new File("Array.txt");
        if (!fileObj.exists()) {
            System.out.println("File does not exist");
        }
        else {
            Scanner fileIn = new Scanner(fileObj);
        for (int i = 0; i < aNum.length; i++) { 
            //System.out.println(fileIn);
            int x = fileIn.nextInt();
            int y = fileIn.nextInt();
            System.out.println(x + " " + y);
           
            aNum[i][0] = x;
            aNum[i][1] = y;
//            parade[i].setX(newX);
//            parade[i].setY(newY);            
            for (int j = 0; j < parade.length; j++) {
                parade[i][0].setX(x);
                parade[i][1].setY(y);
            }
        }
        }
        System.exit(0);
    }
//    
//    public void moveAll(Character[] Character) {
//        for (int i = 0; i < aNum.length; i++) {
//            Character[i].setX(aNum[i][0]);
//            Character[i].setY(aNum[i][1]);
//        }        
//    }
    
    public void draw(Graphics g) {
        for (int i = 0; i < parade.length; i++) {
            parade[i][0].show(g);
            parade[i][1].show(g);
        }
    }
    
}


Ultimately, what I would look to do is to place the values of the array aNum[4][2] into each of the 4 objects of parade. The file, Array.txt, has 4 rows of 2 columns, therefore, 4 sets of [x][y] coordinates for the 4 objects I would like to create.

How can I place these values into said objects?
For example, if the first line of the array aNum is 120, 150, then the first object, parade, would be located at (120, 150) on the GameBoard. Thank you so much for helping me out!!
QuestionIS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore3-Nov-17 3:12
Raaz db Bengalore3-Nov-17 3:12 
AnswerRe: IS anybody knows how to convert HTML to XML file USING java Pin
jschell3-Nov-17 6:47
jschell3-Nov-17 6:47 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore3-Nov-17 20:54
Raaz db Bengalore3-Nov-17 20:54 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Richard MacCutchan4-Nov-17 21:09
mveRichard MacCutchan4-Nov-17 21:09 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore5-Nov-17 16:58
Raaz db Bengalore5-Nov-17 16:58 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Richard MacCutchan5-Nov-17 22:09
mveRichard MacCutchan5-Nov-17 22:09 
GeneralRe: IS anybody knows how to convert HTML to XML file USING java Pin
Raaz db Bengalore5-Nov-17 22:19
Raaz db Bengalore5-Nov-17 22:19 
QuestionHi all can anyone solve this for me plz in java Pin
Jbdomnic12321-Oct-17 4:28
Jbdomnic12321-Oct-17 4:28 
AnswerRe: Hi all can anyone solve this for me plz in java Pin
Sascha Lefèvre21-Oct-17 4:40
professionalSascha Lefèvre21-Oct-17 4:40 
AnswerRe: Hi all can anyone solve this for me plz in java Pin
jschell23-Oct-17 7:36
jschell23-Oct-17 7:36 
QuestionCalculator App for order of operations (Android Studio) Pin
Member 1347677620-Oct-17 17:40
Member 1347677620-Oct-17 17:40 
AnswerRe: Calculator App for order of operations (Android Studio) Pin
Richard MacCutchan20-Oct-17 21:54
mveRichard MacCutchan20-Oct-17 21:54 
AnswerRe: Calculator App for order of operations (Android Studio) Pin
jschell23-Oct-17 7:58
jschell23-Oct-17 7:58 
QuestionTrying to develop an app at school using java-mobile app Pin
Member 1347677620-Oct-17 17:03
Member 1347677620-Oct-17 17:03 
QuestionRe: Trying to develop an app at school using java-mobile app Pin
Richard MacCutchan20-Oct-17 21:50
mveRichard MacCutchan20-Oct-17 21:50 
QuestionAnalyze the structure of a class (with package dependence) Pin
Hager.Harald14-Oct-17 12:25
professionalHager.Harald14-Oct-17 12:25 
AnswerRe: Analyze the structure of a class (with package dependence) Pin
Richard MacCutchan14-Oct-17 20:55
mveRichard MacCutchan14-Oct-17 20:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.