Java 为什么鼠标移动到按钮的位置时才会显示按钮
package窗口;importjava.awt.*;importjavax.swing.*;publicclassTestFrame1extendsJFrame{/**...
package 窗口;
import java.awt.*;
import javax.swing.*;
public class TestFrame1 extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
private Image image = null;
private ImageIcon icon = new ImageIcon("images/1.jpg");
JPanel jp1,jp2,jp3;
JButton jb1,jb2,jb3;
JLabel jl1,jl2;
public TestFrame1()
{
super("测试窗口");
jl1=new JLabel("");
jl2=new JLabel("");
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jb1=new JButton(" 借书 ");
jb2=new JButton(" 还书 ");
jb3=new JButton(" 租还查询 ");
jp1.add(jb1);
jp2.add(jb2);
jp3.add(jb3);
this.setLayout(new GridLayout(4, 1));
this.add(jl1);
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.setSize(500,360);
this.setVisible(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public static void main(String[] args)
{
new TestFrame();
}
public void paint(Graphics g)
{
super.paint(g);
image = icon.getImage();
g.drawImage(image, 0, 0, null);
}
} 展开
import java.awt.*;
import javax.swing.*;
public class TestFrame1 extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
private Image image = null;
private ImageIcon icon = new ImageIcon("images/1.jpg");
JPanel jp1,jp2,jp3;
JButton jb1,jb2,jb3;
JLabel jl1,jl2;
public TestFrame1()
{
super("测试窗口");
jl1=new JLabel("");
jl2=new JLabel("");
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jb1=new JButton(" 借书 ");
jb2=new JButton(" 还书 ");
jb3=new JButton(" 租还查询 ");
jp1.add(jb1);
jp2.add(jb2);
jp3.add(jb3);
this.setLayout(new GridLayout(4, 1));
this.add(jl1);
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.setSize(500,360);
this.setVisible(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public static void main(String[] args)
{
new TestFrame();
}
public void paint(Graphics g)
{
super.paint(g);
image = icon.getImage();
g.drawImage(image, 0, 0, null);
}
} 展开
1个回答
2017-10-13
展开全部
绘背景后,再绘一下
jb1.repaint();
jb2.repaint();
jb3.repaint();
~
~
~~~~~
jb1.repaint();
jb2.repaint();
jb3.repaint();
~
~
~~~~~
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询