Skip to main content

How to API

2 replies [Last post]
tgore03
Offline
Joined: 2006-02-17
Points: 0

How do I just using API write a hello world? And then add a table. (I do not want to use XML now.

This would do Swing:
public static void main(String[] args) {

JButton button = new JButton("foo");
JFrame frame = new JFrame();
frame.getContentPane().add(button);
frame.pack();
frame.setVisible(true);

THANK you
Tom

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mark Davidson
Offline
Joined: 2006-02-17
Points: 0

You may want to take a look at this project:

https://j2se-webservice-blueprint.dev.java.net/

This project was developed for the "Java Desktop Clients and Web Services" talk and lab for JavaOne 04. The focus of this project is to investigate and demonstrate preferred practices for designing desktop clients which connect to web service endpoints.

I developed the client using swingx api. All the code which uses the swingx classes is in the class "Main":

https://j2se-webservice-blueprint.dev.java.net/source/browse/j2se-webser...

We'll be documenting this project a lot more in the coming weeks. In the meantime, you may want to take a look at the ws/docs/index.html which describes many of the desktop client/web service issues that were discussed in the talk/lab.

Hope this helps.

--Mark

rameshgupta
Offline
Joined: 2004-06-04
Points: 0

> How do I just using API write a hello world? And then
> add a table. (I do not want to use XML now.

With JDNC, you do not *have* to use XML, if you don't want to. Also, the three layers of JDNC are cleanly separated, with no unnatural dependencies -- So, you don't have to pay the price for features you don't want or need.

Using the Swing Extensions layer is just like using Swing:

public static void main(String[] args) {
TableModel myModel = new MyTableModel();
JXTable table = new JXTable(myModel);

// Call standard JTable methods:
table.setRowHeight(22);
table.setRowMargin(1);

// Call new JXTable methods:
table.setFilters(new FilterPipeline(
new Filter[] {
new ShuttleSorter(0, true) // column 0 ascending
}));
table.setHighlighters(new HighlighterPipeline(
new Highlighter[] {
AlternateRowHighlighter.linePrinter,
}));

// Put it all together using plain old Swing code:
JFrame frame = new JFrame();
JScrollPane scroller = new JScrollPane(table);
frame.getContentPane().add(scroller);
frame.pack();
frame.setDefaultCloseOperation(
JFrame.DISPOSE_ON_CLOSE);

// Finally, make it visible:
frame.setVisible(true);
}

Using the JDNC Java API layer is similar, but even simpler. For example, JNTable (not JXTable) automatically provides a scroll pane and alternate rows:

public static void main(String[] args) {
TableModel myModel = new MyTableModel();
JNTable table = new JNTable(myModel);

// To call JTable/JXTable methods:
// table.getTable().setRowHeight(22);

// Call new JNTable methods:
table.setHasColumnControl(true);

// Put it all together using plain old Swing code:
JFrame frame = new JFrame();
frame.getContentPane().add(table);
frame.pack();
frame.setDefaultCloseOperation(
JFrame.DISPOSE_ON_CLOSE);

// Finally, make it visible:
frame.setVisible(true);
}