Home » Newcomers » Newcomers » game doesn't fully load(my game loads a bit and every time its something else)
game doesn't fully load [message #1764951] |
Sun, 04 June 2017 15:44  |
Eclipse User |
|
|
|
so when i run this the screen doesn't load fully. some labels are gone and some appear after a while. I just started with this so my code is a bit weird and i'm from Belgium so if you see a variable that's written in dutch and you can't read it i can translate it.
package fullGame;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import javax.swing.JLabel;
public class AllGame {
// player gegevens
int playerLvl = 1;
int playerMoney = 1000;
String playerWeapon = "fists";
int playerHp = 100;
String playerName;
int maxPlayerHp;
int weaponDemage;
// game gegevens
String storyLine;
int aPressed;
int keuze;
//enemy gegevens
int maxEnemyHp;
int enemyHp;
//frame gegevens
JButton RightButton, LeftButton, UpButton, DownButton;
private JFrame frame = new JFrame();
public static void main(String[] args) {
AllGame window = new AllGame();
window.frame.setVisible(true);
window.Frame();
}
public void Frame(){
frame.setBounds(100, 100, 454, 330);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.green);
frame.getContentPane().setLayout(null);
DownButton = new JButton("down");
DownButton.setBounds(324, 245, 77, 25);
frame.getContentPane().add(DownButton);
DownButton.setVisible(false);
UpButton = new JButton("up");
UpButton.setBounds(324, 191, 77, 25);
frame.getContentPane().add(UpButton);
UpButton.setVisible(false);
RightButton = new JButton("right");
RightButton.setBounds(370, 219, 66, 25);
frame.getContentPane().add(RightButton);
RightButton.setVisible(false);
LeftButton = new JButton("left");
LeftButton.setBounds(281, 219, 77, 25);
frame.getContentPane().add(LeftButton);
LeftButton.setVisible(false);
JLabel lblplayerHp = new JLabel(Integer.toString(playerHp));
lblplayerHp.setBounds(33, 13, 56, 32);
frame.getContentPane().add(lblplayerHp);
JLabel lblMoney = new JLabel(Integer.toString(playerMoney));
lblMoney.setBounds(124, 17, 50, 24);
frame.getContentPane().add(lblMoney);
JLabel lblLvl = new JLabel(Integer.toString(playerLvl));
lblLvl.setBounds(227, 21, 56, 16);
frame.getContentPane().add(lblLvl);
JLabel lblWeapon = new JLabel(playerWeapon);
lblWeapon.setEnabled(true);
lblWeapon.setBounds(329, 21, 56, 16);
frame.getContentPane().add(lblWeapon);
JLabel lblHp = new JLabel("HP:");
lblHp.setBounds(12, 21, 56, 16);
frame.getContentPane().add(lblHp);
JLabel lblMoney_1 = new JLabel("Money:");
lblMoney_1.setBounds(77, 21, 56, 16);
frame.getContentPane().add(lblMoney_1);
JLabel lblLvl_1 = new JLabel("Lvl");
lblLvl_1.setBounds(206, 21, 56, 16);
frame.getContentPane().add(lblLvl_1);
JLabel lblWeapon_1 = new JLabel("Weapon:");
lblWeapon_1.setBounds(274, 21, 56, 16);
frame.getContentPane().add(lblWeapon_1);
JLabel lblStory = new JLabel(storyLine);
lblStory.setBounds(12, 72, 412, 72);
frame.getContentPane().add(lblStory);
JButton AButton = new JButton("A");
AButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
aPressed = aPressed + 1;
if(aPressed == 1){
lblStory.setText("okey this is a simple game where you have a few options to win");
}
else if(aPressed == 2){
lblStory.setText("you have the choice every time to go where you want");
}
else if(aPressed == 3){
lblStory.setText("okey lets start.");
}
else if(aPressed == 4){
lblStory.setText("you can now start to go where you want to go");
DownButton.setVisible(true);
UpButton.setVisible(true);
LeftButton.setVisible(true);
RightButton.setVisible(true);
}
}
});
AButton.setBounds(73, 245, 60, 25);
frame.getContentPane().add(AButton);
JButton BButton = new JButton("B");
BButton.setBounds(12, 245, 50, 25);
frame.getContentPane().add(BButton);
}
Attachment: scherm.png
(Size: 3.56KB, Downloaded 101 times)
|
|
| |
Goto Forum:
Current Time: Wed Mar 19 06:34:53 EDT 2025
Powered by FUDForum. Page generated in 0.09012 seconds
|