1 Star 0 Fork 17

闪耀之星 / AXmlSwing

forked from dipoo / AXmlSwing 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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(皮肤包,可选)
The MIT License (MIT) Copyright (c) 2015 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

使用xml简化swing开发 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/sunshine_forever/AXmlSwing.git
git@gitee.com:sunshine_forever/AXmlSwing.git
sunshine_forever
AXmlSwing
AXmlSwing
master

搜索帮助

14c37bed 8189591 565d56ea 8189591