- 浏览: 563100 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
jiang2011jiang:
mybatis3源码核心类1--Configuration -
tuyf_hs:
同求 图片
zookeeper+dubbo+dubbo管理集群的简要配置[单机] -
安静听歌:
请问图片还能找的会吗?你的图片和原文的图片都挂了,,,如果有图 ...
zookeeper+dubbo+dubbo管理集群的简要配置[单机] -
ahua186186:
yngwiet 写道楼主,有一个地方不太明白,为什么要用“ge ...
ListView中getChildAt(index)的使用注意事项 -
yngwiet:
楼主,有一个地方不太明白,为什么要用“getChildAt(p ...
ListView中getChildAt(index)的使用注意事项
1.最近在做swing开发,数据量很多,然后碰到swing内存溢出的问题,故参照CSDN上别人的思路写啦一个工具类。
package com.sf.module.common.util;
import java.awt.Component;
import java.awt.Container;
import java.awt.Window;
import java.awt.event.ActionListener;
import java.awt.event.ComponentListener;
import java.awt.event.ContainerListener;
import java.awt.event.FocusListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyListener;
import java.awt.event.InputMethodListener;
import java.awt.event.ItemListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.beans.PropertyChangeListener;
import java.beans.VetoableChangeListener;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.EventListener;
import javax.swing.AbstractButton;
import javax.swing.ActionMap;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.KeyStroke;
import javax.swing.WindowConstants;
import javax.swing.event.AncestorListener;
import javax.swing.event.CaretListener;
import javax.swing.event.ChangeListener;
import javax.swing.text.JTextComponent;
/**
* <p>类型名称: UIReleaseUtil </p>
* <p>类型描述: 释放资源的工具类。</p>
* <p>add by sgh 461245 on 2014-01-07</p>
*/
public class UIReleaseUtil
{
private UIReleaseUtil()
{
}
/**
* 释放资源
* @param cmp
*/
public static void freeSwingObject(Component cmp)
{
freeSwingObjectImpl(cmp);
freeObject(cmp);
}
/**
* 使一个对话框关闭时内存可以被释放
* @param dlg
*/
public static void createFreeableDlg(JDialog dlg)
{
dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dlg.addWindowListener(new WindowCloseAdapter());
}
private static void freeSwingObjectImpl(Component cmp)
{
if (cmp == null)
{
return;
}
freeComponent(cmp);
freeContainer(cmp);
freeJComponent(cmp);
freeButton(cmp);
freeText(cmp);
freeWindow(cmp);
}
private static void freeComponent(Component cmp)
{
//注销并释放监听器资源
EventListener[] listeners = cmp.getComponentListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeComponentListener((ComponentListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getFocusListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeFocusListener((FocusListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getHierarchyListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeHierarchyListener((HierarchyListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getHierarchyBoundsListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeHierarchyBoundsListener((HierarchyBoundsListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getInputMethodListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeInputMethodListener((InputMethodListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getKeyListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeKeyListener((KeyListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getMouseListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeMouseListener((MouseListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getMouseMotionListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeMouseMotionListener((MouseMotionListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getMouseWheelListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeMouseWheelListener((MouseWheelListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getPropertyChangeListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removePropertyChangeListener((PropertyChangeListener) listeners[i]);
}
closeUIFreeable(listeners);
}
private static void freeContainer(Component cmp)
{
if (!(cmp instanceof Container))
{
return;
}
Container container = (Container) cmp;
Component[] cmps = container.getComponents();
for (int i = 0; i < cmps.length; i++)
{
freeSwingObjectImpl(cmps[i]);
}
container.removeAll();
}
private static void freeJComponent(Component cmp)
{
if (!(cmp instanceof JComponent))
{
return;
}
JComponent jcmp = (JComponent) cmp;
//注销并释放监听器资源
EventListener[] listeners = jcmp.getAncestorListeners();
for (int i = 0; i < listeners.length; i++)
{
jcmp.removeAncestorListener((AncestorListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = jcmp.getContainerListeners();
for (int i = 0; i < listeners.length; i++)
{
jcmp.removeContainerListener((ContainerListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = jcmp.getVetoableChangeListeners();
for (int i = 0; i < listeners.length; i++)
{
jcmp.removeVetoableChangeListener((VetoableChangeListener) listeners[i]);
}
closeUIFreeable(listeners);
//释放keystroke
KeyStroke[] keystrokes = jcmp.getRegisteredKeyStrokes();
for (int i = 0; i < keystrokes.length; i++)
{
jcmp.unregisterKeyboardAction(keystrokes[i]);
}
closeUIFreeable(keystrokes);
//其他
ActionMap actionMap = jcmp.getActionMap();
if (actionMap != null)
{
actionMap.clear();
}
jcmp.setActionMap(null);
}
private static void freeWindow(Component cmp)
{
if (!(cmp instanceof Window))
{
return;
}
Window window = (Window) cmp;
//注销并释放监听器资源
EventListener[] listeners = window.getWindowFocusListeners();
for (int i = 0; i < listeners.length; i++)
{
window.removeWindowFocusListener((WindowFocusListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = window.getWindowListeners();
for (int i = 0; i < listeners.length; i++)
{
window.removeWindowListener((WindowListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = window.getWindowStateListeners();
for (int i = 0; i < listeners.length; i++)
{
window.removeWindowStateListener((WindowStateListener) listeners[i]);
}
closeUIFreeable(listeners);
window.dispose();
}
private static void freeButton(Component cmp)
{
if (!(cmp instanceof AbstractButton))
{
return;
}
AbstractButton btn = (AbstractButton) cmp;
//注销并释放监听器资源
EventListener[] listeners = btn.getActionListeners();
for (int i = 0; i < listeners.length; i++)
{
btn.removeActionListener((ActionListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = btn.getChangeListeners();
for (int i = 0; i < listeners.length; i++)
{
btn.removeChangeListener((ChangeListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = btn.getItemListeners();
for (int i = 0; i < listeners.length; i++)
{
btn.removeItemListener((ItemListener) listeners[i]);
}
closeUIFreeable(listeners);
closeUIFreeable(btn.getAction());
btn.setAction(null);
}
private static void freeText(Component cmp)
{
if (!(cmp instanceof JTextComponent))
{
return;
}
JTextComponent text = (JTextComponent) cmp;
EventListener[] listeners = text.getCaretListeners();
for (int i = 0; i < listeners.length; i++)
{
text.removeCaretListener((CaretListener) listeners[i]);
}
closeUIFreeable(listeners);
}
static void freeObject(final Object obj)
{
Field[] fields = obj.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++)
{
if (Modifier.isFinal(fields[i].getModifiers()))
{
continue;
}
if (Modifier.isStatic(fields[i].getModifiers()))
{
continue;
}
//基本类型或者String不释放
if (fields[i].getType().isPrimitive() || fields[i].getType().getName().equals("java.lang.String"))
{
continue;
}
try
{
fields[i].setAccessible(true);
fields[i].set(obj, null);
}
catch (Exception ignore)
{
//dMsg.warn(ignore);
}
}
}
private static void closeUIFreeable(Object[] freeables)
{
for (int i = 0; i < freeables.length; i++)
{
closeUIFreeable(freeables[i]);
}
}
private static void closeUIFreeable(Object freeable)
{
/* if (freeable instanceof UIFreeable)
{
((UIFreeable) (freeable)).freeResource();
}*/
freeable = null;
}
// private static DebugPrn dMsg = new DebugPrn(GuiUtil.class.getName());
}
/**
* <p>文件名称: WindowCloseAdapter.java </p>
* <p>文件描述: 窗口关闭器。
* <p>用于关闭对话框,并回收其资源。</p>
*/
class WindowCloseAdapter extends WindowAdapter
{
/**
* 默认构造方法。
*/
public WindowCloseAdapter()
{
super();
}
/**
* 带是否释放资源参数的构造方法。
* @param dispose boolean
*/
public WindowCloseAdapter(boolean dispose)
{
super();
this.dispose = dispose;
}
/**
* @see java.awt.event.WindowListener#windowClosing(WindowEvent)
* @param e
*/
public void windowClosing(WindowEvent e)
{
Window source = e.getWindow();
if (source != null)
{
if(!dispose)
{
source.hide();
return;
}
// if (source instanceof UIFreeable)
// {
// ((UIFreeable) source).freeResource();
// }
source.dispose();
UIReleaseUtil.freeSwingObject(source);
//GuiUtil.freeSwingObject(source);
}
}
//关闭的时候是否释放资源
private boolean dispose = true;
}
package com.sf.module.common.util;
import java.awt.Component;
import java.awt.Container;
import java.awt.Window;
import java.awt.event.ActionListener;
import java.awt.event.ComponentListener;
import java.awt.event.ContainerListener;
import java.awt.event.FocusListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyListener;
import java.awt.event.InputMethodListener;
import java.awt.event.ItemListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.beans.PropertyChangeListener;
import java.beans.VetoableChangeListener;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.EventListener;
import javax.swing.AbstractButton;
import javax.swing.ActionMap;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.KeyStroke;
import javax.swing.WindowConstants;
import javax.swing.event.AncestorListener;
import javax.swing.event.CaretListener;
import javax.swing.event.ChangeListener;
import javax.swing.text.JTextComponent;
/**
* <p>类型名称: UIReleaseUtil </p>
* <p>类型描述: 释放资源的工具类。</p>
* <p>add by sgh 461245 on 2014-01-07</p>
*/
public class UIReleaseUtil
{
private UIReleaseUtil()
{
}
/**
* 释放资源
* @param cmp
*/
public static void freeSwingObject(Component cmp)
{
freeSwingObjectImpl(cmp);
freeObject(cmp);
}
/**
* 使一个对话框关闭时内存可以被释放
* @param dlg
*/
public static void createFreeableDlg(JDialog dlg)
{
dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dlg.addWindowListener(new WindowCloseAdapter());
}
private static void freeSwingObjectImpl(Component cmp)
{
if (cmp == null)
{
return;
}
freeComponent(cmp);
freeContainer(cmp);
freeJComponent(cmp);
freeButton(cmp);
freeText(cmp);
freeWindow(cmp);
}
private static void freeComponent(Component cmp)
{
//注销并释放监听器资源
EventListener[] listeners = cmp.getComponentListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeComponentListener((ComponentListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getFocusListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeFocusListener((FocusListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getHierarchyListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeHierarchyListener((HierarchyListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getHierarchyBoundsListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeHierarchyBoundsListener((HierarchyBoundsListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getInputMethodListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeInputMethodListener((InputMethodListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getKeyListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeKeyListener((KeyListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getMouseListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeMouseListener((MouseListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getMouseMotionListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeMouseMotionListener((MouseMotionListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getMouseWheelListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removeMouseWheelListener((MouseWheelListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = cmp.getPropertyChangeListeners();
for (int i = 0; i < listeners.length; i++)
{
cmp.removePropertyChangeListener((PropertyChangeListener) listeners[i]);
}
closeUIFreeable(listeners);
}
private static void freeContainer(Component cmp)
{
if (!(cmp instanceof Container))
{
return;
}
Container container = (Container) cmp;
Component[] cmps = container.getComponents();
for (int i = 0; i < cmps.length; i++)
{
freeSwingObjectImpl(cmps[i]);
}
container.removeAll();
}
private static void freeJComponent(Component cmp)
{
if (!(cmp instanceof JComponent))
{
return;
}
JComponent jcmp = (JComponent) cmp;
//注销并释放监听器资源
EventListener[] listeners = jcmp.getAncestorListeners();
for (int i = 0; i < listeners.length; i++)
{
jcmp.removeAncestorListener((AncestorListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = jcmp.getContainerListeners();
for (int i = 0; i < listeners.length; i++)
{
jcmp.removeContainerListener((ContainerListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = jcmp.getVetoableChangeListeners();
for (int i = 0; i < listeners.length; i++)
{
jcmp.removeVetoableChangeListener((VetoableChangeListener) listeners[i]);
}
closeUIFreeable(listeners);
//释放keystroke
KeyStroke[] keystrokes = jcmp.getRegisteredKeyStrokes();
for (int i = 0; i < keystrokes.length; i++)
{
jcmp.unregisterKeyboardAction(keystrokes[i]);
}
closeUIFreeable(keystrokes);
//其他
ActionMap actionMap = jcmp.getActionMap();
if (actionMap != null)
{
actionMap.clear();
}
jcmp.setActionMap(null);
}
private static void freeWindow(Component cmp)
{
if (!(cmp instanceof Window))
{
return;
}
Window window = (Window) cmp;
//注销并释放监听器资源
EventListener[] listeners = window.getWindowFocusListeners();
for (int i = 0; i < listeners.length; i++)
{
window.removeWindowFocusListener((WindowFocusListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = window.getWindowListeners();
for (int i = 0; i < listeners.length; i++)
{
window.removeWindowListener((WindowListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = window.getWindowStateListeners();
for (int i = 0; i < listeners.length; i++)
{
window.removeWindowStateListener((WindowStateListener) listeners[i]);
}
closeUIFreeable(listeners);
window.dispose();
}
private static void freeButton(Component cmp)
{
if (!(cmp instanceof AbstractButton))
{
return;
}
AbstractButton btn = (AbstractButton) cmp;
//注销并释放监听器资源
EventListener[] listeners = btn.getActionListeners();
for (int i = 0; i < listeners.length; i++)
{
btn.removeActionListener((ActionListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = btn.getChangeListeners();
for (int i = 0; i < listeners.length; i++)
{
btn.removeChangeListener((ChangeListener) listeners[i]);
}
closeUIFreeable(listeners);
listeners = btn.getItemListeners();
for (int i = 0; i < listeners.length; i++)
{
btn.removeItemListener((ItemListener) listeners[i]);
}
closeUIFreeable(listeners);
closeUIFreeable(btn.getAction());
btn.setAction(null);
}
private static void freeText(Component cmp)
{
if (!(cmp instanceof JTextComponent))
{
return;
}
JTextComponent text = (JTextComponent) cmp;
EventListener[] listeners = text.getCaretListeners();
for (int i = 0; i < listeners.length; i++)
{
text.removeCaretListener((CaretListener) listeners[i]);
}
closeUIFreeable(listeners);
}
static void freeObject(final Object obj)
{
Field[] fields = obj.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++)
{
if (Modifier.isFinal(fields[i].getModifiers()))
{
continue;
}
if (Modifier.isStatic(fields[i].getModifiers()))
{
continue;
}
//基本类型或者String不释放
if (fields[i].getType().isPrimitive() || fields[i].getType().getName().equals("java.lang.String"))
{
continue;
}
try
{
fields[i].setAccessible(true);
fields[i].set(obj, null);
}
catch (Exception ignore)
{
//dMsg.warn(ignore);
}
}
}
private static void closeUIFreeable(Object[] freeables)
{
for (int i = 0; i < freeables.length; i++)
{
closeUIFreeable(freeables[i]);
}
}
private static void closeUIFreeable(Object freeable)
{
/* if (freeable instanceof UIFreeable)
{
((UIFreeable) (freeable)).freeResource();
}*/
freeable = null;
}
// private static DebugPrn dMsg = new DebugPrn(GuiUtil.class.getName());
}
/**
* <p>文件名称: WindowCloseAdapter.java </p>
* <p>文件描述: 窗口关闭器。
* <p>用于关闭对话框,并回收其资源。</p>
*/
class WindowCloseAdapter extends WindowAdapter
{
/**
* 默认构造方法。
*/
public WindowCloseAdapter()
{
super();
}
/**
* 带是否释放资源参数的构造方法。
* @param dispose boolean
*/
public WindowCloseAdapter(boolean dispose)
{
super();
this.dispose = dispose;
}
/**
* @see java.awt.event.WindowListener#windowClosing(WindowEvent)
* @param e
*/
public void windowClosing(WindowEvent e)
{
Window source = e.getWindow();
if (source != null)
{
if(!dispose)
{
source.hide();
return;
}
// if (source instanceof UIFreeable)
// {
// ((UIFreeable) source).freeResource();
// }
source.dispose();
UIReleaseUtil.freeSwingObject(source);
//GuiUtil.freeSwingObject(source);
}
}
//关闭的时候是否释放资源
private boolean dispose = true;
}
发表评论
-
shiro落地的设计复杂度(最后总结)
2018-06-19 17:22 581经过1周的源码研究,终于对shiro的原理有了深刻的理解,基于 ... -
shiro login成功后保存了哪些数据
2018-06-19 17:05 1476shiro login成功后 保存了Principals 和 ... -
shiro 会话原理分析
2018-06-19 12:40 15951、从哪里获取sessionid每次请求都会尝试获取ses ... -
shiro内部原理分析
2018-06-15 17:07 2413一句话总结:会话域Context一路收集principal ... -
Zookeeper入门-001 源码环境搭建
2018-03-15 11:47 9061.到github下载源码:https://github.c ... -
dubbo服务治理之路由规则研究
2018-01-31 15:50 22111.今天没太多事情,挤 ... -
shiro SecurityUtils.getSubject()深度分析
2018-01-12 17:38 489411.总的来说,SecurityUtils.getSubject ... -
@Async核心实现1 --------AsyncExecutionAspectSupport
2017-12-27 10:34 1983基本原理: 通过spring的扩展接口AbstractBea ... -
从零开始玩转JMX(1):简介和 Standard MBean
2017-08-23 15:20 0http://www.importnew.com/22299. ... -
java基础回顾
2017-08-15 11:21 0http://www.cnblogs.com/skywang1 ... -
mybatis-generator-maven-plugin 插件扩展 增加自定义方法
2017-08-10 16:50 0https://my.oschina.net/alexgaoy ... -
解决了DeferredResult请求长时间占用数据库连接的问题
2017-08-04 09:55 2359最近看了看开源项目appllo配置中心的源码,发现一个很有意思 ... -
httpclient发送webservice
2017-05-03 23:25 0http://aperise.iteye.com/blog/2 ... -
与大师面对面交流:Chris Richardson 来华布道微服务架构
2016-11-28 21:28 825http://www.daocloud.io/microser ... -
eclipse反编译
2016-11-23 20:48 0http://jingyan.baidu.com/articl ... -
spring security
2016-09-12 19:28 0http://www.importnew.com/5641.h ... -
浅析JPA中EntityManager无法remove entity的问题
2016-07-18 21:50 0http://rickqin.blog.51cto.com/1 ... -
Permission Denied(publickey) 解决
2016-07-14 19:18 27821.生成公钥和私钥放到C:\Users\itservice\. ... -
权限管理系统
2016-04-18 13:29 0http://git.oschina.net/ketayao/ ... -
Java工程师成神之路--面试必须复习的基础
2015-12-28 17:20 0http://www.open-open.com/news/v ...
相关推荐
7. **关闭串口**:在完成通信后,记得调用`SerialPort.closePort()`来关闭串口,释放资源。 在Java Swing界面中,你可以创建按钮、文本框等组件来控制串口的操作。例如,一个“打开串口”按钮,一个“关闭串口”...
总的来说,这个坦克大战游戏展示了Java Swing在桌面应用开发中的实用性,涵盖了面向对象编程、图形绘制、事件处理、定时器、碰撞检测以及资源管理等多个Java编程的关键知识点。通过这样的项目实践,开发者不仅可以...
8. **资源管理**:游戏可能包含音频、图片等资源,需要正确加载和释放。Java提供了诸如ImageIcon和AudioClip等类来处理这些资源。 9. **调试与优化**:开发过程中,开发者会遇到各种问题,如性能瓶颈、内存泄漏等,...
Swing是Java编程语言中的一个图形用户界面(GUI)工具包,它是Java Foundation Classes (JFC)的一部分。在Swing中,你可以创建丰富的、跨平台的桌面应用。在Swing应用中实现蓝牙文件发送功能,主要涉及到Java的蓝牙API...
在Java编程领域,Swing库是用于构建图形用户界面(GUI)的一个强大的工具包。它提供了丰富的组件和功能,使得开发者能够创建出复杂的桌面应用程序,其中包括游戏开发。本项目“飞机大战”就是利用Swing库来实现一个...
Java Swing 是Java GUI(图形用户界面)库的一部分,它提供了丰富的组件和工具,用于构建桌面应用程序。在Swing中,浮动面板(Floating Panel)是一种可自定义定位和移动的组件,通常用于创建灵活且交互性强的用户...
9. **资源管理**:为了管理音频文件,开发者需要考虑如何有效地加载和释放资源,防止内存泄漏。 10. **用户体验**:一个优秀的音乐播放器应该提供方便的控制选项,如音量调节、播放进度滑块、随机播放、循环播放等...
为了确保数据正确复制,还应考虑异常处理和资源管理的问题,比如使用try-catch结构来捕获I/O操作中可能发生的异常,并确保在操作完成后关闭流,释放系统资源。 本文中提到的技术和方法是计算机软件应用技术领域内的...
在这个小项目中,我们使用了Swing库来构建用户界面,Swing是Java提供的一个轻量级的GUI(图形用户界面)工具包,非常适合开发桌面应用程序。 在Java中,Socket通常用于实现客户端-服务器架构。Socket类代表了网络上...
在Java编程中,Swing是一个用于构建桌面应用程序的图形用户界面(GUI)工具包。有时,我们可能需要在Swing应用中连接到数据库以实现数据的存储和检索。以下是一个详细的Java Swing连接数据库的步骤,以SQL Server为例...
6. 关闭连接,释放资源。 在整合Swing和MySQL时,可以创建一个数据库模型类,封装数据库操作,使业务逻辑和视图分离。此外,还可以利用Swing的事件监听机制,当用户在界面上触发某个操作时,如点击保存按钮,对应的...
4. 绘制完成后,记得调用Graphics2D对象的dispose()方法释放资源。 在这个项目中,描述提到了"封装类工具类",这意味着开发者可能创建了一些辅助类来简化流程图的绘制过程。这些类可能包括: - `FlowChart`类:...
6. 关闭资源:完成操作后,记得关闭Statement、Connection以及可能的ResultSet,以释放数据库资源。 在描述的"很简单的应用"中,我们可能会创建一个Teacher类,封装教师的信息,并提供用于与数据库交互的方法。这些...
Swing是Java提供的一种用于构建桌面应用的图形用户界面(GUI)工具包,它属于Java Foundation Classes (JFC)的一部分。这个“KTV管理系统”项目利用Swing来创建了一个完整的用户界面,为KTV业务提供了便捷的操作与...
Swing是Java AWT(抽象窗口工具包)的扩展,提供了一组组件,如按钮、文本框、面板等,用于构建用户界面。Swing组件是轻量级的,这意味着它们不依赖于操作系统提供的图形功能,因此跨平台兼容性更好。 在这款游戏中...
- **工具准备**:准备好所需的开发工具,如Eclipse或IntelliJ IDEA。 #### 二、事件与用户交互 ##### 事件基础 - **事件模型**:Swing采用了委托事件模型,该模型将事件处理逻辑分离到独立的监听器类中。 - **事件...
5. **关闭资源**:完成操作后,务必关闭结果集、Statement和连接,以释放数据库资源。 在实际开发中,为了提高安全性,密码通常不会以明文形式存储,而是存储其哈希值。登录时,用户输入的密码也会先进行哈希处理,...
3. **图形绘制**:Java的`Graphics2D`类是Swing中用于绘制2D图形的关键工具。在这个项目中,游戏中的飞机、子弹、敌人等元素都是通过`Graphics2D`在屏幕上绘制出来的。开发者需要掌握如何使用`drawRect`、`drawImage...
本篇将详细探讨一款基于Java Swing开发的星际争霸游戏源代码,让我们一起深入理解其背后的编程原理和技术实现。 Java Swing是Java Foundation Classes (JFC)的一部分,它提供了丰富的用户界面组件,如按钮、面板、...
Java Swing 是Java编程语言中的一个图形用户界面(GUI)工具包,它是Java Foundation Classes (JFC)的一部分。在“java连连看代码SWING”这个项目中,开发者使用了Swing库来构建一个连连看游戏,该游戏拥有图形化界面...