java – JFrame背景图片

我正在创建一个GUI,虽然是一个简单的,我想要一个背景图像(2048 X 2048)填满整个窗口和一个正方形到左上角,偶尔的64 X 64图像可以加载.提前感谢任何帮助的人:)
编辑:我已经知道如何使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获取更多信息

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...