java swing 按钮不显示

按钮迟迟不出现,网上说加了super.paint(g);也没用。555~~~
package game01;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class Test extends JFrame {
public Test()
{
this.setVisible(true);
this.setLocation(0,0);
this.setSize(700,700);
this.setLayout(null);
JPanel p1 = new JPanel();
p1.setLayout(null);
p1.setBounds(0,0,700,700);
JButton b1 = new JButton("b1");
b1.setBounds(0,0,100,100);
p1.add(b1);
this.add(p1);
}
public void paint(Graphics g)
{
super.paint(g);
BufferedImage bi = new BufferedImage(700,700,BufferedImage.TYPE_INT_RGB);
Graphics g2 = bi.createGraphics();
g2.setColor(Color.WHITE);
g2.fillOval(150, 150, 100, 100);
g.drawImage(bi, 0, 0, this);

}
/**
* @param args
*/
public static void main(String[] args)
{
Test test = new Test();
}

}

你重写的BufferedImage区域会覆盖掉button。(button和BufferedImage区域重叠)g.drawImage(bi, 0,0, this); 改成g.drawImage(bi, 0,130, this); 差不多就可以出现,重写的是多的30 是JFrame的标题栏宽度。追问

怎样才能让按钮覆盖在BufferedImage上呢

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-08-24

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;


public class Test extends JFrame
{
public Test()
{
this.setLocation(0, 0);
this.setSize(700, 700);
this.setLayout(null);
JPanel p1 = new JPanel();
p1.setLayout(null);
p1.setBounds(0, 0, 700, 700);
JButton b1 = new JButton("b1");
b1.setBounds(0, 0, 100, 100);
p1.add(b1);
this.add(p1);
this.setVisible(true);
}
public void paint( Graphics g )
{
super.paint(g);
BufferedImage bi =
new BufferedImage(700, 700, BufferedImage.TYPE_INT_RGB);
Graphics g2 = bi.createGraphics();
g2.setColor(Color.WHITE);
g2.fillOval(150, 150, 100, 100);
g.drawImage(bi, 0, 0, this);

}
/**
 * @param args
 */
public static void main( String[] args )
{
Test test = new Test();
}

}