标题:java添加背景,帮帮忙
取消只看楼主
星辰star
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-5-16
结帖率:0
 问题点数:0 回复次数:0 
java添加背景,帮帮忙
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class qq<BackgroundPanel> extends JFrame {
    private JPanel jPanel1;
    private JPanel jPanel2;
    private JPanel jPanel3;
    private ImageIcon background;
    public static void main(String[] args) {
       qq text=new qq();
       text.setLocationRelativeTo(null);
       text.setVisible(true);
    }
    private qq()
    {
        super();
        init();
    }
    private void init(){
    try{
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            jPanel1 = new JPanel();
             getContentPane().add(jPanel1, BorderLayout.CENTER);
             jPanel1.setLayout(null);
             {
                // background=new ImageIcon("picture/1.png");
                 jPanel2=new JPanel(){
                 public void paintComponents(Graphics g) {
                     Image img = new ImageIcon("2.jpg").getImage();
                     super.paintComponent(g);
                      g.drawImage(img,0,0,this);
                 }
                 };
                 jPanel1.add(jPanel2);
                // jPanel2.setBackground(java.awt.Color.BLUE);
                 jPanel2.setBounds(0, 0, 300, 75);
             }
        }
        pack();
        setSize(300, 620);
    }catch (Exception e) {
        e.printStackTrace();
       }
    }
}
没有背景啊!!!高手帮忙啊
搜索更多相关主题的帖子: class background private public 
2011-12-06 20:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-357147-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.250885 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved