我认为并希望这是一个小问题。
我有一个JFrame
在蛇游戏中显示的。文本,例如"Game Over, your snake is crashed"
或其他内容,将显示在JLabel
.
问题是我JLabel
的总是空的!
这是代码:
package ch.gibb.snake1;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class endFrame extends JFrame {
/**
* Auto-generated VersionUID
*/
private static final long serialVersionUID = -6535942219723507798L;
public static void main(String[] args) {
displayFrame();
}
public static void displayFrame() {
JFrame frame = new JFrame("Game Over");
JLabel info = new JLabel("My 127.0.0.1 is my castle", JLabel.CENTER);
int height = 670;
int width = 630;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int ex = (screen.width / 2) - (width / 4); // Center horizontally.
int ey = (screen.height / 2) - (height / 4); // Center vertically.
frame.setTitle("Game Over");
frame.setBounds(ex, ey, width / 2, height / 2);
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
info.setBounds(ex, ey, width/2, height/2);
frame.add(info);
frame.setVisible(true);
}
}