Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  Quick Structuring Question  (Read 844 times)
0 Members and 1 Guest are viewing this topic.
Offline straydoginc

Junior Devvie





« Posted 2005-09-22 15:53:02 »

In using Applets I can define parameters when the applet is deployed to an html page.

In using the code below:

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  
import java.applet.Applet; 
import java.net.*;

//  TILE BACKGROUND
//     in the HTML use :
//       PARAM NAME="bgImage" VALUE="images/myImage.jpg"
//     in the APPLET tag

public class tile extends Applet {
  Image bgImage = null;

  public void init() {
   try {
      MediaTracker tracker = new MediaTracker (this);
      bgImage = getImage
        (new URL(getCodeBase(), getParameter("bgImage")));
      tracker.addImage (bgImage, 0);
      tracker.waitForAll();
      }
   catch (Exception e) {
      e.printStackTrace();
      }
   setLayout(new FlowLayout());
   add(new Button("Ok"));
   add(new TextField(10));
        }

  public void update( Graphics g) {
   paint(g);
   }

  public void paint(Graphics g) {
   if(bgImage != null) {
      int x = 0, y = 0;
      while(y < size().height) {
         x = 0;
         while(x< size().width) {
            g.drawImage(bgImage, x, y, this);
            x=x+bgImage.getWidth(null);
            }
         y=y+bgImage.getHeight(null);
         }
      }
   else {
      g.clearRect(0, 0, size().width, size().height);
      }
    }
  }
 


  <HTML>
  <TABLE><TR><TD>
  <APPLET CODE=tile.class WIDTH=150 HEIGHT=150>
    <PARAM NAME="bgImage"  VALUE="images/jht.gif">
  </APPLET>
 
</HMTL>
 


Can I integrate the Image and url to the image without using a parameter at all?
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2005-09-22 16:22:21 »

I dont think I understand your question.

You can just initialize a field with the value of the parameter, or even hard code it as a constant straight into the code.

But that seems to be too obviosu so it can't be what you are asking, can it?

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline straydoginc

Junior Devvie





« Reply #2 - Posted 2005-09-22 17:13:35 »

Actually that is about it. Im having a huge issue trying to drop a background image into my applet. I just relized that people are using Param:'s to make the background image in the simplist code ive seen (attached above). But I dont really wish to use a param to set the background image. If this is the easiest way then ill use it but would love to know how to do the alternative. Because If i ever build this into something that isn't an applet and runs using WebStart for example i may not have the Param available to set this.

So a how 2 is my main question Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cborders

Junior Devvie





« Reply #3 - Posted 2005-09-22 17:22:27 »

1  
bgImage = getImage(new URL(getCodeBase(), getParameter("bgImage")));

Actually loads the image from the specified url, if you want you can chage it to
1  
bgImage = getImage(new URL(getCodeBase(), "images/myImage.jpg"));

to hard-code the location of the image in there.  That will work as long as it's running as an applet, but you'll have to change up how it's loading the image a little to run as an application, but that is the only line that should change!
Offline straydoginc

Junior Devvie





« Reply #4 - Posted 2005-09-23 15:10:34 »

Rock on! Thank you much!
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.

toopeicgaming1999 (71 views)
2014-11-26 15:22:04

toopeicgaming1999 (60 views)
2014-11-26 15:20:36

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!