Jump to content
  • Advertisement
Sign in to follow this  
a new beginning

NetBeans on Mac (problems)

This topic is 2836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey so when try to run a program that displays images on a jpanel, the image doesnt show? but when i run the same program on a windows machine, it will show, does any1 know what the problem is or could be?

Share this post


Link to post
Share on other sites
Advertisement
ya i dont remember the code to put this in format? srry bout that
package horrorgame;

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

public class Player{
//players current level
private int lvl;
//health
private int hp;
//How scared/brave you are
private int nerve;
//how long you can run/melee speed
private int stamina;
//how strong you are
private int strength;
//players position
private MyPoint position = new MyPoint();

private Image playerImg = new ImageIcon("zelda.gif").getImage();

public Player(){
lvl = 1;
hp = 20;
nerve = 1;
stamina = 1;
strength = 1;
setPlayerPosition(100,100,0);
}
public void setPlayerPosition(double x, double y, double z){
position.changePosition(x, y, z);

}

public void setX(double x){

}
public void movePlayer(){

}
public void paint(Graphics g){
g.drawImage(playerImg, (int)position.getX(), (int)position.getY(),50, 50,null);

}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package horrorgame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*
to draw on jpanels, you need to create a class that extends jpanel,
and overrides the paintComponent method. jpanel should be used to draw on??
*/
public class GamePanel extends JPanel implements KeyListener{
Player player = new Player();
public GamePanel(){
addKeyListener(this);
setBackground(Color.RED);
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
player.paint(g);
g.fillRect(20, 20, 40, 40);
}
/** Handle the key typed event from the text field. */
public void keyTyped(KeyEvent e){

}

/** Handle the key pressed event from the text field. */
public void keyPressed(KeyEvent e){
if(e.getKeyCode() == e.VK_W){
}
}

/** Handle the key released event from the text field. */
public void keyReleased(KeyEvent e){
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package horrorgame;
//allows us to use jframe
import java.awt.*;
import javax.swing.*;

public class GameFrame extends JFrame{
GamePanel gamePanel = new GamePanel();
//size of frame
private int xDim = 800, yDim = 600;
public GameFrame(){
//sets title of frame
setTitle("HorrorGame");
setSize(xDim,yDim);
setContentPane(gamePanel);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
}

Share this post


Link to post
Share on other sites
So which part isn't working as expected?

Can you reproduce the problem with a minimal amount of code i.e. by creating a single class that extends JPanel and overrides its paintComponent method? Keep in mind that no one else here has "zelda.gif" or MyPoint and so cannot even attempt to reproduce your problem. It's also often the case that by stripping things back to a minimal test case, you'll find the problem yourself.

Share this post


Link to post
Share on other sites
its just the drawing of the image thats the problem right now, it just doesn't draw,

// gamepanel class does extend a jPanel and overrides the paint component, and it draws the rect, but doesnt draw the image, and ya the zelda.gif was just a random pic to test if the image would draw on screen...... and ill try to retest with the minimal amount of code to see wats up, but again, i dont know if its just not drawing on my mac(compatability issues or sumthing), because the image draws on a pc(windows machine), which is a bit odd to me.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
heres the myPoint class, it just a class with an x,y,z.
package horrorgame;

public class MyPoint{
//x position is going to determine where the character is left or right of
//the screen
double x;
//y position is going to determin if a character moving up or down, as well
//as jumping
double y;
//z position is going to determine how far into the screen/up close to the
//screen the player is, this is going to work with the characters y pos
//as well, ex if character jumps, players y pos increases, but z stays the
//same. but if character moves towards the screen, then y position changes,as
//well as the z position, drawing character bigger or smaller....
double z;

public MyPoint(){

}

public void changePosition(double tX, double tY, double tZ){
x = tX; y = tY; z = tZ;

}

public double getX(){
return x;
}

public double getY(){
return y;
}

public double getZ(){
return z;
}
}

Share this post


Link to post
Share on other sites
Here's the deal: if you provide a minimal but compilable chunk of course that exhibits your problem, somebody here can copy and paste it in to their IDE or editor and run it with the minimum of fuss. Right now, you're making it unduly hard for anyone to help you. Somebody has to hack your snippets of code together/apart, set up the correct directory structure, sort out the build...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!