JFrame invisible border issue - border

I´ve a little issue I would like to get solved.
On my JFrame there seems to be like an invisible border around the frame. So when something should be invisible or stop at ykoord = 0 e.g., it becomes invisible/stops like 20 pixels from the borders you see. Although the background is painted correctly...
Maybe I need to add something here:
public Game()
{
add(new Board());
setTitle("Game");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(BOARD_WIDTH, BOARD_HEIGTH);
setLocationRelativeTo(null);
setVisible(true);
setResizable(false);
}
Please help!

Related

Can't get CircleMapObject from Tiled fLIbGDX

I created a TiledMap in Tiled with a few (object)layers.
Now I wanted to use Box2D to locate, in this case the Ractangles, and put them in a Physics world so my Player can collide with them. However this worked fine for the Rectangles, but I have some problem with the Circles. Here the code I used to create boxes/Rectanles :
for (MapObject object : map.getLayers().get(3).getObjects()
.getByType(RectangleMapObject.class)) {
Rectangle rect = ((RectangleMapObject) object).getRectangle();
new normalBox(world,map,rect);
}
Now I wanted to do the same thing for coins but therfore I need something like an Ellipse or a Circle. My Problem is it doesnt seem to find any Circles in the TiledMap :
for (MapObject object : map.getLayers().get(4).getObjects()
.getByType(CircleMapObject.class)) {
Circle circ = ((CircleMapObject) object).getCircle();
new Coin(world,map,circ);
}
I think the problem is that you cant create Circles in the TiledMapEditor. I created Ellipses and gave them equal width and height, which should be a Circle, but apparently this doesnt work...
Any solutions or tips would be great!!

Overriding the x getter in Actionscript 3.0

I have a class called Element. It is basically my ultra-movieclip, and nearly all classes in the game subclass it. Element extends Movieclip
The code in the game is built around the idea that all Movieclips are registered at the top-left corner. Register it somewhere else, and everything starts to fall apart.
The problem is, sometimes the in the animation and such, the top-left corner moves, but the registration point doesn't, and you end up with a registration point somewhere in the middle of the Movieclip. This causes problems.
So, how do I fix this problem? We can find the true top-left corner of a Movieclip using getBounds (this is the documentation for it), but using getBounds over and over in code would get kinda tedious.
My idea is to override the x getter in the Element class. That way, we can always know where the Element's true top-left corner is, without having to write a bunch of complicated code every time!
And for the sake of argument, let's assume that just making a new getter like "trueX" will open a trapdoor beneath my feet and plunge me into a cage of starving gophers.
I cannot figure out how to override the x getter! How can we do this? Have I missed an incredibly simple solution to the problem that has nothing to do with overriding?
override public function get x():Number {
//I have no idea what I'm doing!
}
This should be all you need to do: (if I understand your question right)
override public function get x():Number {
return super.x + getBounds(this).x;
}

Manage ImageIcon in jPanel

I have a problem when loading a image using jLabel to Imageicon into a Jpanel. When The image have big size (width and height), it makes a Jpanel in my Splitpane so big too in display. How to make this image have default size?
And, how to implement mouse or mouse wheel when big size image is loaded. So ,It makes the image can be dragged or pull up and down... ?
My code like this...
public FileImage() {
try {
image = ImageIO.read(new File("/media/Data/workspace/final_tugas_akhir/tmp/hasil/akhirnya.png"));
} catch (IOException ex) {
System.out.println("Failed to Load Image...!!! ");
}
JLabel jLabel = new JLabel(new ImageIcon(image));
jLabel.setPreferredSize(new Dimension(10, 10));
jPanel3.add(jLabel); // jpanel3 is my panel in main class
}
and in main class just use this
pnlProsesAlgoritma.add(new FileImage()); // pnlProsesAlgoritma is panel to "stick" jpanel3
this is my screenchot before image not yet loaded :https://www.dropbox.com/s/euslx1jj3n21x7j/before.png
after the image loaded looked like this https://www.dropbox.com/s/0mghkg0bs5cmo9d/after.png
P.S : I am using splitPanel to separate two panel. When the image is loaded, the other panel is shifted...
Thanks 4 the help
Maybe you can use the Stretch Icon. It will automatically resize itself to fill the space available.
Insert your JPanel inside a JScrollPane.
This way, your sizing problem will be solved, and you can navigate large image easily too.

How can I avoid sprite distortion as the frame's bounding box changes?

I have a spritesheet (packed by the wonderful TexturePacker) that looks like so:
and the animation as an animation works well using the current code.
However, when the animation moves to a frame where the bounding box is smaller (e.g. when the legs are closer, when the figure is kneeling, etc.), the image distorts so that the smaller bounding box fills the bounding box of the sprite.
How can I fix this?
The spritesheet above is a frame-extraction from a sample Adobe flash animation.
Easier way:
You can make all the textureregions the same size.
Hard way:
Keep it like this, but you need to save and calculate the size and position of every textureregion to draw.
I personally recommend you the first option, just make all the image the same size.
cant give you a link but here is what i do for these situations
while making the texture packer strip the white space
make a array of AtlasSprite for images
then in my render method
public void render(float delta) {
atlasSprite = animation.getKeyFrame(statetime, Animation.LOOPING);
atlasSprite.draw(batcher)
};
in my update method, which gives exact rectangular bounds of the current image displayed. Since you have stripped the whitespace and used AtlasSprite so bounds will be without blank whitespace.
public void update(float delta) {
bounds = sprite.getBoundingRectangle();
}
P.S. this is just a pseudo code and many syntatical error could be there its just to give you a idea

Scrollable html JLabel

I have a Jlabel packed with html. I would like to scroll this content as you would with overflow : auto; in css. I can't seem to get this to work. Has anyone come across this? I'd like to keep the content in HTML - for mark up - and use something light to scroll though it.
BTW: The Jlabel is in a popup - I can use something else other than a JLabel if needs be but would like to keep the html.
Cheers,
slotishtype
Put that JLabel in a JScrollPane instanciated that way :
JScrollPane scroller = new JScrollPane(myJLabel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
Notice that, as this constructor states, those parameters can be changed afterwards.