我发送的类将JPanel通过ObjectOutputStream扩展到客户端,以便他们的GUI“加载”。
public class ClickOptionPanel extends JPanel implements Serializable {
private Font font = new Font("Arial", Font.BOLD, 13);
private JLabel clickerTitle;
private JSlider clickerMaxSlider, clickerMinSlider;
private JTextField clickerMinField, clickerMaxField;
private JCheckBox clickInsideMinecraft, autoBlock;
public ClickOptionPanel() {
setLayout(new BorderLayout());
add(getClickerTitlePanel(), BorderLayout.NORTH);
add(getClickerSliderPanel(), BorderLayout.CENTER);
add(getCheckBoxPanel(), BorderLayout.SOUTH);
}
private JPanel getClickerTitlePanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEtchedBorder());
clickerTitle = new JLabel("Clicker Options");
clickerTitle.setFont(font);
panel.add(clickerTitle);
return panel;
}
private JPanel getClickerSliderPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
clickerMaxSlider = new JSlider(0, 200, 125);
clickerMaxSlider.setPreferredSize(new Dimension(300, 45));
clickerMinSlider = new JSlider(0, 200, 75);
clickerMinSlider.setPreferredSize(new Dimension(300, 45));
panel.add(clickerMaxSlider, BorderLayout.NORTH);
panel.add(clickerMinSlider, BorderLayout.CENTER);
panel.add(getClickFieldPanel(), BorderLayout.SOUTH);
return panel;
}
private JPanel getClickFieldPanel() {
JPanel panel = new JPanel();
clickerMaxField = new JTextField(10);
clickerMaxField.setFont(font);
clickerMaxField.setHorizontalAlignment(SwingConstants.CENTER);
clickerMinField = new JTextField(10);
clickerMinField.setFont(font);
clickerMinField.setHorizontalAlignment(SwingConstants.CENTER);
panel.add(clickerMinField);
panel.add(clickerMaxField);
return panel;
}
private JPanel getCheckBoxPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder(BorderFactory.createEtchedBorder());
clickInsideMinecraft = new JCheckBox("Only click inside of Minecraft: ");
clickInsideMinecraft.setHorizontalTextPosition(SwingConstants.LEFT);
autoBlock = new JCheckBox("Enable auto-block: ");
autoBlock.setHorizontalTextPosition(SwingConstants.LEFT);
panel.add(clickInsideMinecraft, BorderLayout.NORTH);
panel.add(autoBlock, BorderLayout.SOUTH);
return panel;
}
我正在发送JPanel。我在发送之前创建了一个新实例。
JPanel空白了 - 为什么会这样?
答案 0 :(得分:0)
我做的一切都正确 - 只是在客户端,我忘了将ois.readObject对象设置为面板!