【发布时间】:2014-03-06 03:22:54
【问题描述】:
请解释为什么它不起作用,您能否发布解决此问题的解决方案。非常感谢您提前。
public class Run extends JFrame{
/** Fields **/
static JPanel jpanel;
private int x, y;
/** Constructor **/
public Run() {
/** Create & Initialise Things **/
jpanel = new JPanel();
x = 400; y = 400;
/** JPanel Properties **/
jpanel.setBackground(Color.red);
jpanel.setPreferredSize(new Dimension(20, 30));
/** Add things to JFrame and JPanel **/
add(jpanel);
/** JFrame Properties **/
setTitle("Snake Game");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setCursor(null);
setResizable(false);
setSize(new Dimension(x,y));
setLocationRelativeTo(null);
setVisible(true);
}
/** Set the Cursor **/
public void setCursor() {
setCursor (Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
/** Main Method **/
public static void main(String [ ] args) {
Run run = new Run();
run.setCursor();
}
}
【问题讨论】:
-
你说的不起作用是什么意思?
-
嗯,我有大小为 400、400 的 JFrame,但是当我尝试将 JPanel 设置为大小 30、30 时,它只会从 JFrame 继承原始大小。