Java,在窗口中显示背景图运行如下:代码如下:package在窗口中显示背景图;importjava.awt.BorderLayout;importjava.awt.Container;importjava.awt.Graphics;importjava.net.URL;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JComboBox;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JTextField;publicclassBackgroundPanelextendsJFrame{publicBackgroundPanel(){Containercp=getContentPane();cp.setLayout(newBorderLayout());NewPanelp=newNewPanel();cp.add(p,BorderLayout.CENTER);cp.add(newJButton(Button),BorderLayout.SOUTH);p.add(newJTextField(10));p.add(newJButton(Clickme));p.add(newJComboBox());p.add(newJButton(Hello,world!));setSize(400,300);setDefaultCloseOperation(EXIT_ON_CLOSE);setVisible(true);}publicstaticvoidmain(String[]args){newBackgroundPanel();}classNewPanelextendsJPanel{privatestaticfinallongserialVersionUID=1L;publicvoidpaintComponent(Graphicsg){intx=0,y=0;URLurl=getClass().getResource(图片.jpg);ImageIconicon=newImageIcon(url);g.drawImage(icon.getImage(),x,y,getSize().width,getSize().height,this);while(true){g.drawImage(icon.getImage(),x,y,this);if(xgetSize().width&&ygetSize().height)break;if(xgetSize().width){x=0;y+=icon.getIconHeight();}elsex+=icon.getIconWidth();}}}}