java中可不可以在按钮上添加文本域

来源:百度知道 编辑:UC知道 时间:2024/07/05 00:21:41
急用啊!!!各位大虾帮帮忙~~~~如果可以,请把代码发一下,先谢过了

import javax.swing.*;
import java.awt.*;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
Container container = frame.getContentPane();
container.setLayout(new FlowLayout());
JButton button = new JButton("dd");
JTextField field = new JTextField(10);
button.add(field);
container.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200,200);
frame.setVisible(true);
}
}