The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

need help with a new way of source code

Hello everybody! I recently started with programming in java! I learned from a dutch book written by David J. Barnes en Michael K÷lling. The book is translated form the english version: Objects First With Java a parctical introduction using BlueJ. Now that I'm finally through the book i was looking for a task! That's when I stumbled upon a task which was from my brother in 2004! I first asked him but he couldn't answer me (he mostly is programming in LabView, like 9 years)
First I want to apologize for my bad English typing I from Belgium and I am trying really hard!!

the task: I need to create a maze in which a player is moving! He can only be moved by the air of a ventilator or by the attraction of a magnet. So by clicking with the mouse on those items, the ventilator or magnet need the become an active element. Whether it affects the player depends on the position of the player and ventilator/magnet! By performing those clicks you have to show the player to the exit of the maze.

I first started with the development of an algorithm for generating a maze, after 8 hours I finally gave up. Now I've created a maze by defining a 2D-array in which I declared which position is a wall and which is a path, probably not the right way but good enough for the time being.
Than I made one head Class 'Vak' from that class I extended 'a Path', 'a Wall', 'a Ventilator', 'a Magneet' and finally 'a player'. Those are all the items I guess I need for solving this problem. I created a play area 'Speelbord'. Here I Stored all of my logic (source code)! Here is also where my problem starts. Specifically in this piece of source code:

the piece in Bold is which I did to collect the positions and see whether the player can or cannot move. This will still compile in BlueJ. Now I've created an other class 'controller' Here I make a mouseListener and I am trying to declare it. There for I wrote the following source code:

If I compile now I got the following error: cannot find symbol- method beweegVerticaal. Which is wired because I wrote it (prove above) Now after trying to solve it and reading on the internet I guess I know what the problem might be. My guess is he is expecting some class of those in bold (Speler, Vak, Ventilator, Magneet)
But I cannot put that class there because when I perform a click there need to be a move... So my guess is I need to change my logic, I need the change the way I am thinking but how, how can I do it?

In the code you see I ask java to give me the co÷rdinats of the grid where I click and where the co÷rdinates of a mt are, so I can compare them. If I compile know I got the following error message: "cannot find symbol variable mt" which is logic because I didn't declare it! But if I do declare, which you can see in this code:

it compiles perfectly! However it is nog possible for java to do because the mouseListener is a implemented code from java itself so I cannot add parameters! But I need those parameters to withdraw the co÷rdinates!
How might I be able to solve this problem?
thx in advance

Re: need help with a new way of source code

Yes I noticed I cannot add parameters to a method which is already been written by JAVA itself. But my question is how can I make this mt variable a class variable! Because in my program that I'v written I made a class Vak. This is the main class from here I made extensions to Magneet, Ventilator, Speler, ... But to see whether my mouseClicked can go through I performed an if-statement in which I ask to compare the co÷rdinates of the mouseClick and the co÷rdinates magneet mt. I cannot perform that unless I add the parameter 'Magneet mt' to the methode mouseClicked written by JAVA and thus make an error!
thx in advance!!

Re: need help with a new way of source code

thanks a lot for helping me out here!! Now I have a mayor problem, at least I think it is a mayor problem!! I finally succeded with compiling all of my code. Now when I want to start my application nothing happens. Just a white screen pops up, in stead of a maze! The maze which I created by hand in the class 'Speelbord'. I thinks my problem is in my class 'View'

Re: need help with a new way of source code

I am sorry but I don't know how I possibly could do that! I started on programming but the way I see it I cannot delet any of those classes! I can make a picture of the maze I am trying to display... Maybe I need to translate my program in English? (I am from Belgium so it is all written in dutch)
I still think the problem is in the class 'view' there I putted in comment an "Iterator<Vak> vakken..." so the program would compile. if on the other hand you take it out of commentary the program display a fault: cannot find symbol - method getVakken() But on the internet I found that an Iterator is used with a simple array,I assume a 1D array! But in the class 'Speelbord' you can see I used a 2D array to perform my maze. Maybe the code is correct written but I am using the wrong types together to get my maze displayed...
I will keep working on a smaller program but don't know whether I will succeed...
thx in advance!!

