• Advertisement

Archived

This topic is now archived and is closed to further replies.

[java] Pixel Plotting Under Java

This topic is 6519 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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().

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
I would like to know how to do pixel plotting. I''m not too good with low level graphics stuff.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement