2017-02-18 64 views
1

我正在發送我的類,它通過ObjectOutputStream將JPanel擴展到客戶端,以便他們的GUI將「加載」。正確的方式來序列化一個JPanel?

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

我一切正常 - 只是在客戶端,我忘了將ois.readObject對象設置爲面板!

相關問題