我在使用 JFrame 和 JPanel 时遇到问题。我的整个代码如下:
class GUIExample
{
public static void main(String args[])
{
//Creating the frame
JFrame frame=new JFrame("Chat Frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setLocationRelativeTo(null);
frame.setDefaultLookAndFeelDecorated(true);
frame.setLayout(new FlowLayout());
//Creating data panel and a label and a text box
JPanel dataPanel=new JPanel();
dataPanel.setLayout(new FlowLayout());
dataPanel.setLocation(0,0);
dataPanel.setOpaque(true);
dataPanel.setBackground(Color.WHITE);
dataPanel.setSize(200,200);
JLabel lblName=new JLabel("Enter Text: ");
lblName.setLayout(new FlowLayout());
lblName.setBounds(0, 10, 2, 2);
dataPanel.add(lblName);
frame.add(dataPanel);
frame.setVisible(true);
}
}
请帮助程序发生了什么