• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Double buffering / drawChars / flickering

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm new to Java Applets. I read a little tutorial(1) and this weekend, I'm actually trying to practise on a small piece of Code.
This is a ball moving through the 'void'. It is red. If you type 'Wort', it turns green.
Thats alright.
What does not work is drawing the char array 'name' or a String 'Hello World'. It just keeps flickering and disapearing.
Please tell me my mistake.

// double buffering and paint are probably the source of the evil

Thanks,
Chris

1: The tutorial i read:
http://www.javacooperation.gmxhome.de/

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chris,
Welcome to the Ranch.

Your code uses AWT, whereas the recommended thing to do is use Swing.
Swing by default is double buffer enabled.

In your code, it is very easy to switch from AWT components to Swing.
AWT->Swing
Applet->JApplet

Take out the update. You don't need it.

Instead of paint() use paintComponent();

Dont use getGraphics(). You already got a graphics instance called g. Just invoke g.drawString()

More about custom painting can be found here http://java.sun.com/docs/books/tutorial/uiswing/painting/
(It also contains a nice article on difference between AWT and Swing painting approaches)
 
Chris Kinsky
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your answer. I tried switching to swing, but I didn't manage it (yet).
My mistake was indeed located in paint()


I didn't want to give up my 'game', so I just moved on with awt.

In my IDE Eclipse, the gameflow is smooth. But if I open the applet via Firefox, all I get is a permission denied.
I use the igerman98-wordlist by Björn Jacke under GPL to generate words. This file is saved as words.txt in the world/ package.

You can reproduce the error here: http://the-agos.net/~User0/game-0.2/game.html

I read, that error is caused by false permissions, if you do not sign the code. Therefore I created a signed .jar archive which includes all pictures, class-files and words.txt.

You can reproduce the next error I get here: http://the-agos.net/~User0/game-0.3/game.html
It is a nullpointerexception, that appears, because it does not load the words from words.txt into an array.
The array is read at line 295, but is null..




This method reads the words.txt located in world/


I don't think you need my full code, it seems to be more an permissions-problem. If you want to see it anyway, just say so please.

Thanks for your time and advice,
Chris aka editalot
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem is that you have your words.txt inside your jar. Under such circumstances, you need to use a different way to load the resources, using getClass().getResource() or getClass().getResourceAsStream()
An example of the getResource can be found here http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html
 
Chris Kinsky
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your help. I've got it working.
the changed code:

This is my new version.
http://www.the-agos.net/~User0/game-0.4/game.html
It is not very chewy at the moment, but it is a 0.X version still

Thanks again,

Chris
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool game
 
Chris Kinsky
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh, thank you !

I'm still improving it, at the moment, the version is at 0.5
http://the-agos.net/~User0/game-0.5/game.html

On that site I'll have links to the newest version if it comes out. I also tried to implement a global highscore ranking, and better graphics.
A bug is moving there now..

After reviewing the code and bringing it into a nicer form /* with comments */ I could post it here for interested people.
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic