有这个Java JFrame类,我想在其中使用boxlayout,但是我收到一条错误,指出java.awt.AWTError: BoxLayout
无法共享
这是代码
public class secureChat {
private JFrame myFrame;
private int width;
private int height;
private JPanel allPanel;
private JPanel titlePanel;
private JPanel holdPanel;
private JPanel serverPanel;
private JPanel portPanel;
private JPanel encrypPanel;
private JPanel decrypPanel;
public static void main(String[] args) {
secureChat S = new secureChat();
}
public secureChat()
{
width = 600;
height = 480;
myFrame = new JFrame();
myFrame.setLocation(450, 200);
myFrame.setTitle("secure chat");
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(width, height);
allPanel = new JPanel();
myFrame.add(allPanel);
allPanel.setLayout(new BoxLayout(allPanel, BoxLayout.Y_AXIS));
allPanel.setBackground(Color.blue);
titlePanel = new JPanel();
allPanel.add(titlePanel);
titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.X_AXIS));
holdPanel = new JPanel();
allPanel.add(holdPanel);
holdPanel.setLayout(new BoxLayout(holdPanel, BoxLayout.X_AXIS));
}
}
任何帮助都是apreciated