请问如何在Java的界面中插入背景图

来源:百度知道 编辑:UC知道 时间:2024/06/19 23:04:40
请各位帮个忙。
我做了个小程序,但在加入背景图时,大小总是不合适,请各位指教一下,谢谢~~
原程序如下:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class BackgroundImage extends JFrame{
public BackgroundImage(){
Animater animator = new Animater();
animator.setOpaque(true);
animator.setBackground(Color.white);
setContentPane(animator);
JButton button1 = new JButton( "确定" );
JButton button2 = new JButton( "取消" );
JLabel lab=new JLabel("");
JLabel lab1=new JLabel("增添歌曲 请选择");
JLabel label1 = new JLabel("歌曲名:") ;
JLabel label2 = new JLabel("歌手:") ;
JLabel label3 = new JLabel(&q

public class BackgroundImage extends JFrame {

public BackgroundImage() {
JButton button1 = new JButton("确定");
JButton button2 = new JButton("取消");
JLabel lab = new JLabel(new ImageIcon("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片\\Blue hills.jpg"));
JLabel lab1 = new JLabel("增添歌曲 请选择");
JLabel label1 = new JLabel("歌曲名:");
JLabel label2 = new JLabel("歌手:");
JLabel label3 = new JLabel("类型:");
JTextField text1 = new JTextField();
JTextField text2 = new JTextField();
JTextField text3 = new JTextField();
label1.setBounds(30, 5, 120, 120);
label2.setBounds(30, 80, 120, 120);
label3.setBounds(30, 150, 120, 120);
text1.setBounds(220, 50, 320, 30);