Advertisement

[java] Pixel Plotting Under Java

Started by March 20, 2000 12:26 AM
4 comments, last by Kosh 24 years, 9 months ago
hi everyone, I would like to know, can someone please download my java code, which is at this URL http://mx1.xoom.com/KoshHome/JavaApplication.zip and tell me why it doesnt do anything, I am trying to just plot some pixels around, but for some reason, it''s not working, I was wondering if it''s just something simple that I am getting wrong, if you can fix it, either just upload it to a site, then link it here, or just put a couple of lines that tell me what to change and where I went wrong. Thanks everyone, I have been sitting up for the last 10 hours on this, without success. kosh
if understanding it made and born with time, then time, is understandings greatest enemy.....
Here is the problem class rewritten. The AppFrame was not doing what it was supposed to, first you didn''t call the super() constructor (as you should have), but created another Frame in the constructor that then got lost (you didn''t preserve the reference to it. Also in paint() you don''t have to say getGraphics() as you allready have it...


public class AppFrame extends Frame
{
PixelImage piximage = null;

public AppFrame( int framesize_x, int framesize_y ) {
super("2DG Demo");
piximage = new PixelImage(new Dimension
(framesize_x,framesize_y));
setSize(framesize_x, framesize_y);
setVisible(true);
}

public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(piximage.getImage(),0,0,null);
}
}


If you use this code, it''ll work. I also suggest adding a bit of code to your forever for-loop in the Application class. Something like:

try
{
Thread.currentThread().sleep(20);
}
catch( InterruptedException ie )
{
}


That''ll make it a bit more loose loop (that gives other threads some time to do something).

If you like to NOT use the normal repaint-update-paint cycle I suggest you change the repaint method to:

public void paintNow()
{
Graphics2D g2d = (Graphics2D) this.getGraphics();
g2d.drawImage(piximage.getImage(),0,0,null);
}


and in the Application class instead of saying app.repaint() say app.paintNow().
-Pasi Keranen
Advertisement
hello all,
JAVANERD !!!! YOUR A FUCKING GENIUS !!!!

yes, it works muhahahahhahah I can plot pixels !!!!

ok, would anyone like a quick and dirty tutorial for you to point people at ? tired of answering the "how do I plot a pixel" question, time and time again ? well, if you want, I''ll do one, now that I can do it, I dont mind helping other people.

What does everyone say ?

kosh
if understanding it made and born with time, then time, is understandings greatest enemy.....
I would like to know how to do pixel plotting. I''m not too good with low level graphics stuff.
quote: Original post by Jim_Ross

I would like to know how to do pixel plotting. I''m not too good with low level graphics stuff.


Yeah, me too do you know any good books from low level graphics?



Time comes, time goes and I only am.
Yeah! Spread the knowledge...
-Pasi Keranen

This topic is closed to new replies.

Advertisement