1
我使用CookSwing(http://cookxml.yuanheng.org/cookswing/)构建Java Swing UI,但该网站没有很多信息。我被困在试图让我的Java类从表单中的文本字段中检索字符串(用XML声明)。这应该很容易,但我没有尝试过。有没有人有这样的经验?下面是Java类:CookSwing - 从文本字段检索字符串
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import cookxml.cookswing.CookSwing;
public final class CookSwingForm
{
// Listener for the Quit button
public ActionListener exitAction = new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
System.exit(0);
}
};
public CookSwingForm()
{
CookSwing cookSwing = new CookSwing(this);
cookSwing.render("sampleform.xml").setVisible(true);
}
public static void main(String[] args)
{
new CookSwingForm();
}
}
这里是XML文件(“sampleform.xml”):
<frame title="Sample Form" size="300,70"
defaultcloseoperation="EXIT_ON_CLOSE">
<borderlayout>
<constraint location="West">
<textfield columns="20" />
</constraint>
<constraint location="East">
<button text="Quit" actionlistener="exitAction" />
</constraint>
</borderlayout>
</frame>
我只需要有Java类检索从该公司在声明的文本框字符串XML文件。任何帮助是极大的赞赏。谢谢!
是的,我可以在XML文件中给文本字段添加一个ID或一个名称,但是如何使用它来引用来自Java类的文本字段? – Mike
@Mike,用你的例子编辑我的答案。 –
完美运作。谢谢,戒指! – Mike