MIDRANGE dot COM Mailing List Archive



Home » JAVA400-L » February 2008

Re: Which UI "engine" to use?



fixed

Hi Aaron,

If all you want is a simple dynamic UI there's no need to overcomplicate things... below is a self-contained, executable Swing example of arbitrarily placing some components on a form. Of course some people might say that anything Swing is overcomplicated, but I'm a fan so what the heck. This example may not demonstrate best practices in Swing, but if it's results you're after then this may be right up your alley. (Please disregard the JFormDesigner stuff... that's just me cheating.)

t.

- - -

import java.awt.*;
import javax.swing.*;

public class NullLayoutDemo extends JPanel
{

public NullLayoutDemo()
{
initComponents();
}

private void initComponents()
{
// JFormDesigner - Component initialization - DO NOT MODIFY // GEN-BEGIN:initComponents
label2 = new JLabel();
label3 = new JLabel();
textField1 = new JTextField();
comboBox1 = new JComboBox();
button1 = new JButton();

//======== this ========
setLayout(null);

//---- label2 ----
label2.setText("Field 1");
add(label2);
label2.setBounds(new Rectangle(new Point(15, 20), label2.getPreferredSize()));

//---- label3 ----
label3.setText("Field 2");
add(label3);
label3.setBounds(new Rectangle(new Point(15, 55), label3.getPreferredSize()));
add(textField1);
textField1.setBounds(70, 14, 140, textField1.getPreferredSize().height);
add(comboBox1);
comboBox1.setBounds(70, 50, 140, comboBox1.getPreferredSize().height);

//---- button1 ----
button1.setText("Submit");
add(button1);
button1.setBounds(new Rectangle(new Point(126, 85), button1.getPreferredSize()));

setPreferredSize(new Dimension(225, 125));
// JFormDesigner - End of component initialization //GEN- END:initComponents
}

// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN- BEGIN:variables
private JLabel label2;
private JLabel label3;
private JTextField textField1;
private JComboBox comboBox1;
private JButton button1;
// JFormDesigner - End of variables declaration //GEN-END:variables

public static void main(String[] args)
{
JFrame frame = new JFrame("Null Layout Demo");
frame.setContentPane(new NullLayoutDemo());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}

}


On 20-Feb-2008, at 6:45 PM, Thorbjørn Ravn Andersen wrote:

Aaron Bartell skrev den 20-02-2008 22:38:
Could you elaborate on what you mean by "drawing the screen dynamically"?


I get an XML feed from the server and it will have something like the
following:

<form id="form1">
<button id="btnSubmit" x="12" y="100" value="Submit" />
</form>

Based on that I know I need to display a form with a single button on the
screen which I do by parsing the XML and incrementally "drawing it" by
instantiating AWT objects and adding them to a panel/frame.

The snippet looks very close to something HTML'ish, so perhaps you could
use an XSLT-stylesheet to create HTML you could use in a web page? The
logic for that is very simple.

It all depends on how much functionality and speed you need.

--
Thorbjørn


--
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.






Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact