0
我从Java编程语言开始。我想创建一个JFrame并在其上放置一个背景图像,并在JFrame上方,我想插入小部件:JTextArea,JButton ...但它们不能重叠。这里是我的代码:JFrame上的背景图像
public void go() {
cadre = new JFrame("Premiere Feneêtre");
cadre.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
cadre.setSize(600, 600);
cadre.setVisible(true);`
BorderLayout agencement = new BorderLayout();
JPanel arrierePlan = new JPanel(agencement);
arrierePlan.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
Box boiteABoutons = new Box(BoxLayout.PAGE_AXIS);
boiteABoutons.setSize(150,150);
boiteABoutons.setOpaque(false);
//boiteABoutons.setBackground(Color.yellow);
b1 = new JButton("Bouton 1");
b1.addActionListener(this);
b2 = new JButton("Bouton 2");
b2.addActionListener(this);
b3 = new JButton("Bouton 3");
boiteABoutons.add(b1);
boiteABoutons.add(b2);
boiteABoutons.add(b3);
zoneTexte = new JTextArea();
Panneau p1 = new Panneau();
arrierePlan.add(BorderLayout.SOUTH, boiteABoutons);
arrierePlan.add(BorderLayout.NORTH,zoneTexte);
cadre.getContentPane().add(p1);
cadre.getContentPane().add(arrierePlan);
}
public class Panneau extends JPanel {
public void paintComponent(Graphics g){
try {
Image img = ImageIO.read(new File("C:/Users/........png"));
//g.drawImage(img, 10, 10, this);
g.drawImage(img, 10, 10, this.getWidth(), this.getHeight(), this);
} catch (IOException e) {
e.printStackTrace();
}
}
}
我读过几个关于这个问题的事情,我遇到了这个问题,但没有什么帮助。
谢谢 对不起,我的英文不好