Im new to this forum and I was wondering if someone could help me? In my project I want my map (background image) to load, however It does not seem to do it at all and I have used mostly every single way. I you can see what my problem is could you show a correction . It is based in two classes!
This is the fist one and my main class!
package com.bloodtake.quest;
import java.awt.Canvas;
import java.awt.Dimension;
import
java.awt.Graphics;
import javax.swing.JFrame;
import com.bloodtake.quest.graphics.Screen;
import
com.bloodtake.quest.world.*;
public class QuestComponent extends Canvas implements Runnable
{
private static final long serialVersionUID =
1L;
private static final int WIDTH = 160;
private
static final int HIGHT = 120;
private static final int SCALE = 4;
private static final Graphics Graphics = null;
boolean
screenLoad = false;
private boolean running;
private
Thread thread;
private Game game;
private Screen
screen;
public QuestComponent() {
Dimension
size = new Dimension(WIDTH*SCALE,
HIGHT*SCALE);
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
game
= new Game();
screen = new Screen(WIDTH,
HIGHT);
}
public synchronized void
start(){
if (running) return;
running =
true;
new
Thread(this).start();
thread.start();
}
public
synchronized void stop(){
if (running)
return;
running = false;
try
{
thread.join();
} catch
(InterruptedException e)
{
e.printStackTrace();
}
}
public
void run(){
while (running)
{
tick();
render();
Map.printMap();
}
}
private void tick()
{
game.tick();
}
private void
render() {
screen.render(game);
}
public static void main(String[] args)
{
QuestComponent game = new
QuestComponent();
JFrame frame = new
JFrame("Quest: A Demo
Unleashed");
frame.add(game);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
boolean
screenLoad = true;
if(screenLoad = true)
{
System.out.println("Screen Successfully
Loaded!");
game.start();
}
}
}
[/quote]
This is my class that loads my map
package com.bloodtake.quest.world;
// Imports
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.swing.JFrame;
// Game Imports
public abstract class Map extends JFrame {
private static final long serialVersionUID = 1L;
public static BufferedImage map;
public void init(){
try{
map = ImageIO.read( getClass().getResource("A1.png"));
}
catch(IOException e) {
System.out.println("Load Image error:");
}
}
public static void printMap(){
System.out.println("Loading map...");
// This is the section where the image (A1.png) needs to print so in my main class is can load.
//known as Map.printMap()
}
}
[/quote]