java jframe背景图片_java – JFrame背景图片

这是将背景图像添加到jframe中的简单示例

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class BackgroundImageJFrame extends JFrame

{

JButton b1;

JLabel l1;

public BackgroundImageJFrame()

{

setTitle("Background Color for JFrame");

setSize(400,400);

setLocationRelativeTo(null);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

/*

One way

-----------------

setLayout(new BorderLayout());

JLabel background=new JLabel(new ImageIcon("C:\Users\Computer\Downloads\colorful design.png"));

add(background);

background.setLayout(new FlowLayout());

l1=new JLabel("Here is a button");

b1=new JButton("I am a button");

background.add(l1);

background.add(b1);

*/

// Another way

setLayout(new BorderLayout());

setContentPane(new JLabel(new ImageIcon("C:\Users\Computer\Downloads\colorful design.png")));

setLayout(new FlowLayout());

l1=new JLabel("Here is a button");

b1=new JButton("I am a button");

add(l1);

add(b1);

// Just for refresh :) Not optional!

setSize(399,399);

setSize(400,400);

}

public static void main(String args[])

{

new BackgroundImageJFrame();

}

}

>点击here获取更多信息

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值