I am beginner in Java. I am trying to make a gui game and I want to add key adapter but I dont know where should i get as parameter start- where is Jframe extended Slides-where is new Layout set (panels buttons etc) Casual - where is setText change
I use many seperate class like Colors and Fonts but I think that I dont have to include that.
Here is a two fragments that throws Null Pointer Exception. I must add I tried all classes above as parameter to constructor but it didnt worked .After all here is code :
Casual.java (fragment)
public void firstDay(){
pv.movingHandlerON=true;
start.addKeyListener(new MovingChoiceHandler(slides)); // naprawic !
music.setMusic(pv.musicDay);
music.loopMusic(99);
music.startMusic();
slides.textPanel.setText("You had the accident in forrest.\nYou take all u got and go
into adventure.\n\nWhere do You want to go?\n\n[Q] Go forest Pathway [Z] Go Muddy
road");
}
MovingChoiceHandler .java (full code without import and package)
public class MovingChoiceHandler extends KeyAdapter {
PlayerVariables pv=new PlayerVariables();
Start start;
Slides slides;
Casual casual;
MovingChoiceHandler(Slides slides){
this.start=slides.start;
}
// tutaj przez strzałki bedziemy zmieniac slajdy
public void keyPressed(KeyEvent e){
// if(pv.movingHandlerON==true) {
switch (e.getKeyCode()) {
case KeyEvent.VK_Q:
System.out.println("Sprawdzanie gory check");
break;
case KeyEvent.VK_W:
System.out.println("Sprawdzanie dolu check");
break;
}
//}
}
}
If You interested more here it is full code if You dont see here any problem. As I say i tried start, casual,and slides but it still throw this exception.I tried even like
this.slides=slides;
this.start=slides.start;
Full code :
Start.java : https://pastebin.com/tmv7td8x
StartButtonHandler (start->slides) :https://pastebin.com/3ZX1CZgT
Slides.java :https://pastebin.com/bebR4qBk (Casual is added without handler into Slides)
Casual.java :https://pastebin.com/mR1DS1cJ
MovingChoiceHandler.java: https://pastebin.com/rXtSkN4c
(added in first method in casual to change next "slides"