Hello! I don't know how to get my package to work. Ineed help to get access to my Screen file.
I have created a folder called "spel", and in that folder I have 2 subfolders, the first subfolder is called "rain" and inside it I have the class file "Game". The second subfolder is called "graphics", and inside that I have my class file "Screen".
Please, it would make me so happy to know what I'm doing wrong.
I have created a folder called "spel", and in that folder I have 2 subfolders, the first subfolder is called "rain" and inside it I have the class file "Game". The second subfolder is called "graphics", and inside that I have my class file "Screen".
Please, it would make me so happy to know what I'm doing wrong.
Code:
class Game:
-----------------------------
package spel;
import graphics.Screen;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
public static int width = 300;
public static int height = width/16*9;
public static int scale = 3;
private Thread thread;
private JFrame frame;
private boolean running = false;
private Screen screen;
private BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
private int [] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
public Game() {
Dimension size = new Dimension(width * scale, height * scale);
setPreferredSize(size);
frame = new JFrame();
}
public synchronized void start() {
running = true;
thread = new Thread(this, "Display");
thread.start();
}
public synchronized void stop(){
running = false;
try {
thread.join();
}catch(InterruptedException e){
e.printStackTrace();
}
}
public void run() {
while(running) {
update();
render();
}
}
public void update() {
}
public void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
g.dispose();
bs.show();
}
public static void main(String[]args) {
Game game = new Game();
game.frame.setResizable(false);
game.frame.setTitle("Rain");
game.frame.add(game);
game.frame.pack();
game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.frame.setLocationRelativeTo(null);
game.frame.setVisible(true);
game.start();
}
}
class Screen:
-----------------------------
package spel;
//https://www.youtube.com/watch?v=fPSJnzA0nLY = Här är du!
public class Screen {
private int width;
private int height;
public int [] pixels;
public Screen(int width, int height) {
this.width = width;
this.height = height;
}
}
-----------------------------
Error:
Game.java:4: error: package graphics does not exist
import graphics.Screen;
^
Game.java:27: error: cannot find symbol
private Screen screen;
^
symbol: class Screen
location: class Game
2 errors
Comment