当前页面: 开发资料首页 → Netbeans 专题 → Visual Mobile Designer Custom Components Creating Tables with TableItem
摘要: The Visual Mobile Designer (VMD) is a graphical interface within the NetBeans Mobility Pack that enables you to design mobile applications using drag and drop components.
The Visual Mobile Designer (VMD) is a graphical interface within the NetBeans Mobility Pack that enables you to design mobile applications using drag and drop components. With it, you can determine the application flow and the design of your GUI by using components supplied by the IDE, or by using components you design yourself. The VMD contains many standard components you might use to create your application: Lists, Alerts, Forms, Images, and more. It also includes custom components that simplify the creation of more complex components, such as wait screens, splash screens and tables.
The TableItem component enables you to quickly create tbales that consist of one or more columns, each with a header area and a data area that repeats for each record. The table can be larger than a screen in both directions; users can use a cursor to scroll in all directions.
As you'll see in this tutorial, using the TableItem component of the Visual Mobile Designer (VMD) in the NetBeans Mobility Pack simplifies the design and implementation of data tables in your mobile application.
This example shows you how to use the TableItem and TableModel components in
a mobile application. You'll learn the basic features of the the components,
how to use the components to visualize data in your JavaME application, and
how to manipulate data inside the SimpleTableModel component. The TableItem
custom component discussed in this tutorial visualizes a table from the SimpelTableModel
interface,
displays the data and, optionally, allows the user to
edit the data.
Besides the TableItem custom component we'll use two other MIDP components: TextBox and Form.
Before you begin, you need to install the following software on your computer:
If you are new to the NetBeans Mobility Pack 5.0, you should start with NetBeans Mobility Pack 5.0 Quick Start Guide before continuing.
Take the following steps to install the tableitemexample sample application:
Now that you have seen the TableItem component in action, let's go back to the beginning and create this application. To create the application, you will do the following:
MyTableExample
in the Project Name field. Change the
Project Location to a directory on your system. From now on, we will refer
to this directory as $PROJECTHOME. MyTableExample
project in the Project Window,
then choose File > New File (Ctrl-N) . Under Categories, select Java
Classes. Under File Types, select Java Package. Click Next. tableitemexample
in the Package Name field. Click Finish.
tableitemexample
package in the Project window,
then choose File > New File (Ctrl-N) . Under Categories, select MIDP.
Under File Types, select Visual MIDlet. Click Next. MyTableItemMidlet
into MIDlet Name and MIDP Class
Name fields. Click Finish. TableItem
Example
into the Label property.
.if (command == okCommand1) {
, where it says //insert
pre-action code here)
: /* This part of the code is responsible for
* saving values into the table model
*/
// Get the position of the cursor in the table
int row = tableItem1.getSelectedCellRow();
int column = tableItem1.getSelectedCellColumn();
// Set new value to the table model
simpleTableModel1.setValue(column,row,textBox1.getString());
// Repaint table model on the screen device
simpleTableModel1.fireTableModelChanged();
} else if (command == itemCommand1) {
, where it says //insert
pre-action code here)
: /* This part of the code is responsible for
* getting value from the table model
*/
if (textBox1 != null) {
// Get position of the cursor in the table.
int row = tableItem1.getSelectedCellRow();
int column = tableItem1.getSelectedCellColumn();
// Get value from the table model
Object value = simpleTableModel1.getValue(column,row);
// Set textBox string value
if (value != null)
textBox1.setString(value.toString());
else
textBox1.setString("");
}
Press <F6> to Run the main project.
Alternatively you could select Run > Run Main Project.
The NetBeans IDE provides API documentation—javadocs—for the TableItem and TableModel components, as well as other components you can use in the VMD. To read the javadocs for the TableItem and TableModel components:
org.NetBeans.microedition.lcdui.
You will see links
for the component information
.