Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  *rawr* Core JApplet file  (Read 935 times)
0 Members and 1 Guest are viewing this topic.
Offline Keteri

Junior Newbie




pwning n00bs in high heels since 1986


« Posted 2009-03-31 04:14:56 »

I would very much like to create a "core" file as the basis of my game, displayed in an applet

Basically, I need 2 files (see below)

Core.java - contains methods:
stop()
run()
init()
gameLoop()
update()

Manager.java - contains methods (and some others, but these are the methods im having issues with)
setMode()
getGraphics()
update()

I'm using ScreenManager.java as my guide
(from Chapter 2 of Developing Games in Java - I book I've recently purchased and am totally in love with)
The problem is, I want to learn how to make full screen games, but I also want to learn how to implement this code into a JApplet (not a full screen window) and I'm having some trouble making the connection.
(I have another 30 Chapter book on just Java, and only 1 Chapter covers Applets. Not to mention the author of Developing Games in Java assumes the reader is only interested in Full Screen Windows)

Think you can help, but haven't read the Book?
Seriously, it's an awesome book, and I recommend it to anyone who's new to game programming in Java. The source code for ScreenManager.java is found in Chapter 2.
You can visit the author's website and take a look at the code in the book here.

Think you can help, but you don't know what the heck I'm talking about?
That's ok, I'm a little cooky. I appreciate any help you can give me. Basically I want to make a JApplet without drawing graphics using:
1  
2  
3  
4  
5  
public void paint ( Graphics g )
{
   super.paint ( g );
   g.drawString( "Hello World~!", 25, 25 );
}

If you decide to grant me some of your code, I thank you in advance; however I do request that the code you write is VERY VERY VERY simple. I do not want to steal anyone else's code. I really want to read it, understand it, and then expand on it using my own brain.

Thanks in advance.
Offline Hsaka
« Reply #1 - Posted 2009-03-31 05:46:46 »

Hi

I'm not sure if I understood the question, so correct me if I'm wrong.

Basically you want to create an applet class (Core.java) and then use Manager.java to handle the actual drawing? Since you want to create an applet, you won't need any of the display mode stuff in ScreenManager.

Here is some simple code:

Core.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
import java.applet.*;
import java.awt.*;

public class Core extends Applet implements Runnable
{
   private Image dbImage;
   private Graphics dbg;

   public void init()
   {
      setBackground (Color.BLACK);
   }

   public void start ()
   {
      Thread th = new Thread (this);
      th.start ();
   }

   public void stop()
   {

   }

   public void destroy()
   {

   }

   public void run ()
   {
      Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
                //game loop
     while (true)
      {
         repaint();

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

         }

         Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
      }
   }

   public void update (Graphics g)
   {
      if (dbImage == null)
      {
         dbImage = createImage (this.getSize().width, this.getSize().height);
         dbg = dbImage.getGraphics ();
      }

      dbg.setColor (getBackground ());
      dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);

      dbg.setColor (getForeground());
      paint (dbg);

      g.drawImage (dbImage, 0, 0, this);
   }

   public void paint (Graphics g)
   {
     
   }
}


Manager.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
import java.awt.*;

public class Manager extends Core{

    public void update(Graphics g)
    {
        super.update(g);
    }

    public void paint(Graphics g)
    {
        super.paint(g);
        g.setColor  (Color.WHITE);
   g.drawString( "Hello World~!", 25, 25 );
    }

}
Offline Keteri

Junior Newbie




pwning n00bs in high heels since 1986


« Reply #2 - Posted 2009-03-31 06:37:21 »

thats exactly what i was looking for, thank you~!
i knew it was something fairly "simple" to achieve, im just not very familiar with Applets (hence why I want to learn more about using them)
thanks again  Cheesy
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.

Pippogeek (38 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (31 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (53 views)
2014-09-19 03:14:18
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!