Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Setting Applet Background  (Read 1195 times)
0 Members and 1 Guest are viewing this topic.
Offline straydoginc

Junior Devvie





« Posted 2005-08-11 19:56:01 »

Im in the process of building and perfecting a simple 2 fighter or monster vs fighter battle system as an applet.

What i do not know how to do and need some guidance on.. (after massive amounts of google searching and reading) is:

how do i place a back ground image on my applet that I can place other images and drawStrings on?
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2005-08-16 02:29:00 »

Im in the process of building and perfecting a simple 2 fighter or monster vs fighter battle system as an applet.

What i do not know how to do and need some guidance on.. (after massive amounts of google searching and reading) is:

how do i place a back ground image on my applet that I can place other images and drawStrings on?

The same way you draw anythign else.

To chnage the background of a JPanel to an image you would subclass it and over-ride its update.  Im sure there are many tutorials on the net about this.   Whenever I need it frankly i justr ecreate it, it takes me about a minute of lookig at the JPanel docs to throw together a "JImagePanel" so its not something I keep the details of in active memory Smiley


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-08-26 19:20:11 »

K im still having a huge issue with this.

Here is my class that is grabing my image:

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  
package battleApplet;

import javax.swing.*;
import java.awt.*;
import java.awt.image.*;


/**
 * @author zalexander TODO This Draws the background
 */


public class GuiInterface extends JViewport {
   
   private String dir = System.getProperty("user.dir");
   private String imageFile1 = dir + "/images/monkey_bigwrench.gif";
   private TexturePaint imagePaint1;
   private Rectangle imageRect;

      public GuiInterface() {
          BufferedImage image = ImageUtilities.getBufferedImage(imageFile1, this);
          imageRect =  new Rectangle(0, 0, image.getWidth(), image.getHeight());
          imagePaint1 = new TexturePaint(image, imageRect);
         
        }
   
   
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
          Graphics2D g2d = (Graphics2D)g;
          g2d.setPaint(imagePaint1);
          g2d.fill(imageRect);
          g2d.setPaint(Color.black);
          g2d.draw(imageRect);
     
        }

}


and in my main class:

I import the class

1  
import battleApplet.GuiInterface;


then i create the new object

1  
private GuiInterface       guiInterface = new GuiInterface()


then in my init() method where IM building my interface I want to put it here

1  
 guiInterface.paintComponent(Graphics g);


But it is telling me it can't find the g in (Graphics g).

What am I doing wrong?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2005-08-26 21:25:13 »

Um.  This syntax is just simply wrong:

1  
 guiInterface.paintComponent(Graphics g);


You dont put the class name befoer a parameter  in a method call.

Im not sure your logic is right either but whats abvoe wont even compile.


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 #4 - Posted 2005-08-27 21:54:55 »

Yup I noticed this. Thats where Im having the problem. What is a good example of how to do this or where do i need to alter my code to handle this?
Offline Ask_Hjorth_Larsen

Junior Devvie




Java games rock!


« Reply #5 - Posted 2005-08-27 23:12:10 »

If you want paintComponent to be called, you should use a repaint method such as repaint() or repaint(0). Don't try to call paintComponent directly.
Offline straydoginc

Junior Devvie





« Reply #6 - Posted 2005-08-31 17:12:44 »

Hmmm. With what ive provided above:

#1 is there a better way to accomplish laying a background for my applet

#2 How would I use the repaint method. Or should I take the paint componet out of my guiinterface class all together and create it in the main class?
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (57 views)
2014-11-29 21:32:03

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

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

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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