代码拉取完成,页面将自动刷新
同步操作将从 dipoo/AXmlSwing 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
使用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、效果图 ###依赖包
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。