Java Swing GUI代码更改没有任何区别
我正在为一个带有Swing的扑克游戏制作GUI,我正在为按钮编写动作监听器,我最初为Check按钮编写了一个动作监听器,SYSOUTs“button listener Works”只是为了检查它是否工作 我已经修改了这段代码,编写了一些合适的侦听器,并且通过某种魔法,呈现的GUI仍然引用了sysout。。。在下面的代码中,我对“检查”按钮的侦听器进行了深入研究,并添加了一个用于调用的按钮,但不知何故忽略了此更改 我甚至完全删除了action listener,保存了所有内容,但它仍然写出了这个幻影代码 此外,ButtonBar中的JComboBox不会显示 TLDR无论我对GUI的代码做什么,它都会显示旧代码的结果 请有人救我Java Swing GUI代码更改没有任何区别,java,swing,user-interface,Java,Swing,User Interface,我正在为一个带有Swing的扑克游戏制作GUI,我正在为按钮编写动作监听器,我最初为Check按钮编写了一个动作监听器,SYSOUTs“button listener Works”只是为了检查它是否工作 我已经修改了这段代码,编写了一些合适的侦听器,并且通过某种魔法,呈现的GUI仍然引用了sysout。。。在下面的代码中,我对“检查”按钮的侦听器进行了深入研究,并添加了一个用于调用的按钮,但不知何故忽略了此更改 我甚至完全删除了action listener,保存了所有内容,但它仍然写出了这个幻
public class ButtonBar extends JPanel {
public ButtonBar() {
setBorder(BorderFactory.createTitledBorder("Moves:"));
JButton checkButton = new JButton("Check");
JButton callButton = new JButton("Call");
JButton raiseButton = new JButton("Raise");
JButton foldButton = new JButton("Fold");
JLabel selectPlayStyle = new JLabel("Select opponent play style");
callButton.addActionListener(e -> System.out.println("Sherbert Lemon"));
//create the comboBox
String[] playStyleStrings = {
"Tight Aggressive",
"Tight Passive",
"Loose Aggressive",
"Loose Passive"
};
JComboBox < String > playStyleList = new JComboBox < String > (playStyleStrings);
playStyleList.setSelectedIndex(0);
playStyleList.addActionListener(e -> System.out.println("none"));
//DELETE THIS
setLayout(new GridBagLayout());
/*this is a class where you can establish where all of your Swing bits and bobs will go.*/
GridBagConstraints gc = new GridBagConstraints();
//These show you how much space is allocated to each row
gc.weightx = 0.2;
gc.weighty = 0.2;
//moves button column - all the JLabels
gc.gridx = 0;
add(checkButton, gc);
gc.gridx = 1;
add(callButton, gc);
gc.gridx = 2;
add(raiseButton, gc);
gc.gridx = 3;
add(foldButton, gc);
gc.gridx = 4;
add(selectPlayStyle, gc);
gc.gridx = 5;
add(playStyleList, gc);
}
}
大型机
它显示了旧代码的结果……我甚至完全删除了action listener,保存了所有内容,但它仍然写出了这个虚拟代码
你的意思是删除、保存和编译吗?在一位同行的建议下,我使用了eclipse clean函数并重新构建了项目。但现在我得到的只是“错误:找不到或加载主类GUI.App”在您的项目中有主方法吗?听起来你的项目配置说你的main不在某个地方。它显示了旧代码的结果…我甚至完全删除了action listener,保存了所有内容,但它仍然写出了这个虚拟代码
你的意思是删除,保存,在一位同行的建议下,我使用了eclipseclean函数并再次构建了该项目。但现在我得到的只是“错误:找不到或加载主类GUI.App”在您的项目中有主方法吗?听起来好像你的项目配置说你的主站在它不在的地方。
public class App {
public static void main(String[] args) {
/*Swing likes to manage it's own thread so this allows it to do so.
This creates a Swing Thread and runs the method inside of it for you */
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//main window for the application to load into
JFrame frame = new MainFrame("Tren Poker Systems");
frame.setSize(1000, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
GameManager gm = new GameManager();
}
}
public class MainFrame extends JFrame {
private OddsPanel oddsPanel;
private CardsPanel cardsPanel;
private ButtonBar buttonBar;
private static JTextArea gameInfoArea;
public MainFrame(String title) {
super(title);
//Create Swing components.
gameInfoArea = new JTextArea("Game information will be found here: ");
oddsPanel = new OddsPanel();
cardsPanel = new CardsPanel();
buttonBar = new ButtonBar();
//Set layout manager.
setLayout(new BorderLayout());
Container container = getContentPane();
container.add(gameInfoArea, BorderLayout.CENTER);
container.add(oddsPanel, BorderLayout.WEST);
container.add(cardsPanel, BorderLayout.EAST);
container.add(buttonBar, BorderLayout.SOUTH);
}
public static void addToGamePane(String information) {
gameInfoArea.append(information + "\n");
}
}