继续努力学习 Java一帆风顺,一小 issue。 我的游戏板包括“JPanel”和“每个板”。 现在,这带来了一些问题:
因此,每一件散装船的大小都掩盖了整个JFrame,隐藏了其他碎片和背景(加板)。
斜体确定碎片的位置。
我有拖欠的流动管理人。 沥青 set和 no。
Perhaps i should make the piece to extend other JComponent? Added image: That s the piece, now the greyed area is also the piece! Checked that by making a mousePressed listener and assigning some stuff to it. Below the grey area, is the gameboard (or at least, should be!), another JPanel.
alt text http://img42.imageshack.us/img42/2227/crshotvdy.png
一些法典:
package TheProject;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class GameWindow extends JFrame {
public GameWindow() {
setSize(800, 600);
setLocationRelativeTo(null);
Map map = new Map(800, 600, 2);
add(map);
MilitaryUnit imperialRussia = new MilitaryUnit(30, Color.BLACK, Color.YELLOW, Color.WHITE);
imperialRussia.setPreferredSize(new Dimension(30, 30));
add(imperialRussia);
}
}
This happens when i apply the pack() method: alt text http://img442.imageshack.us/img442/5813/screenshot2ml.png
该股周围的包装,而不是较大的地图,填充了联合阵线。