tailieunhanh - J2ME in a Nutshell phần 3

trang trong đó một loạt các hồ sơ cung cấp cơ sở vật chất còn thiếu có thể được cung cấp, trong một hình thức thích hợp cho lớp thiết bị mà mỗi hồ sơ được thiết kế. Thông tin hồ sơ thiết bị di động, hoặc MIDP cho ngắn, là một trong những hồ sơ, được sử dụng trên các thiết bị nhỏ gọn với một giao diện người dùng hạn chế | J2ME in a Nutshell public class TextBox2MIDlet extends TextBoxMIDlet implements CommandListener Exit command private static final Command EXIT COMMAND new Command Exit 0 OK command private static final Command OK_COMMAND new Command OK 0 Clear text box content private static final Command CLEAR_COMMAND new Command Clear 1 Reverse the content of the text box private static final Command REVERSE_COMMAND new Command Reverse 1 protected void startApp boolean firstTime started If this is the first execution of startApp install commands if firstTime OK_COMMAND EXIT_COMMAND CLEAR_COMMAND REVERSE_COMMAND this Command implementations. public void commandAction Command c Displayable d if c EXIT_COMMAND destroyApp true notifyDestroyed else if c OK_COMMAND OK pressed else if c CLEAR_COMMAND null else if c REVERSE_COMMAND String str if str null StringBuffer sb new StringBuffer str .toString Notice that this example is implemented by deriving it directly from the TextBoxMIDlet class from the previous example. Of course you wouldn t normally have to do this in the real world but here it serves to show how easy it is to add command handling to an existing class and you don t need to replicate code that you saw earlier The four Commands are defined as static class members for example 99 J2ME in a Nutshell private static final Command EXIT COMMAND new Command Exit 0 Since Commands are simply constant-valued objects you can usually define them in this way and then reuse them wherever you need to which would include adding the same instance to more than one screen if necessary. You can see from Example 4-2 that the EXIT and OK commands use the standard types and respectively which allows the .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.