• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

AXmlSwing: 使用xml简化swing开发

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

AXmlSwing

开源软件地址:

https://gitee.com/dipoo/AXmlSwing

开源软件介绍:

AXmlSwing

使用xml简化swing开发###文档请查看wiki###demo请查看AXmlSwingDemo###如何使用#####1、配置文件src/axmlswing.cfg.xml

<?xml version="1.0" encoding="UTF-8"?><configuation>	<!-- 配置扫描事件监听器的包名 -->	<scan-package>demo.listeners</scan-package>	<!-- 自定义属性,可用于布局文件中:如${title},	或者通过VarsManager.getVarValue(name)获取值 -->	<properties>		<property name="title">虾片神器</property>		<property name="alert">下载地址不能为空</property>	</properties>	<!-- 定义标签全局属性 -->	<tag-default>		<tag name="JLabel">			<attr name="foreground">blue</attr>		</tag>		<tag name="JTextField">			<attr name="columns">10</attr>		</tag>	</tag-default></configuation>

#####2、布局文件demo.xml

<?xml version="1.0" encoding="UTF-8"?><!-- 	${rootPath}:项目根目录src(内置变量) --><JFrame id="mainWindow" title="${title}" width="300" height="300"	locationRelativeTo="null" defaultCloseOperation="3" 	iconImage="${rootPath}/anchor.gif" layout="0">	<JMenuBar bounds="5, 0, 280, 25" cursor="HAND_CURSOR">		<JMenu text="任务">			<JMenuItem text="打开"/>			<JMenuItem text="保存"/>			<JMenuItem text="另存为"/>			<JMenuItem onclick="exit()" text="退出"/>		</JMenu>		<JMenu text="编辑">			<JMenuItem text="新建"/>			<JMenuItem text="删除"/>		</JMenu>		<JMenu text="搜索"/>		<JMenu text="帮助"/>	</JMenuBar>	<JLabel text="地址" bounds="10, 50, 60, 30" icon="${rootPath}/anchor.gif" />	<JTextField id="urlField" text="逗比"		bounds="60, 50, 220, 30" />	<JButton id="downBtn" text="下载" icon="${rootPath}/anchor.gif"		toolTipText="按钮提示" bounds="100, 100, 100, 30"		foreground="red" cursor="HAND_CURSOR" font="微软染黑,0,12"/></JFrame>

####3、事件处理DownBtnListener.java

    package demo.listeners;    @EventAnnotation("downBtn")//标明id=downBtn控件事件监听器    //所有控件的事件监听器都要继承AbstractListener类并改写其中的方法    public class DownBtnListener extends AbstractListener{        public void mouseClicked(MouseEvent e) {			JButton btn = (JButton) e.getSource();			JFrame mainWindow = (JFrame) ComponentManager.getMainWindow();			JOptionPane.showMessageDialog(null, "你好, 主窗口名称为:" + 			     mainWindow.getTitle() + ",按钮text:" + btn.getText());			JTextField field=(JTextField)ComponentManager.getComponent("urlField");			JOptionPane.showMessageDialog(null, field.getText());		}    }

#####4、加载布局文件demo.java

    package demo;	    public class Demo {        public static void main(String[] args) throws Exception {		  //加载布局文件		  GuiXmlLoader.load("demo.xml");		}    }

#####5、效果图demo###依赖包

  • dom4j-1.6.1.jar
  • jaxen-1.1.1.jar
  • beautyeye_lnf.jar(皮肤包,可选)

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap