java backgroundpanel,java setLayout(null) 的异常
java setLayout(null) 的错误
........
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
MainFrameTest frame = new MainFrameTest();
frame.setVisible(true);
} catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainFrameTest()
{
BackGroundPanel background_panel = new BackGroundPanel(1144, 712);
this.initComponents();
// this.initDate();
// setSize(1024, 789);
Toolkit toolkit = getToolkit(); // 不懂啊?怎么不是 new 呢?
Dimension dimension = toolkit.getScreenSize();
int screenHeight = dimension.height;
int screenWidth = dimension.width;
int frameHeight = this.getHeight();
int frameWidth = this.getWidth();
this.setLocation((screenWidth - frameWidth) / 2,
(screenHeight - frameHeight) / 2);
this.setComponentsPosition();
}.......
//
private void setBackgroundSize()
{
int frameWidth = this.getWidth();
int frameHeight = this.getHeight();
int modifyFrameHeight = frameHeight - menuBar.getHeight() - 30;
//System.out.println("frameWdith = " + frameWidth);
//System.out.println("frameWidth = " + frameWidth);
//System.out.println("modifyFrameHeight = " + modifyFrameHeight);
background_panel.setBounds(0, 0, frameWidth, modifyFrameHeight);
}
private void initDate()
{
}
private void setComponentsPosition()
{
Component[] component = fastPanel.getComponents();
background_panel.setLayout(null);
fastPanel.add(background_panel, new Integer(Integer.MAX_VALUE)); // 将背景面板添加到原来的fastPanel面板上
this.setBackgroundSize();
for (int i = 0; i
{
fastPanel.remove(component[i]);
background_panel.add(component[i]);
component[i].setBounds(component[i].getX(), component[i].getY(),
component[i].WIDTH, component[i].getHeight());
}
}
package com.MainFrame;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import java.awt.Image;
import java.net.URL;
import javax.swing.JPanel;
public class BackGroundPanel extends JPanel
{
int height;
int width;
Image image;
public BackGroundPanel(int w, int h)
{
URL url = BackGroundPanel.class.getResource("/res/背景.jpg");
image = new ImageIcon(url).getImage();
this.initComponents(); // 调用类中的方法
this.height = h;
this.width = w;
}
public void setWidth(int w)
{
this.width = w;
}
public int getWidth()
{
return this.width;
}
public void setHeight(int h)
{
this.height = h;
}
public int getHeight()
{
return this.height;
}
protected void paintComponent(Graphics g) // 与paintComponent的区别
{
super.paintComponent(g);
Graphics g2 = (Graphics)g;
g2.drawImage(image, 0, 0, width, height, this);
}
private void initComponents()
{
setLayout(new java.awt.BorderLayout()); // 这个是神马意思呢
//this.paintComponent()
}
}
package com.swtdesigner;
/*
public class SwingResourceManager
{
}
*/
import java.awt.Image;
import java.awt.Toolkit;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.ImageIcon;
/**
* Utility class for managing resources such as colors, fonts, images, etc.
*
* This class may be freely distributed as part of any application or plugin.
*
* Copyright (c) 2003 - 2004, Instantiations, Inc.
All Rights Reserved
*
* @author scheglov_ke
*/
public class SwingResourceManager {
/**
* Maps image names to images
*/
private static HashMap m_ClassImageMap = new HashMap();
java backgroundpanel,java setLayout(null) 的异常相关推荐
- java中的setLayOut(null)怎么理解
我们都知道,当我们创建好一个新的窗口后,我们要在这个窗口上面添加组件 但是当我们新建了一个Panel实例并且对它使用setBound()方法后运行出来的结果与我们的预期有很大出入,那是因为你没有使用 ...
- java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity异常的易被忽略的原因
最近在开发Spring+Hibernate+Struts整合开发的时候遇到几次这个异常,故记之. 除了网上说的: jsp页面中各个控件的name属性与Action中模型驱动对象的名字不一致原因之外,还 ...
- java 对象为空异常,Java空对象(null)是怎么回事?
Java 语言支持两种数据类型,分别是基本数据类型和引用数据类型,而 null 是一种特殊的引用数据类型.本节主要介绍 Java 空对象是什么及如何判断对象是否为空. 经过<Java new运算 ...
- 为什么我可以在Java中抛出null? [重复]
本文翻译自:Why can I throw null in Java? [duplicate] This question already has an answer here: 这个问题已经在这里有 ...
- java8避免null_在 Java 8 中避免 Null 检查
如何预防 Java 中著名的 NullPointerException 异常?这是每个 Java 初学者迟早会问到的关键问题之一.而且中级和高级程序员也在时时刻刻规避这个错误.其是迄今为止 Java ...
- 《深入理解JVM.2nd》笔记(二):Java内存区域与内存溢出异常
文章目录 概述 运行时数据区域 程序计数器 Java虚拟机栈 本地方法栈 Java堆 方法区 运行时常量池 直接内存 HotSpot虚拟机对象探秘 对象的创建 第一步 第二步 第三步 第四步 最后一脚 ...
- 解决 java.net.ConnectException: Connection refused: connect 异常
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 一. 我的情况很简单: 只是因为我调用服务端接口方法包名没有写对,应该如下面代码中这样写: call ...
- 《深入理解java虚拟机》第2章 Java内存区域与内存溢出异常
Java与C++之间有一堵由内存动态分配和垃圾收集技术所围成的"高墙",墙外面的人想进去,墙里面的人却想出来. 2.1 概述 https://blog.csdn.net/q5706 ...
- java 异常对象_在java中的异常处理中的异常对象是什么
展开全部 Exception类以及他的子类 的一个实例对象 比如32313133353236313431303231363533e58685e5aeb931333264633563 常见异常 1. j ...
最新文章
- 如何在Linux下使用Gitblit工具创建Git仓库服务
- Ubuntu下串口通信之cutecom
- Android控件的继承关系图
- 【总结】升级Xcode8遇到的问题及解决方案!!! [转]
- 【离散数学中的数据结构与算法】三 同余定理
- [Android-Appium]: 安卓自动化测试: 环境准备
- python中文单词_python – 如何显示中文单词,而不是unicode单词
- 洛谷2863 [Usaco06JAN]牛的舞会
- IDEA java 中文乱码解决方法
- HTML5超炫3D雷达扫描地图玩法
- 企业邮箱网页登录入口,网页电子邮箱怎么注册?
- 栾锟数据科学与计算机学院,山东女子学院学生会第四届第一任干部名单
- ae打开模板显示不出来_打开AE模板提示缺少rsmb pro插件的解决办法
- 搭建gataway所遇问题及解决
- 强关联中Tight-Binding哈密顿量的生成
- [Objective-C]第二天
- Premiere Pro 2023下载安装、新增功能介绍
- JTextField的部分常用使用方法
- 盛世昊通全资收购美国上市公司,即将成功登陆纳斯达克证券交易所
- 行楷练习3 复钩竖、连竖