gpt4 book ai didi

Java JFrame_JPanel

转载 作者:行者123 更新时间:2023-12-02 07:32:49 25 4
gpt4 key购买 nike

我在使用 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);
}
}

请帮助了解该程序发生了什么

最佳答案

它显示一个带有标签的窗口,上面写着“输入文本:”有什么问题吗??

关于Java JFrame_JPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12703187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com