如何让文本框出现在此 JFrame 上?在 JFrame 本身之上构建所有内容也是一种好习惯吗?还是覆盖 JPanel 并在其上构建所有内容更好?
提前致谢!
public class GUI {
private static JFrame frame = new JFrame("FrameDemo");
public GUI() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BufferedImage myImage = null;
try {
myImage = ImageIO.read(new File("C:/Users/Desktop/background.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
frame.setContentPane(new ImageFrame(myImage));
JTextField field = new JTextField(10);
frame.add(field, BorderLayout.SOUTH);
Dimension dimension = new Dimension();
dimension.setSize(950, 800);
frame.setSize(dimension);
frame.setVisible(true);
}
}