Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  making an applet into a applet/application hybrid  (Read 1139 times)
0 Members and 1 Guest are viewing this topic.
Offline Serethos

Junior Member




Java games rock!


« Posted 2004-05-15 16:04:04 »

i need to make my applet be runnable as application.
therefore i did nothing more that adding a main method like

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
public static void main(String args[])
      {
            final Memory memory = new Memory();
            JFrame frame = new JFrame();
            frame.add(memory);
            frame.setSize(550, 550);
            frame.setResizable(false);
           
            memory.init();
            memory.start();
           
            // minimize !!
           frame.addWindowListener(new WindowAdapter()
            {
                  public void windowClosing(WindowEvent we)
                  {
                              memory.destroy();
                              System.out.println("Applikation wird geschlossen");
                              System.exit(0);
                  }
            });
           
            frame.setVisible(true);
      }



but by launching it as application i get a NullPointerException in my init() methode where i create my offscreen Buffer:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void init()
      {
            //Definition des des OffScreen Bereiches
           offscreenImg  = createImage(getSize().width, getSize().height);
            offscreen         = (Graphics2D)offscreenImg.getGraphics();
           
            offscreen.setColor(new Color(247, 22, 20));
            offscreen.setFont(new Font("Monospaced", Font.BOLD, 18));
           
            showStartMenu();

      }


right at offscreenImg  = createImage(getSize().width, getSize().height);

first i thought it would be cause an application doesnt seek for the dimension of the applet in the html so i have to set it with setSize(...). but this doesnt fix the problem.

any ideas ?
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #1 - Posted 2004-05-15 16:18:07 »

IIRC you have to call setVisible( true ) first.

Until you do, Java doesn't create screen memory etc for your app.

Until you have screen memory, AWT will bomb if you try to create an Image (which is why headless systems needed a special set of features in 1.4.x to allow them to create and process images, IIRC).

Assuming I'm not spouting BS Wink here, I sympathise with you that this is one of those really crappy parts of AWT desgin/docs that I recall having lots of pain in early days discovering Sad.

malloc will be first against the wall when the revolution comes...
Offline Serethos

Junior Member




Java games rock!


« Reply #2 - Posted 2004-05-15 16:26:04 »

ahhh, very nice, thx. this is one of those mistakes i wouldnt have figured out in years. now i have several other errors, but i first a little try&error. perhaps i need to post them later...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Serethos

Junior Member




Java games rock!


« Reply #3 - Posted 2004-05-15 16:48:38 »

ok, all problems solved, the game is running as an application. but in my quick&dirty way a new aspect comes to my mind.
ive never done a game using a real frame. my applets uses an offscreen image (like you've seen) and paints it active in a game loop. but now i only add the applet-canvas to the jframe. but a swing comonent already uses double-buffering. is the way of adding the applet to the frame a good (normal) one or should i do it in a diffrent way. my sorrow is that there are any problems (perhaps performance) to do active rendering in a swing component...
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #4 - Posted 2004-05-15 22:41:13 »

The problem with mixing applets and frames is the fact they are both top level containers (heavy weights).  I got around that by using a JPanel to implement my own light weight applet (I should probably change that to a Canvas acutally...).   You can still hijack the rendering but its not recommended.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (32 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (40 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!