Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 4th, 2006, 3:25 PM   #11
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3 Harakim is on a distinguished road
When you are done with this, if you wouldn't mind sending me the code I'd like to look at it. I still think you should use Serialization. Since I can't compile it, I would probably write some buggy code.
Harakim is offline   Reply With Quote
Old Jun 4th, 2006, 4:56 PM   #12
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Quote:
Originally Posted by Harakim
For one, I think this line of code:
268:   tetPiece [pieceCounter].setFilledPiece (xLen, yLen, true);
will give a NullPointerException for reasons mentioned by TitaniumDecoy.
It was actually Arevos who mentioned that. :p
titaniumdecoy is offline   Reply With Quote
Old Jun 4th, 2006, 7:13 PM   #13
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
another error from code

Another problem in my code is that I'm not able to send array information between classes. I've created a sample program: Would anyone be able to fix this program so that it actually returns the array?

In c++, I would just send a pointers/refferencea to my array and into the class method. In java is there anyway I can have a pointer to my array in ArrayCollect, and bring that pointer into ArrayData. Or does this work with by fixing the syntax errors?

 Edit**
class ArrayData
{
    int someInt [] = new int [1];

    public ArrayData ()
    {
        someInt = new int [3];

        for (int i = 0 ; i < 3 ; i++)
        {
            someInt [i] = (5 * i) + 1;
        }
    }


    int getInt ()
    {
        return someInt [];
    }
}
class ArrayCollect
{
    public static void main (String [] arguments)
    {
        ArrayData tempData = new ArrayData ();
        int yeint[] = new int[3];
       yeint[] = tempData.getInt ();
  
    }
}
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old Jun 4th, 2006, 10:51 PM   #14
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
int getInt ()
    {
        return someInt ;
    }
That should do it.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Jun 5th, 2006, 3:59 AM   #15
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Small correction:
int[] getInt()
{
    return someInt;
}
Arevos is offline   Reply With Quote
Old Jun 5th, 2006, 5:19 AM   #16
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
Thanks Arevos, I should pay more attention damnit.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Jun 5th, 2006, 8:17 PM   #17
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Thanks for all your help. Somethings in my mind though: In c++ you can pass pointers and refferences into a funtion. So in java is there any simple way to do this? I searched the forums and found "event methods", wow I don't want to get into that. Therefore, this can't be done as it can in c++ can it (create a refference to an object)?

Here's a little example I Found.

#include <iostream>
 #include <stdlib.h>
 

 void swap(int &x, int &y);

 

 int main()

 {

     int x = 5, y = 10;

 

     std::cout << "Main. Before swap, x: " << x 

                                 << " y: " << y << "\n";

     swap(x,y);

     std::cout << "Main. After swap, x: " << x 

                                << " y: " << y << "\n \n \n";
                                
    int x2 = 30, y2 = 40;
    std::cout << "Main. Before swap, x: " << x2 

                                 << " y: " << y2 << "\n";

     swap(x2,y2);

     std::cout << "Main. After swap, x: " << x2 

                                << " y: " << y2 << "\n";
    system("Pause");

     return 0;

 }

 

 void swap (int &rx, int &ry)

 {

     int temp;

 

     std::cout << "Swap. Before swap, rx: " << rx 

                                 << " ry: " << ry << "\n";

 

     temp = rx;

     rx = ry;

     ry = temp;

 

     std::cout << "Swap. After swap, rx: " << rx 

                                << " ry: " << ry << "\n";


 }

Quote:
Source: "Sam's teach yourself c++" by Jesse Liberty
And if the answer is "No java can't do that", wow i'm in a state of shock.


Now back to finishing this tetris game.
__________________
Death smiles at us all. All a man can do is smile back.

Last edited by Eric the Red; Jun 5th, 2006 at 8:36 PM.
Eric the Red is offline   Reply With Quote
Old Jun 6th, 2006, 1:12 AM   #18
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3 Harakim is on a distinguished road
This is a horribly complicated subject for me to explain, but I'll try.

If I understand you correctly, you want to pass the array and modify it and not have to return it. In Java, you can do this the same way as C++.

The references/pointers you pass in Java/C++ pass by value. They are numbers.


Just for sake of an example:
char *temp = new char[x];
foo( temp );

void foo( char *ptr )
{
	ptr = new char[y];
}
`temp` still points at "new char[x]". Why?
I'll just show you a simplified example with sample addresses. It would probably help if you kept track on paper.
char *temp;
temp is created at location 0x00

temp = new char[x];
a new array is allocated starting at location 0x10
the value of the array's address (0x10) is stored in 0x00 (temp)

foo( temp );
`ptr` is created at location 0x04

ptr = new char[y];
a new array is allocated starting at location 0x20
the value of the array's address (0x20) is stored in 0x04 (ptr)


The chart would look like this:
location value
0x00 0x10
0x04 0x20
0x10 the value of temp[0]
0x20 the value of ptr[0]


Put another way, it is like saying this:
int temp = 1;
int ptr = temp;
ptr = 100;

Temp won't change, just ptr. char * is just an int that holds a memory address. (on 32-bit machines)
Harakim is offline   Reply With Quote
Old Jun 6th, 2006, 1:47 AM   #19
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Thanks.. my book doesn't cover any of that stuff (Sam's Java Programming in 24 Hours). I'm definately out to get a book tonight.

Great explanation!
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old Jun 6th, 2006, 5:09 AM   #20
tumbleTetris
Programmer
 
Join Date: May 2006
Posts: 39
Rep Power: 0 tumbleTetris is on a distinguished road
lol yeah, sams 24 hour books have a bad reputation...

all that stuff *should* be explained in any book claiming to teah java progamming.
tumbleTetris is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC