- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果这有助于解决问题,我可以提供所有代码,但我相信,由于这实际上只影响一个类,因此可以在这里解决它,以简化问题。
我有一个 Solitaire 项目(注意包/类名称,这是反复试验,我没有删除旧项目),它拒绝接受我拥有的 GameArea 类,它扩展了 JPanel。 GameArea 在其自己的单独实例中运行良好,其中测试器类仅与 JFrame 上的 JPanel 一起运行。该测试器类使用 setContentPane(newGame) 将其添加到 JFrame。
在下面的类中,getContentPane().add(newGame) 和 setContentPane(newGame) 均未成功将游戏添加到框架中。此类设置一个带有两个按钮的主菜单。第一个将其带入“开始新游戏”屏幕,然后应该启动游戏的按钮将:
1) 如果使用 getContentPane().add(newGame) 则仅显示绿屏
2) 显示按下的“开始新游戏”,然后如果使用 setContentPane(newGame),则卡住在“开始新游戏”屏幕上。这很令人沮丧,因为 getContentPane().removeAll() 在此之前被调用...但是,使用菜单,我可以返回主菜单,并且仍然在卡住和修复的无限循环中运行。
我怀疑因为我对 Swing 类还不够了解,所以我错过了一些东西。非常感谢任何帮助,因为我需要在 2 天内完成此任务。
package guitestersolitairenew;
/**
*
* @author Josh
* @version 1.00 2015/3/28
*/
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import static javax.swing.Action.MNEMONIC_KEY;
import static javax.swing.Action.SHORT_DESCRIPTION;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.GroupLayout;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class GUITesterSolitaireNew extends JFrame
{
public GUITesterSolitaireNew()
{
initComponents();
setMainMenu();
}
private void initComponents()
{
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(80, 135, 40));
setTitle("Klondike Solitaire");
getContentPane().setBackground(new java.awt.Color(85,130,40));
setSize(1200,700);
setLocationRelativeTo(null);
setResizable(false);
JMenuBar menubar = new JMenuBar();
menubar.add(new JMenu("File"));
class MainMenu extends AbstractAction
{
public MainMenu(String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text,icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
@Override
public void actionPerformed(ActionEvent e)
{
setMainMenu();
}
}
menubar.getMenu(0).add(new JMenuItem(new MainMenu("Main Menu", null, "Return to the main menu.", KeyEvent.VK_M)));
class NewGame extends AbstractAction
{
public NewGame(String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text,icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
@Override
public void actionPerformed(ActionEvent e)
{
newGame(e);
}
}
menubar.getMenu(0).add(new JMenuItem(new NewGame("New Game", null, "Start a new game.", KeyEvent.VK_N)));
class RestartGame extends AbstractAction
{
public RestartGame(String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text,icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
@Override
public void actionPerformed(ActionEvent e)
{
//Fix to restart game.
}
}
menubar.getMenu(0)
.add(new JMenuItem(new RestartGame("Restart Game", null, "Restart the current game.", KeyEvent.VK_R)));
class LoadGame extends AbstractAction
{
public LoadGame(String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text,icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
@Override
public void actionPerformed(ActionEvent e)
{
//Fix to load game.
}
}
menubar.getMenu(0).add(new JMenuItem(new LoadGame("Load Game", null, "Load a saved game.", KeyEvent.VK_L)));
class SaveGame extends AbstractAction
{
public SaveGame(String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text,icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
@Override
public void actionPerformed(ActionEvent e)
{
//Fix to save game
}
}
menubar.getMenu(0).add(new JMenuItem(new SaveGame("Save Game", null, "Create a save file.", KeyEvent.VK_S)));
class ExitAction extends AbstractAction
{
public ExitAction (String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text, icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
@Override
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
menubar.getMenu(0).add(new JMenuItem(new ExitAction("Exit", null, "Exit from the program.", KeyEvent.VK_E)));
menubar.add(new JMenu("Help"));
class Rules extends AbstractAction
{
public Rules (String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text, icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
@Override
public void actionPerformed(ActionEvent e)
{
JFrame rules = new JFrame("Klondike Solitaire Rules");
rules.setSize(400,430);
rules.setLocationRelativeTo(null);
rules.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
JTextArea jta = new JTextArea();
jta.setEditable(false);
Component add = rules.add(jta);
JScrollPane jsp = new JScrollPane();
jsp.setViewportView(jta);
rules.getContentPane().add(jsp, java.awt.BorderLayout.CENTER);
jta.setCaretPosition(jta.getText().length());
jta.append("Klondike Solitaire Rules:\n\n");
jta.setCaretPosition(jta.getText().length());
jta.append("The game starts with a standard 52 card deck.\n");
jta.setCaretPosition(jta.getText().length());
jta.append("The cards are first dealt into 7 'tableaus' where the cards\n");
jta.setCaretPosition(jta.getText().length());
jta.append("are all turned face down and one card laid onto each tableau.\n");
jta.setCaretPosition(jta.getText().length());
jta.append("The left one is turned up, and the process is repeated for the\n");
jta.setCaretPosition(jta.getText().length());
jta.append("2nd to 7th tableaus. The 2nd card in the 2nd tableau is turned up.\n");
jta.setCaretPosition(jta.getText().length());
jta.append("Each tableau receives as many cards as the column position. The\n");
jta.setCaretPosition(jta.getText().length());
jta.append("last card in each tableau will be face up. The deck is placed\n");
jta.setCaretPosition(jta.getText().length());
jta.append("off to the side.\n\n");
jta.setCaretPosition(jta.getText().length());
jta.append("The cards are drawn one at a time from deck. Valid moves are: \n");
jta.setCaretPosition(jta.getText().length());
jta.append("-Move card from deck to tableau\n");
jta.setCaretPosition(jta.getText().length());
jta.append("-Move card from deck to foundation <stacks by suit>\n");
jta.setCaretPosition(jta.getText().length());
jta.append("-Click deck again for another card.\n");
jta.setCaretPosition(jta.getText().length());
jta.append("The deck is cycled if cards are remaining. The cards, after\n");
jta.setCaretPosition(jta.getText().length());
jta.append("being face up, will sort in descent of value and opposing\n");
jta.setCaretPosition(jta.getText().length());
jta.append("face color: i.e. a black 6 can only go on top of a red 7.\n\n");
jta.setCaretPosition(jta.getText().length());
jta.append("The player wins by moving all cards from the deck and tableaus\n");
jta.setCaretPosition(jta.getText().length());
jta.append("to the 4 foundations. The foundations sort by suit in ascending\n");
jta.setCaretPosition(jta.getText().length());
jta.append("order of value, starting with the ace. All aces are low.");
rules.setResizable(false);
rules.setVisible(true);
}
}
menubar.getMenu(1)
.add(new JMenuItem(new Rules("Rules", null, "Show a popup aid for the rules of the game.", KeyEvent.VK_R)));
class Info extends AbstractAction
{
public Info (String text, ImageIcon icon, String desc, Integer mnemonic)
{
super(text, icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
@Override
public void actionPerformed(ActionEvent e)
{
JFrame info = new JFrame("Development Info");
info.setSize(450,225);
info.setLocationRelativeTo(null); //sends it to center of screen
info.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); //does not close application, but actually kills the window when closed
JTextArea jta = new JTextArea();
jta.setEditable(false); //The user can't type on the text box.
Component add = info.add(jta); //abstraction that adds the component jta to window info
JScrollPane jsp = new JScrollPane();
jsp.setViewportView(jta); //puts the text area in the scroll pane
info.getContentPane().add(jsp, java.awt.BorderLayout.CENTER); //centers the text area and scroll pane to be the main subject of the frame
jta.setCaretPosition(jta.getText().length()); //sets the cursor to the end of the text typed so far
//edited out
info.setResizable(false);
info.setVisible(true);
}
}
menubar.getMenu(1)
.add(new JMenuItem(new Info("Info", null, "Information about Klondike Solitaire.", KeyEvent.VK_I)));
setJMenuBar(menubar);
}
private void newGame(java.awt.event.ActionEvent evt)
{
getContentPane().removeAll();
getContentPane().repaint();
setBackground(new java.awt.Color(80, 135, 40));
JLabel jLabel1 = new JLabel();
JButton jButton1 = new JButton();
jLabel1.setBackground(new java.awt.Color(80, 135, 40));
jLabel1.setFont(new java.awt.Font("Kunstler Script", 1, 120)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Klondike Solitaire");
jLabel1.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setMaximumSize(new java.awt.Dimension(800, 100));
jLabel1.setMinimumSize(new java.awt.Dimension(800, 100));
jLabel1.setPreferredSize(new java.awt.Dimension(800, 100));
jLabel1.setRequestFocusEnabled(true);
jButton1.setText("Start New Game");
jButton1.setFont(new java.awt.Font("Times New Roman", 1, 20));
jButton1.setMaximumSize(new java.awt.Dimension(200, 50));
jButton1.setMinimumSize(new java.awt.Dimension(200, 50));
jButton1.setPreferredSize(new java.awt.Dimension(200, 50));
jButton1.addActionListener(new java.awt.event.ActionListener()
{
@Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
startNewGame();
}
});
JLabel replay = new JLabel("Replay game from seed:");
replay.setBackground(new java.awt.Color(80,135,40));
replay.setFont(new java.awt.Font("Times New Roman", 1, 20));
replay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
replay.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
replay.setMaximumSize(new java.awt.Dimension(220, 50));
replay.setMinimumSize(new java.awt.Dimension(220, 50));
replay.setPreferredSize(new java.awt.Dimension(220, 50));
JTextField getSeed = new JTextField();
getSeed.setCaretPosition(getSeed.getText().length());
getSeed.setFont(new java.awt.Font("Times New Roman", 1, 18));
getSeed.setMaximumSize(new java.awt.Dimension(150, 24));
getSeed.setMinimumSize(new java.awt.Dimension(150, 24));
getSeed.setPreferredSize(new java.awt.Dimension(150, 24));
JButton startSeed = new JButton("Start Game");
startSeed.setFont(new java.awt.Font("Times New Roman", 1, 20));
startSeed.setMaximumSize(new java.awt.Dimension(130, 30));
startSeed.setMinimumSize(new java.awt.Dimension(130, 30));
startSeed.setPreferredSize(new java.awt.Dimension(130, 30));
startSeed.addActionListener(new java.awt.event.ActionListener()
{
@Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
startNewGame(Integer.parseInt(getSeed.getText()));
}
});
JButton back = new JButton("Back to Main Menu");
back.setFont(new java.awt.Font("Times New Roman", 1, 20));
back.setMaximumSize(new java.awt.Dimension(200, 50));
back.setMinimumSize(new java.awt.Dimension(200, 50));
back.setPreferredSize(new java.awt.Dimension(200, 50));
back.addActionListener(new java.awt.event.ActionListener()
{
@Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
setMainMenu();
}
});
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addGroup(layout.createSequentialGroup()
.addGap(200, 200, 200)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER, false)
.addComponent(back, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(replay, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(getSeed, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(startSeed, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jButton1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGap(200, 200, 200)
.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(90, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(150, 150, 150)
.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(10, 10, 10)
.addComponent(jButton1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(replay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(getSeed, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(startSeed, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(180, 180, 180)
.addComponent(back, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
);
}
private void startNewGame()
{
getContentPane().removeAll();
getContentPane().repaint();
newGame.newGame();
Container pane = getContentPane();
pane.add(newGame);
setContentPane(pane);
getContentPane().revalidate();
getContentPane().repaint();
}
public void startNewGame(int seed)
{
getContentPane().removeAll();
getContentPane().repaint();
newGame.newGame();
add(newGame);
}
private void setMainMenu()
{
getContentPane().removeAll();
getContentPane().repaint();
setBackground(new java.awt.Color(80, 135, 40));
JLabel jLabel1 = new javax.swing.JLabel();
JButton jButton1 = new javax.swing.JButton();
JButton jButton2 = new javax.swing.JButton();
jLabel1.setBackground(new java.awt.Color(80, 135, 40));
jLabel1.setFont(new java.awt.Font("Kunstler Script", 1, 120)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Klondike Solitaire");
jLabel1.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setMaximumSize(new java.awt.Dimension(800, 100));
jLabel1.setMinimumSize(new java.awt.Dimension(800, 100));
jLabel1.setPreferredSize(new java.awt.Dimension(800, 100));
jLabel1.setRequestFocusEnabled(true);
jButton1.setText("New Game");
jButton1.setFont(new java.awt.Font("Times New Roman", 1, 20));
jButton1.setMaximumSize(new java.awt.Dimension(200, 50));
jButton1.setMinimumSize(new java.awt.Dimension(200, 50));
jButton1.setPreferredSize(new java.awt.Dimension(200, 50));
jButton1.addActionListener(new java.awt.event.ActionListener()
{
@Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
newGame(evt);
}
});
jButton2.setText("Load Game");
jButton2.setFont(new java.awt.Font("Times New Roman", 1, 20));
jButton2.setMaximumSize(new java.awt.Dimension(200, 50));
jButton2.setMinimumSize(new java.awt.Dimension(200, 50));
jButton2.setPreferredSize(new java.awt.Dimension(200, 50));
GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addGroup(layout.createSequentialGroup()
.addGap(200, 200, 200)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER, false)
.addComponent(jButton2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGap(200, 200, 200)
.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(90, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(150, 150, 150)
.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(10, 10, 10)
.addComponent(jButton1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(5, 5, 5)
.addComponent(jButton2)
.addContainerGap(120, Short.MAX_VALUE))
);
}
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
/* Set the Nimbus look and feel */
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
{
System.out.println("Main.main(): 492");
if ("Nimbus".equals(info.getName()))
{
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex)
{
java.util.logging.Logger.getLogger(GUITesterSolitaireNew.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
new GUITesterSolitaireNew().setVisible(true);
}
});
}
private javax.swing.JInternalFrame jInternalFrame1;
private GameArea newGame = new GameArea();
}
最佳答案
不要使用setContentPane
来切换 View ,使用CardLayout
,这就是它的设计目的。请参阅How to Use CardLayout了解更多详情
此外,这样做没有什么意义......
setContentPane(pane);
getContentPane().revalidate();
getContentPane().repaint();
在这种情况下,需要重新验证的不是 contentPane
,而是 contentPane
的父级...
关于java - setContentPane() 和 getContentPane().add() 都不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29338956/
我做了一些研究来了解 JFrame 的使用及其部件,我发现了以下信息: 1- JFrame 的部分 根 Pane 菜单裸露 内容 Pane 玻璃板 2- JFrame 实现 RootPaneConta
我创建了一个扩展 JFrame 的类,默认情况下它会创建一个 JPanel。我试过这个: public class Main extends JFrame { JPanel pane; private
何时使用: Container c = getContentPane(); 以及何时使用: frame.getContentPane(); 最佳答案 getContentPane().setBackg
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我有一个扩展 JPanel 并绘制三角形的类。我从其他类(class)调用它来创建三个三角形,但是当绘制第三个三角形时,前两个三角形消失了。如何添加一起显示的多个三角形。代码如下: 三角形.Java:
我这里有一个代码,但我收到了这个错误。如何修复以下代码的错误? Container container = getContentPane(); 这是运行代码。 import java.awt.Bord
我正在处理我的作业,其中一部分要求我在 JFrame 的网格布局中放置一个红色 block 。之后,用户应该能够通过箭头键更改该红色 block 的位置。 到目前为止,我已经能够将红色 block 添
我创建的这些脚本遇到了一些(非常烦人的)问题。 Sburb.java import java.awt.Color; import javax.swing.*; public class Sburb {
我想从内部 Action 类调用外部类的方法 getContentPane()。我不明白为什么我的代码不起作用。 public class MainFrame extends JFrame {
我找到了三种方法来填充我的 JFrame frame = new JFrame("...")createContentPanel 返回一个 JPanel,createToolBar 返回一个 Tool
在这段代码中: JLabel emptyLabel = new JLabel(""); emptyLabel.setPreferredSize(new Dimension(175, 100)); fr
我访问过很多有关 Java Swing 的教程,我想知道使用 .getContentPane().add(); 添加组件之间的区别或使用.add() ,哪个是最好的? (如果还有“更好”的话)。 最佳
如果这有助于解决问题,我可以提供所有代码,但我相信,由于这实际上只影响一个类,因此可以在这里解决它,以简化问题。 我有一个 Solitaire 项目(注意包/类名称,这是反复试验,我没有删除旧项目),
java swing 中的静态上下文错误无法引用非静态方法 getContentPane() import javax.swing.*; import java.awt.*; import java.
我刚刚开始使用 pro Window Builder 创建 java GUI,默认情况下创建了 JFrame 和 getContentPane 面板,在我继续创建另一个具有卡片布局的 mainPane
在一个 JFrame 中,我用另一个 JPanel 替换了一个 Jpanel 。 package testing; import java.io.*; import java.util.*; impo
我有一个扩展JFrame的类Window和一个扩展JPanel的类Content。 Content 对象被添加到 Window 对象中。 类窗口: public class Window extend
这个问题的标题不言自明。我正在使用 JFrame 制作扫雷的克隆,并且刚刚完成玩家选择游戏大小的起始屏幕。单击按钮时,框架应该会为游戏屏幕做好准备。当我单击一个按钮时,该按钮仍处于“按下”状态并且 J
我发现我可以轻松使用(JPanel)frame.getContentPane()作为默认层JPanel,即使有边框。 (一开始这让我感到惊讶。) 这是一种常见/不常见/好/坏行为吗?为什么?执行此操作
我知道,as of Java 1.5 ,可以像这样将组件添加到 JFrame: myFrame.add(myButton); 代替: myFrame.getContentPane().add(myBu
我是一名优秀的程序员,十分优秀!