Re: need help with a new way of source code

I might be able to help, I've done tons with graphics in Java. I'll try to translate the class names, but as Norm said, a small program to demonstrate the problem would be nice.

EDIT: Just because you made this canvas doesn't mean it just works. You've got to plug it into a system, like a graphics library. I couldn't help you with this as this is very library specific, and I'm used to using LWJGL only.

Re: need help with a new way of source code

@ Norm: I really was trying to make a smaller program in which I not succeeded but while doing that it occured to me what I needed to change to my own program to let it display the maze. And let the logic work my player towards the end. thank you very much!!

@ lightofDay: There is no need for it any more! I finally succeeded as I told Norm already! But thanks anyway!

Maybee you guys Can help me with another problem I've been having. I am trying to upload an image for my player, instead of a rectangle. Now I don't know how I need to do that and whether it will fit in a rectangle or not... You see the player can't be bigger then the red rectangle I choose to be my player right now!!
Also if you succeed and lead your player towards the end, there pups-up "Congrats" in yellow. I was wondering if it is possible to let it turn 360░ ...
And last but not least I was wondering if it is possible to let a music play during the game?
Can you help me to solve those questions.

Re: need help with a new way of source code

Glad you fixed it My first theory was you weren't actually displaying the canvas. As for sound, this is also implementation specifc, but many times requires complex setup or an audio codec, which is way out of my league. The problem with a lot of stuff is it's implementation specific. Certain libraries allow easy ways to do things, some don't. I know with LWJGL there was no good way to load images. You had to read straight from the raw file...that was always a pain... Now once you get your player image, with an alpha channel and all that complex stuff if you want, it's very simple to draw. If "g" is your Graphics object, g.drawImage(imageObject, imageWidth, imageHeight, canvas). So the implementation would be g.drawImage(playerImage, playerHeight, playerWidth, this), where this code is put in your canvas "paint" function, making "this" the canvas you want to draw to

Re: need help with a new way of source code

Maybee I've found a way of making a small program in which I can play the music but this time I used eclipse instead of BlueJ!
- on Eclipse I'm getting the following error: "Description Resource Path Location Type
Access restriction: The constructor AudioStream(InputStream) is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Sound_1.java /Sound_1/src line 44 Java Problem" the line is irrelevant here because it shows up at different lines.

>>Solution???: on youtube I read I needed to go to window->preferences->java->compiler->errors/warnings-> deprecated and restricted API: everything to ignore or warning.
Do I also need to check any boxes there if that is the solution?

- therefor I also tried my code in BlueJ and there pop-up a box on my screen with the following:
show() in java.awt.Window has been deprecated
sun.audio.AudioPlayer is internal proprietary API and maybe removed in a future release
sun.audio.AudioPlayer is internal proprietary API and maybe removed in a future release
sun.audio.AudioStream is internal proprietary API and maybe removed in a future release
sun.audio.AudioData is internal proprietary API and maybe removed in a future release
sun.audio.ContinuousAudioDataStream is internal proprietary API and maybe removed in a future release
sun.audio.AudioStream is internal proprietary API and maybe removed in a future release
sun.audio.ContinuousAudioDataStream is internal proprietary API and maybe removed in a future release
>>Solution???: for blueJ I cannot find a solution on the internet do you know any?

Re: need help with a new way of source code

I am so sorry, you can completely ignore my last post!! I managed to solve it my self because google is my friend too (I was completely forgotten about that)
But now I want to implement this Sound to the program I already made! But does anybody know whether it is possible or not and where I could best write/add that code? To class Speelbord or should I make another class Sound and just call it in my game Magnetisch doolhof?

the program with the sound has the following code (which I found on the internet) to let it work you have to add a wav file in the map where your code is stored, this code is working so now error here: