最近我一直在玩 Java Swing,并试图创建一个自定义的 Minecraft 服务器启动器。当我按下标有“属性”的按钮时,它应该更改为一个新面板并在某一时刻完成。但是,由于某种原因,我看不到它不再起作用。有人可以帮忙吗?
package custommcserver;
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
class Window extends JFrame implements ActionListener , ItemListener
{
JPanel mainPnl = new JPanel(new GridLayout(2,1));
JPanel propPnl = new JPanel();
JButton startBtn = new JButton("Start");
JButton stopBtn = new JButton("Stop");
JButton propBtn = new JButton("Properties");
JCheckBox allowNether = new JCheckBox("Allow players to visit the Nether dimension");
public Window()
{
super("Custom Minecraft Server Launcher") ;
setSize(500,200) ;
setDefaultCloseOperation(EXIT_ON_CLOSE) ;
add(mainPnl) ;
mainPnl.add(startBtn);
mainPnl.add(stopBtn);
mainPnl.add(propBtn);
stopBtn.setEnabled(false);
startBtn.addActionListener(this);
stopBtn.addActionListener(this);
propBtn.addActionListener(this);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == stopBtn)
{
stopBtn.setEnabled(false);
startBtn.setEnabled(true);
}
if (event.getSource() == startBtn)
{
stopBtn.setEnabled(true);
startBtn.setEnabled(false);
if (event.getSource() == propBtn)
{
add(propPnl);
mainPnl.setVisible(false);
propPnl.setVisible(true);
propPnl.add(allowNether);
}
}
}
@Override
public void itemStateChanged(ItemEvent event) {
throw new UnsupportedOperationException("Not supported yet.");
}
}