JC Denton

Greenhorn
+ Follow
since Nov 21, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by JC Denton

I doubt this applies to graphics, rather than the language structure.

I have a class extending the JPanel with a member class of custom type Tetris.

Tetris has a method getImage() which returns a bufferedImage to be drawn onto the screen.

In this class it looks like this:



The above code works as desired.

For the 2 player version I'm subclassing this particular class and adding another Tetris member dubbed tetris2.

The same method in the subclass:


forgive the extra BI which is drawn on using g. The interface would otherwise start flickering.

The code compiles but when it is run there's a NPE

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

This is utterly discombobulating. Using JDK1.4.1 the code would work if tetris2 was a member of the parent class and not the subclass.

Is it something to do with the subclass not being able to draw on the panel of the superclass? The constructor of the subclass calls the parent constructor.

Thanks
17 years ago
I'm drawing an image onto a JFrame and manipulating it in all kinds of ways.

Is it possible to grab the RGB of a specific pixel in the JFrame?

I'm trying to display the rgb of each individual pixel as the mouse passes over them.

the image is drawn at (0,0) so currently I'm using



many thanks
[ May 08, 2006: Message edited by: JC Denton ]
17 years ago
Thank you for your help. It is very much appreciated in circumstances most despairing.

I'll confess. My hours are consumed attempting to create tetris, hence the drawing on the JFrame. I fear losing KeyEvent functionality when adding a label component to the form so I wish to restrain from doing so.

The KeyEvent listener is added to the JFrame subclass.

I am using another class to proxy the graphics rendering, allowing me to create multiple instances, easing the process of implementing [local] multiplayer.

As JPanel is a subclass of the Component class, I can override the paintComponent method there. [?]
17 years ago
Im writing a class which intends to turn a bufferedimage objects into a graphics2d object so as to make use of the draw() method. Once that's done the method will return the graphics object to the class subclassing a JFrame. This class will position and paint the graphics object onto the JPanel. At least thats the intention but:

I'm stuck painting the graphics object onto the form. Any ideas? casting it back to a bufferedImage and using paintImage() in the paint() method of JPanel looks like an option but im unsure on how to use this method and graphics efficiency is imperative something which [prob] won't benefit of continual casting..

using getGraphics(), casting and passing the Graphics2d fails to fruit when the class calls Draw() on it. It is not a solution I'm interested in anyhow..

thanx all
17 years ago
Im trying to read a text file saved in ASCII in binary but the string thats supposed to contain the data does not contain anyting... where am I going wrong?

Note: most of the code is copied from Ivor Horton's beginning Java sdk 1.4

public static void readFile(String path) {
String myString = "";
filePath = new File(path);
myString = filePath.toString();
System.out.println(myString + "\n" + filePath);
//testing stuff
FileInputStream inFile = null;
File aFile = new File(path);

try {
inFile = new FileInputStream(aFile);
} catch (FileNotFoundException e) {
e.printStackTrace(System.err );
System.exit(1);
//1? how is 1 different from 0?
}
FileChannel inChannel = inFile.getChannel();
ByteBuffer buf = ByteBuffer.allocate((int)filePath.length());
//small file expected so I created a buffer the size of that file
//what exception will be thrown if the integer overflows?
try {
myString = ((ByteBuffer)(buf.flip())).asCharBuffer().toString();
//flip??
System.out.println(myString);
//should now contain the file contents
buf.clear();
inFile.close();
//suits me
}catch(IOException e) {
System.out.println( "Couldn't open the files: " + e );
e.printStackTrace(System.err);
//no exceptions are printed when the file is run
System.exit(1);
}
System.exit(0);
}

In the final version of the program the file should be located in the same directory as the program. How do I find where the program is located?
Thanx all
19 years ago
Hi all
Im switching to java from VB and I was discussing IDE's on the vb forums: http://visualbasicforum.com/showthread.php?t=198425
The reason I'm switching is that I shivver everytime some1 asks me what I program in or when some early teen says VB - it's just its image. Also it will come in very handy learning other proper languages and when I hopefully go to UNI netxt year to study computer science as a mature student.
my main message is this: [maybe some1 here is able to help me [better?] ]

I bought Ivor Horton's Beginning Java JDK 1.4 [1100 pages] 2+ years ago and only got through the initial 400 and forgot most of that [probably due to incompetence but blaming it on that would be incompetent as its a simple thing to do... ] so I consider myself a beginner. In those days whenever copying / editing an example program from the book I would be using JCreator or sometimes notepad. JCreator [lite] is a great alternative to notepad but not much else. The lite version at least doesn't have autocomplete or step through and breakpoints [some of the strenghts of VB].

I prefer making interface-less programs as you can concentrate on the core without the usual user input hassle of validating every action, but hey thats programming I suppose...

Yesterday I downloaded and installed JBuilder from Borland and initial impressions were a bit cumbersome. I had trouble enough getting it to recognise 3 classes as part of one project [finally just dragged them in the project explorer window]. I'm not sure why it comes with its own compiler [It's the Java one, right?] but hey ho. Getting adjusted is gonna take some time I suppose [coding in it atleast] but I did manage to change the compiler to my JDK 1.5 beta as it didn't like my
import java.IOException;
import java.FileNotFoundException;
statements. Not that changing the compiler helped a lot.
I have the java documentation in the docs folder - will JBuilder integrate with it to offer support in a MSDN fashion? [another agreeable feature of VB]

Would anyone suggest Visual J++ if you're only developing java apps for the windows platform? Is the 'visual' bit as daunting as the 'visual' in M$ VC++ ?

IF the interface designer proofs useful then I will certainly use it otherwise JCreator will have to assist there.

The reason I'm suddenly switching to Java again is this: http://planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=57209&lngWId=1 . It is a college program I did in VB and posted it as lots of people are having trouble with the problem interpretation only to find out you are not supposed to share your work. Good intentions getting us in trouble eh? It's almost as if they try to impede any postive actions. Anyway. This way lots of people can use it as a reference yet I'm not sharing my work as I won't be handing it in. It's merely a case of translating it into Java.
Well, when I say merely...
I have a pretty limited period of time to get this thing done: file handling, general coding [*should* be ok - the generating code - see link], interface :0 and turning it into an applet..

This raises some questions tho:
what's Java's version of app.path?
How do I pass an array between methods/functions or rather reference them in memory the way I have done in the VB version.
Can applets perform read and write actions on the machine it is stored? Can I refuse connections if a client is already connected? [As I don't want two people generating a new match *see link ^ *]
Any hints on using the interface designer in Jbuilder? Instead of using Java's equiveland of the tree view control I was this time hoping on using its equiveland on the list-view control - any tips on that as I don't think Mr Ivor discusses it in detail - merely its availability.

The way I planned the file reading code was:
Open it in binary
Create a file buffer the size of the file
Read the entire file into the file buffer at once [it is only a small file - competitors.game included in the zip: http://planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=57209&lngWId=1]

Making it executable [Jar(?)] will pose as one of the final challenges as will compiling it with a compiler tool that makes it harder to decompile as Java seems notorious concerning source availability even when compiled. Not that I'm against open source - on the contrary - but this time fellow students should only be able to access the 'binary' - well Java's solution.


Well, here I go. Thanx people
19 years ago