异度部落格

学习是一种生活态度。

0%

需要 xsel、zenity 和 base64

1
2
3
4
sudo apt-get install xsel
sudo apt-get install ael
sudo apt-get install zenity
sudo apt-get install mkvtoolnix

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
save_dir0=~/Download  #最后面千万不要加“/”,不然保存文件的时候可能找不到路径。
max_num=20 #在此设定axel的最大连接数
[ ! -d $save_dir0 ] && mkdir -p $save_dir0
#下载链接,给出一个下载进度条,并且当点击“取消”的时候将该axel废掉武功。
DOWNLOAD() {
axel -n $max_num "$1" -o "$2/$3" |while read a;do
echo "$a" |grep "<!-- /[D -->" |sed 's/^/[ *//;s/%.*$//;s/^Download.*$/100/'
done |zenity --progress --auto-close --text="下载 $true_url$2" --width="350" 2>/dev/null &
axel_info=`ps ax |grep "axel.*$1" |awk '{print $1"-"$2}'`
axel_tty=`echo $axel_info |sed 's/^.*-//'`
axel_pid=`echo $axel_info |sed 's/-.*$//'`
while true;do
if ! [ "`ps ax |grep "$axel_tty.*zenity"`" ];then
[ "`ps -A |grep "$axel_pid"`" ] && kill $axel_pid
break
fi
sleep 1
done &
}
#出来一个动作选择菜单,选择下一步动作。
UI() {
choice=$(zenity --list --title "默认保存目录为:$save_dir0" --text "解析得URL:$true_url" /
--column "选项" --column "动作" /
A 下载至默认目录 B 选择目录并下载 C 保存链接到剪贴板 2>/dev/null);
case $choice in
'A')
file_name=`zenity --entry --title="重命名文件" --text="请输入一个文件名(取消则按链接默认命名)" 2>/dev/null`
DOWNLOAD $true_url $save_dir0 $file_name
file_name=""
;;
'B')
save_dir=`zenity --file-selection --directory 2>/dev/null`
file_name=`zenity --entry --title="重命名文件" --text="请输入一个文件名(取消则按链接默认命名)" 2>/dev/null`
DOWNLOAD $true_url $save_dir $file_name
file_name=""
;;
'C')
printf "$true_url" |xsel -i -b
;;
esac
}
#从剪贴板获取迅雷地址,并将其解码成http的。
DECODE() {
str0="`xsel -b`"
if [ `echo "$str0" |grep "^thunder"` ] && [ "$str" != "$str0" ];then
str="$str0"
true_url="`printf "$str" |sed 's/^thunder://////' |base64 -d |sed 's/^AA//;s/ZZ$//'`"
[ ! -z "$true_url" ] && UI
true_url=""
fi
}

while true;do
DECODE
sleep 1
done

我的系统是 Ubuntu8.04 的

安装方法: 编辑源文件:

1
sudo gedit /etc/apt/sources.list

加入下面两行:

1
2
deb http://ppa.launchpad.net/googlegadgets/ubuntu hardy main
deb-src http://ppa.launchpad.net/googlegadgets/ubuntu hardy main

保存退出。

接下来就是更新系统和安装 Google Gadgets:

1
2
sudo apt-get update
sudo apt-get install google-gadgets

提示如下信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
keke@Lin:~$ sudo aptitude install google-gadgets
[sudo] password for keke:
正在读取软件包列表… 完成
正在分析软件包的依赖关系树
读取状态信息… 完成
正在读取扩展状态文件
正在初始化软件包状态… 完成
正在编辑扩展状态信息… 完成
创建标签数据库… 完成
下列新软件包将被自动安装:
libmozjs0d libqtwebkit1d libxul-common libxul0d
下列“新”软件包将被安装。
google-gadgets libmozjs0d libqtwebkit1d libxul-common libxul0d
0 个软件包被升级,新安装5 个, 0 个将被删除, 同时 0 个将不升级。
需要获取 19.8MB 的存档。 解包后将要使用 61.9MB。
您要继续吗?[Y/n/?] y
警告:您将安装以下软件包的不可信版本!

不可信的软件可能会危害您的系统安全。
只有当您非常清楚地了解这就是您所要执行的操作时,才应该进行安装操作。

google-gadgets

您想忽略这条警告信息并继续执行吗?
要继续,请键入“Yes”;要中止,请键入“No”:

然后键入“Yes”,安装完成。

运行:ggl-gtk

下面是官方给的方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
Introduction

This page describe the method of building Google Gadgets for Linux from source code. Following instruction apply to Google Gadgets for Linux 0.10.3.
Preparation

Before building this project, you need do some preparation work, for example, downloading project source code, installing dependent packages and prepare build system.
Download source code

You can get the source code from the svn repository. Please follow the instruction on Source page to check it out.

For end users, the best way is to download a release source package from our download page.
Dependent packages

This project depends on various external libraries and applications, they must be available in your system before building this project. For different Linux distributions and operating systems, the packages name and installation method might be different. Following are information for the most popular distributions. If you know what packages are required for other distributions and operating systems, feel free to tell us and we will update this page to include them.
Ubuntu 8.04 and 8.10 series

If you are using Ubuntu 8.04 or 8.10 series, including all of their variants, such Kubuntu etc., you need install following mandatory packages:

- build-essential
- zip
- flex
- desktop-file-utils
- shared-mime-info
- zlib1g-dev
- libxml2-dev
- libdbus-1-dev
- libx11-dev
- libxt-dev
- libltdl3-dev (for Ubuntu 8.04) or libltdl7-dev (for Ubuntu 8.10)
- libgstreamer-plugins-base0.10-dev
- network-manager-dev
- libstartup-notification0-dev
- xulrunner-1.9-dev (Mandatory for GTK version, optional for Qt version)

If you want to use GUI and sidebar based on GTK library, you need following packages:

- libgtk2.0-dev
- librsvg2-dev
- libcurl4-gnutls-dev or libcurl4-openssl-dev

If you want to use GUI based on QT library, you need following packages:

- libqt4-dev

If you want to build source code checked out from svn trunk, you also need following packages:

- autoconf
- automake
- libtool

Please note that, QT based GUI is not fully functional on Ubuntu 8.04, because the version of QT library is too low.

You can use apt-get command to install these packages, for example:

$ sudo apt-get install build-essential zip flex desktop-file-utils shared-mime-info zlib1g-dev libgtk2.0-dev libxml2-dev libdbus-1-dev librsvg2-dev libltdl3-dev libcurl4-gnutls-dev libgstreamer-plugins-base0.10-dev xulrunner-1.9-dev network-manager-dev libqt4-dev libstartup-notification0-dev

You can just copy above command in to a terminal and execute it.
openSUSE 10.3 and 11.0

If you are using openSUSE 10.3 and later versions, you need install following mandatory packages:

- gcc-c++
- zip
- flex
- desktop-file-utils
- shared-mime-info
- libtool
- zlib-devel
- libxml2-devel
- dbus-1-devel
- xorg-x11-devel
- xorg-x11-libXt-devel
- startup-notification-devel
- NetworkManager-devel
- gstreamer-0_10-plugins-base-devel (for openSUSE 11.0 or above) or gstreamer010-plugins-base-devel (for openSUSE 10.3)
- mozilla-xulrunner190-devel (for openSUSE 11.0 or above) or mozilla-xulrunner181-devel (for openSUSE 10.3) (Mandatory for GTK version, optional for Qt version)

If you want to use GUI and sidebar based on GTK library, you need following packages:

- gtk2-devel
- librsvg-devel
- libcurl-devel

If you want to use GUI based on QT library, you need following packages:

- libqt4-devel
- libQtWebKit-devel (only available since openSUSE 11.0)

If you want to build source code checked out from svn trunk, you also need following packages:

- autoconf
- automake

Please note that, QT based GUI is not fully functional on openSUSE 10.3, because the version of QT library is too low.

You can use yast or zypper to install these packages.
Fedora 8 and 9

If you are using Fedora 8 and later versions, you need install following mandatory packages:

- gcc-c++
- zip
- flex
- desktop-file-utils
- shared-mime-info
- libtool-ltdl-devel
- zlib-devel
- libxml2-devel
- dbus-devel
- libX11-devel
- libXt-devel
- startup-notification-devel
- NetworkManager-devel
- gstreamer-plugins-base-devel
- gstreamer-devel
- xulrunner-devel (for Fedora 9 or above) or firefox-devel (for Fedora 8) (Mandatory for GTK version, optional for Qt version)

If you want to use GUI and sidebar based on GTK library, you need following packages:

- gtk2-devel
- librsvg2-devel
- libcurl-devel (for Fedora 9 or above) or curl-devel (for Fedora 8)

If you want to use GUI based on QT library, you need following packages:

- qt-devel (for Fedora 9 or above) or qt4-devel (for Fedora 8)

If you want to build source code checked out from svn trunk, you also need following packages:

- autoconf
- automake
- libtool

You can use yum command to install these packages.
Mandriva 2009

If you are using Mandriva 2009, you need install following mandatory packages:

- gcc-c++
- zip
- flex
- desktop-file-utils
- shared-mime-info
- libltdl3-devel
- zlib1-devel
- libxml2-devel
- libdbus-1-devel
- libnm_util-devel
- libstartup-notification-1-devel
- libgstreamer0.10-devel
- libgstreamer-plugins-base0.10-devel
- libxulrunner-devel (Mandatory for GTK version, optional for Qt version)

If you want to use GUI and sidebar based on GTK library, you need following packages:

- librsvg2-devel
- libcurl-devel
- libcairo-devel
- libgtk+2.0_0-devel

If you want to use GUI based on QT library, you need following packages:

- libqt4-devel

If you want to build source code checked out from svn trunk, you also need following packages:

- autoconf
- automake
- libtool

You can use urpmi to install these packages, for example:

#urpmi gcc-c++ zip flex desktop-file-utils shared-mime-info libltdl3-devel zlib1-devel libxml2-devel libdbus-1-devel libnm_util-devel libstartup-notification-1-devel libgstreamer0.10-devel libgstreamer-plugins-base0.10-devel libxulrunner-devel librsvg2-devel libcurl-devel libcairo-devel libgtk+2.0_0-devel libqt4-devel autoconf automake libtool

Prepare build system

There are two different build systems can be used to build this project, autoconf/automake and cmake. Though cmake build system has been included in official source package since 0.10.3, it’s still in experimental stage. So autoconf/automake is still the best choice for most users.

If you want to try out cmake build system, you need install cmake version 2.4 or above first. Most distributions ship cmake package nowadays.

If you want to build source code checked out from svn trunk, you need run autotools/bootstrap.sh script before starting build. For example:

$ svn checkout http://google-gadgets-for-linux.googlecode.com/svn/trunk/ ggl-trunk
$ cd ggl-trunk
$ sh autotools/bootstrap.sh

Build

autoconf/automake based build system is highly recommended for normal users. cmake build system usually uses less time to build this project, but may still contain some problems.

Both build systems support out-of-tree build, that is, the build task can be done in a separated directory instead of inside the source code directory. Then you can remove all temporary files generated by build system easily without touching the source files. This approach is highly recommended.
Build with autoconf/automake
Invoke configure script

You need run configure script to generate makefile before building. For example, you can use following commands to perform an out-of-tree build:

Prepare source code:

$ tar jxf google-gadgets-for-linux-0.10.3.tar.bz2
$ cd google-gadgets-for-linux-0.10.3

Or, if you want to use he bleeding-edge version:

$ svn checkout http://google-gadgets-for-linux.googlecode.com/svn/trunk/ ggl-trunk
$ cd ggl-trunk
$ sh autotools/bootstrap.sh

Run configure script out-of-tree:

$ mkdir build
$ cd build
$ ../configure –prefix=/usr

It might take one or two minutes to run configure script, if anything goes well, a configure summary will be displayed, such as:

Build options:
Version “0.10.3″
Install prefix /usr
Install included libltdl no
Build shared libs yes
Build static libs yes
Enable debug no
Host type linux
OEM brand

Libraries:
GTK SVG Support yes
Build libggadget-gtk yes
Build libggadget-qt yes
Build libggadget-dbus yes
Build libggadget-npapi yes

Extensions:
Build dbus-script-class yes
Build gtk-edit-element yes
Build gtkmoz-browser-element yes
Build qtwebkit-browser no
Build gst-audio-framework yes
Build gst-video-element yes
Build gtk-system-framework yes
Build gtk-flash-element yes
Build qt-system-framework yes
Build linux-system-framework yes
Build smjs-script-runtime yes
Build qt-script-runtime no
Build curl-xml-http-request yes
Build qt-xml-http-request yes
Build libxml2-xml-parser yes

Hosts:
Build gtk host yes
Build qt host yes

The result might be different on different system. If some dependency libraries are missing, corresponding build option might be set to “no”. For example, above result shows that my QT library may be too old to support qtwebkit-browser and qt-script-runtime extensions.

Among above results, The most important are “Build gtk host” and “Build qt host”, if non of these options are “yes”, then means some mandatory dependent packages might be missing. You need at least one host to be built.

The “–prefix” parameter of configure script controls the target directory where you want to install the project. Usually “/usr” is the best choice for normal users. However, default value is “/usr/local”, and on some systems, it might not work properly. So “–prefix=/usr” is highly recommended for all users.

Besides “–prefix” parameter, there are some other parameters you might want to use:

- –enable-debug

It enables debug build, which will generate slower and larger binary but suitable for debugging. This option is not recommended for normal users.

- –with-browser-plugins-dir

Since 0.10.3, Google Gadgets for Linux support new APIs introduced in Google Desktop for Windows 5.8. The most important one is the “Full support for Flash”, that is, a desktop gadget can play a .swf file from the internet directly. On Linux, it requires adobe flash browser plugin. This option specifies the directory where the flash plugin can be found. The directory might be different on different Linux distributions, for example:

- On Ubuntu/Debian: /usr/lib/xulrunner-addons/plugins
- On openSUSE: /usr/lib/browser-plugins (32bit system) or /usr/lib64/browser-plugins (64bit system)
- On Fedora: /usr/lib/mozilla/plugins (32bit system) or /usr/lib64/mozilla/plugins (64bit system)

- –libdir

Specifies the directory to install shared libraries. The default value is “${prefix}/lib”. On 32bit Linux systems, this option can usually be omitted. But on 64bit Linux systems, the value are different on different systems. On Ubuntu/Debian, it has no difference between 32bit and 64bit systems. On openSUSE and Fedora, it shall be specified explicitly to ${prefix}/lib64, where ${prefix} is the directory specified by –prefix parameter. For example, if you are using openSUSE 11.0 64bit, then you need use following configure command:

$ ../configure –prefix=/usr –libdir=/usr/lib64 –with-browser-plugins-dir=/usr/lib64/browser-plugins

- –help

To display a complete lists of parameters that you can use.

Build

After executing configure script, you can just invoke command make in the same directory to build the project. There are multiple CPUs or a CPU with multi cores in your machine, you can use command make -jN to make the build process faster, where N is the number of CPUs you have. For example, on a dual-core machine, you can use following command:

$ make -j2

Install

If the build finished without any problem, then you can use command make install to install the project. You need root privilege to run this command. For eample, on Ubuntu, you can:

$ sudo make install

On some systems like Fedora, sudo might not work, and you may need use command su to switch to root first.

Then can just run command ggl-gtk or ggl-qt in a terminal to launch Google Gadgets for Linux. You can also find and launch Google Gadgets in application menu’s Accessories or Internet submenu.

If you want to make binary package, you can use following command to install the target files into a specific directory (eg. /tmp/ggl-root):

$ make DESTDIR=/tmp/ggl-root install

Then you can pack all things in /tmp/ggl-root into binary package.
Build with cmake

cmake build is only available publicly since 0.10.3. You need cmake 2.4 or above to build it. Similar than autoconf/automake build system, you need three steps to build the project:
Configure

For example, on Ubuntu/Debian systems, to do an out-of-tree build, you need:

$ mkdir build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/usr -DGGL_DEFAULT_BROWSER_PLUGINS_DIR=/usr/lib/xulrunner-addons/plugins ../

A summary will be displayed if anything goes well:

Build options:
Version “0.10.3″
Build type Debug
OEM brand

Libraries:
GTK SVG Support 1
Build libggadget-gtk 1
Build libggadget-qt 1
Build libggadget-dbus 1

Extensions:
Build dbus-script-class 1
Build gtkmoz-browser-element 1
Build gst-audio-framework 1
Build gst-video-element 1
Build linux-system-framework 1
Build smjs-script-runtime 1
Build curl-xml-http-request 1
Build libxml2-xml-parser 1
Build gtk-edit-element 1
Build gtk-system-framework 1
Build qt-edit-element 1
Build qtwebkit-browser-element 0
Build qt-xml-http-request 1
Build qt-script-runtime 0
Build qt-system-framework 1

Hosts:
Build gtk host 1
Build qt host 1

– Configuring done
– Generating done

After executing cmake, you can use command ccmake to check and change configure parameters:

$ ccmake ../

Build

Same as autoconf/automake build system, you can use make command to build the project. Use make -j2 on a dual-core system can make the progress faster.
Install

Same as autoconf/automake build system, you can use make install command to install the project into your system. You also need root privilege to do it.

You can also use make DESTDIR=/tmp/ggl-root install to install all things into a specific directory (eg. /tmp/ggl-root).

有些时候装完 netbeans,当你写完一个程序的时候,发现 IDE 提示说“找不到 XXX.h”

解决办法如下: 工具 -》 选项 -》 C/C++ -》 C++编译器 -》 添加 -》/usr/include/c++/4.2.4(你的可能不是 4.2.4)

先去OpenOffice网站下载一个OOo_3.0.0_LinuxIntel_install_zh-cn_deb.tar.gz 1. 进入DEBS文件夹,执行 sudo dpkg -i *.deb

  1. sudo apt-get autoremove openoffice.org-common*

  2. 进入DEBS里面的desktop-integration文件夹安装执行

1
sudo dpkg -i openoffice.org3.0-debian-menus_3.0-9354_all.deb

当然可以添加源:

1
deb http://ppa.launchpad.net/openoffice-pkgs/ubuntu intrepid main

最近也不知道怎么搞的,耳机里面有杂音。。。好囧。

后来把声卡驱动搞了又搞也没用,后来发现貌似是声音设置有问题。。

解决办法如下:

  1. 双击左上的喇叭按钮,打开声音控制;

  2. 选择首选项,在弹出的窗口中把所有选项都选上;

  3. 关闭Front Mic、Font Mic Boost、线路输入、CD、Microphone(我的问题在于没有关闭Front Mic选项)。

又是个作业。。当时搞到两天多。。有个问题一直没解决。。得 YOYO 大牛指点。顿悟。。

定义一个 User 类,保存用户字段。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.Date;
public class User {
private String name=new String();
private int age=0;
private boolean sex=true;
private Date birthday=new Date();
private String nativePlace=new String();
private String postcode=new String();
private String address=new String();
User()
{
}
public void setName(String s)
{
name=s;
}
public void setAge(int x)
{
age=x;
}
public void setSex(boolean s)
{
sex=s;
}
public void setBirthday(Date d)
{
birthday=d;
}
public void setNativePlace(String s)
{
nativePlace=s;
}
public void setPostcode(String s)
{
postcode=s;
}
public void setAddress(String s)
{
address=s;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public boolean getSex()
{
return sex;
}
public Date getBirthday()
{
return birthday;
}
public String getNativePlace()
{
return nativePlace;
}
public String getPostcode()
{
return postcode;
}
public String getAddress()
{
return address;
}
}

AlertThread 类,用来实现开机进度条功能(由于没学过 Thread 所以写的很是不完善)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Gauge;
public class AlertThread extends Thread {
Alert al;
public AlertThread(Alert al) {
this.al=al;
}
public void run()
{
Gauge indicator=al.getIndicator();
for(int i=0;i<10;i++)
{
indicator.setValue(i);
try
{
Thread.sleep(500);
}
catch(Exception e)
{

}
}
}
}

这个当然是主程序了,O(∩_∩)O

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import java.util.Date;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class UserManage extends MIDlet implements CommandListener{
private User user[]=new User[100];
private int userLen=0,sel=0;
private Display display;
private Form userForm;
private List userList;
private TextField tfName,tfAge,tfNativePlace,tfPostcode,tfAddress;
private Command saveCommand,cancelCommand,editCommand,addCommand,deleteCommand,exitCommand,enterCommand;
private ChoiceGroup cgSex;
private DateField dfBirthday;
private boolean isEdit=false;

public UserManage() {
//创建窗体,列表
userForm=new Form("用户信息");
userList=new List("用户列表",List.IMPLICIT);
//创建组件
tfName=new TextField("姓名","",50,TextField.ANY);
tfAge=new TextField("年龄","",5,TextField.NUMERIC);
tfNativePlace=new TextField("籍贯","",20,TextField.ANY);;
tfPostcode=new TextField("邮编","",5,TextField.NUMERIC);
tfAddress=new TextField("地址","",100,TextField.ANY);
String[] sexArray=new String[]{"男","女"};
cgSex=new ChoiceGroup("性别",ChoiceGroup.POPUP,sexArray,null);
dfBirthday=new DateField("出生年月",DateField.DATE);
//创建Command
saveCommand=new Command("保存",Command.OK,1);
cancelCommand=new Command("取消",Command.CANCEL,1);
addCommand=new Command("添加",Command.ITEM,1);
editCommand=new Command("编辑",Command.ITEM,2);
deleteCommand=new Command("删除",Command.ITEM,3);
exitCommand=new Command("退出",Command.EXIT,1);
enterCommand=new Command("进入",Command.OK,1);
//添加组件
userForm.append(tfName);
userForm.append(tfAge);
userForm.append(cgSex);
userForm.append(dfBirthday);
userForm.append(tfNativePlace);
userForm.append(tfPostcode);
userForm.append(tfAddress);
//添加Command
userForm.addCommand(saveCommand);
userForm.addCommand(cancelCommand);
userForm.setCommandListener(this);
userList.addCommand(addCommand);
userList.addCommand(deleteCommand);
userList.addCommand(editCommand);
userList.addCommand(exitCommand);
userList.setCommandListener(this);
//字体设置

}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
display=Display.getDisplay(this);
Alert al=new Alert("");
al.setType(AlertType.INFO);
al.setTimeout(Alert.FOREVER);
Gauge g=new Gauge(null,false,5,0);
g.getPreferredHeight();
g.getPreferredWidth();
al.setIndicator(g);
al.setString("用户管理系统载入中....");
al.addCommand(enterCommand);
al.addCommand(exitCommand);
al.setCommandListener(this);
AlertThread t=new AlertThread(al);
t.start();
display.setCurrent(al);
}
public void commandAction(Command c,Displayable d)
{
if(userForm.isShown())
{
if(c==saveCommand)
{
user[userLen] = new User();
user[userLen].setName(tfName.getString());
user[userLen].setAge(Integer.parseInt(tfAge.getString()));
user[userLen].setSex(!cgSex.isSelected(0));
user[userLen].setBirthday(dfBirthday.getDate());
user[userLen].setNativePlace(tfNativePlace.getString());
user[userLen].setPostcode(tfPostcode.getString());
user[userLen].setAddress(tfAddress.getString());
userList.append(user[userLen].getName(),null);
userLen++;
if(isEdit)
{
delete(sel);
}
}
display.setCurrent(userList);
}
if(userList.isShown())
{
sel=userList.getSelectedIndex();
if(c==addCommand)
{
tfName.setString("");
tfAge.setString("");
tfNativePlace.setString("");
tfPostcode.setString("");
tfAddress.setString("");
cgSex.setSelectedIndex(0, true);
dfBirthday.setDate(new Date());
isEdit=false;
display.setCurrent(userForm);
}
if(c==editCommand)
{
tfName.setString(user[sel].getName());
tfAge.setString(String.valueOf(user[sel].getAge()));
tfNativePlace.setString(user[sel].getNativePlace());
tfPostcode.setString(user[sel].getPostcode());
tfAddress.setString(user[sel].getAddress());
if(user[sel].getSex())
{
cgSex.setSelectedIndex(0,true);
}
else
{
cgSex.setSelectedIndex(1,true);
}
dfBirthday.setDate(user[sel].getBirthday());
isEdit=true;
display.setCurrent(userForm);
}
if(c==deleteCommand)
{
delete(sel);
}


}
if(c==cancelCommand)
{
display.setCurrent(userList);
}
if(c==exitCommand)
{
//destroyApp(false);
notifyDestroyed();
}
if(c==enterCommand)
{
display.setCurrent(userForm);
}
}
public void delete(int n)
{

for(int i=n;i<userLen-1;i++)
{
user[i]=user[i+1];
}
userLen--;
userList.delete(n);
}
}

中兴实训的第一个作业,一个简单的手机备忘录。。

由于没学过 JAVA,所以写得十分的 ws,大牛勿鄙。。。。

作业题目:制作一个备忘录要求(用 TextBox 进行信息录入,长度限定为 50 个汉字,录入完毕后将信息保存到内存中,保存后跳转到 List 列表界面,设计可以对 List 中的信息进行删除,修改,添加操作,进行删除时要求有 Alert 提示框。

这个题目很是抽象的说。。到现在还不是很懂。。就随便写了一个。好囧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*Memo Design by Killua 2008.11.5*/
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
public class Memo extends MIDlet implements CommandListener{
private Display display;
private String[] stringArray;
private int tbLen,numEdit;
private TextBox tbAdd,tbView,tbEdit;
private List list;
private Command saveCommand=new Command("Save",Command.OK,1);
private Command addCommand=new Command("Add",Command.ITEM,2);
private Command editCommand=new Command("Edit",Command.ITEM,3);
private Command deleteCommand=new Command("Delete",Command.ITEM,4);
private Command viewCommand=new Command("View",Command.ITEM,1);
private Command exitCommand=new Command("Exit",Command.EXIT,5);
private Command okCommand=new Command("OK",Command.OK,1);
private Command cancelCommand=new Command("Cancel",Command.CANCEL,1);

public Memo() {
display=Display.getDisplay(this);
list=new List("",Choice.IMPLICIT);
stringArray=new String[100];
tbAdd=new TextBox("Add","",50,TextField.ANY);
tbEdit=new TextBox("Edit","",50,TextField.ANY);
tbView=new TextBox("View","",50,TextField.UNEDITABLE);
tbLen=numEdit=0;
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
tbAdd.addCommand(saveCommand);
tbAdd.addCommand(cancelCommand);

tbEdit.addCommand(saveCommand);
tbEdit.addCommand(cancelCommand);

tbView.addCommand(cancelCommand);

list.addCommand(addCommand);
list.addCommand(editCommand);
list.addCommand(deleteCommand);
list.addCommand(viewCommand);
list.addCommand(exitCommand);

tbAdd.setCommandListener(this);
tbEdit.setCommandListener(this);
tbView.setCommandListener(this);
list.setCommandListener(this);

display.setCurrent(tbAdd);
}
public void commandAction(Command cmd,Displayable d)
{
if(tbAdd.isShown())
{
if(cmd==saveCommand)
{
String stringAdd=tbAdd.getString();
if(!stringAdd.equals(""))
{
stringArray[tbLen++]=stringAdd;
list.append(stringAdd,null);
}
display.setCurrent(list);
}
}
if(tbEdit.isShown())
{
if(cmd==saveCommand)
{
String stringEdit=tbEdit.getString();
stringArray[numEdit]=stringEdit;
list.set(numEdit,stringEdit, null);
display.setCurrent(list);
}
}
if(cmd==cancelCommand)
display.setCurrent(list);
if(list.isShown())
{
if(cmd==addCommand)
{
tbAdd.setString("");
display.setCurrent(tbAdd);
}
if(cmd==editCommand)
{
numEdit=list.getSelectedIndex();
tbEdit.setString(stringArray[numEdit]);
display.setCurrent(tbEdit);
}
if(cmd==deleteCommand)
{
Alert al=new Alert("");
al.setType(AlertType.WARNING);
al.setString("you delete the record");
al.setTimeout(2000);
display.setCurrent(al);
int i=list.getSelectedIndex();
list.delete(i);
for(int j=i;j<tbLen-1;j++)
stringArray[j]=stringArray[j+1];
tbLen--;
display.setCurrent(list);
}
if(cmd==viewCommand)
{
int i=list.getSelectedIndex();
tbView.setString(stringArray[i]);
display.setCurrent(tbView);
}
}
if(cmd==exitCommand)
{
notifyDestroyed();
}
}
}

本来程序最开始的时候是用 TextBox 数组的,可是无伦怎么改也是数组非法访问,而 tbArray[tbLen++]=tbAdd;这个也不知道有什么问题,一直有错。。每次赋值都把所有的给覆盖掉了,orz。最后实在没招了,用 String[]了。最后还是很 ws 的完成了。。

1.1 版本

增加了 Delete 时候的判断。。。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*Memo Design by Killua 2008.11.5*/
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
public class Memo extends MIDlet implements CommandListener{
private Display display;
private String[] stringArray;
private int tbLen,numEdit,numDelete;
private TextBox tbAdd,tbView,tbEdit;
private List list;
private Alert al;
private Command saveCommand=new Command("Save",Command.OK,1);
private Command addCommand=new Command("Add",Command.ITEM,2);
private Command editCommand=new Command("Edit",Command.ITEM,3);
private Command deleteCommand=new Command("Delete",Command.ITEM,4);
private Command viewCommand=new Command("View",Command.ITEM,1);
private Command exitCommand=new Command("Exit",Command.EXIT,5);
private Command okCommand=new Command("OK",Command.OK,1);
private Command cancelCommand=new Command("Cancel",Command.CANCEL,1);

public Memo() {
display=Display.getDisplay(this);
list=new List("Killua's Memo",Choice.IMPLICIT);
stringArray=new String[100];
tbAdd=new TextBox("Add","",50,TextField.ANY);
tbEdit=new TextBox("Edit","",50,TextField.ANY);
tbView=new TextBox("View","",50,TextField.UNEDITABLE);
al=new Alert("Waring");
al.setType(AlertType.WARNING);
al.setString("you delete the record,are you sure?");
al.setTimeout(Alert.FOREVER);
tbLen=numEdit=0;
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
tbAdd.addCommand(saveCommand);
tbAdd.addCommand(cancelCommand);

tbEdit.addCommand(saveCommand);
tbEdit.addCommand(cancelCommand);

tbView.addCommand(cancelCommand);

list.addCommand(addCommand);
list.addCommand(editCommand);
list.addCommand(deleteCommand);
list.addCommand(viewCommand);
list.addCommand(exitCommand);

al.addCommand(okCommand);
al.addCommand(cancelCommand);

al.setCommandListener(this);
tbAdd.setCommandListener(this);
tbEdit.setCommandListener(this);
tbView.setCommandListener(this);
list.setCommandListener(this);

display.setCurrent(tbAdd);
}
public void commandAction(Command cmd,Displayable d)
{
if(tbAdd.isShown())
{
if(cmd==saveCommand)
{
String stringAdd=tbAdd.getString();
if(!stringAdd.equals(""))
{
stringArray[tbLen++]=stringAdd;
list.append(stringAdd,null);
}
display.setCurrent(list);
}
}
if(tbEdit.isShown())
{
if(cmd==saveCommand)
{
String stringEdit=tbEdit.getString();
stringArray[numEdit]=stringEdit;
list.set(numEdit,stringEdit, null);
display.setCurrent(list);
}
}
if(al.isShown())
{
if(cmd==okCommand)
{
list.delete(numDelete);
for(int j=numDelete;j<tbLen-1;j++)
stringArray[j]=stringArray[j+1];
tbLen--;
display.setCurrent(list);
}
}
if(cmd==cancelCommand)
display.setCurrent(list);
if(list.isShown())
{
if(cmd==addCommand)
{
tbAdd.setString("");
display.setCurrent(tbAdd);
}
if(cmd==editCommand)
{
numEdit=list.getSelectedIndex();
tbEdit.setString(stringArray[numEdit]);
display.setCurrent(tbEdit);
}
if(cmd==deleteCommand)
{
display.setCurrent(al);
numDelete=list.getSelectedIndex();
}
if(cmd==viewCommand)
{
int i=list.getSelectedIndex();
tbView.setString(stringArray[i]);
display.setCurrent(tbView);
}
}
if(cmd==exitCommand)
{
notifyDestroyed();
}
}
}

装完Eclipse +WTK2.5.2后运行j2me程序发现编译错误,如下

1
2
3
4
5
6
7
8
9
10
11
12
13
Exception in thread “AWT-EventQueue-0″ java.lang.NullPointerException
at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.initSystemColorDefaults(GTKLookAndFeel.java:1267)
at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.loadStyles(GTKLookAndFeel.java:1509)
at com.sun.java.swing.plaf.gtk.GTKLookAndFeel.access$000(GTKLookAndFeel.java:37)
at com.sun.java.swing.plaf.gtk.GTKLookAndFeel$WeakPCL$1.run(GTKLookAndFeel.java:1449)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

如果通过命令行直接启动WTK会遇到如下情况:

1
2
3
4
5
6
7
(<unknown>:14996): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkComboBoxEntry (need an instance of GtkEntry or of a subclass)

(<unknown>:14996): Gtk-CRITICAL **: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)’ failed

(<unknown>:14996): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)’ failed

(<unknown>:14996): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)’ failed

解决办法: 首先找到你的WTK的安装目录,在bin中找到ktoolbar和emulator这两个文件,这两个是启动WTK和Emulator的两个启动文件,使用vi或者gedit来对这两个文件进行编辑,在两个文件中的相关位置添加如下一行即可: -Dswing.systemlaf=”javax.swing.plaf.metal.MetalLookAndFeel” / 添加后的ktoolbar如下(注意红色标注的那行即可):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh

javapathtowtk=/usr/java/jdk1.6.0_05/bin/

PRG=$0

# Resolve soft links
while [ -h "$PRG" ]; do
ls=`/bin/ls -ld “$PRG”`
link=`/usr/bin/expr “$ls” : ‘.*-> (.*)$’`
if /usr/bin/expr “$link” : ‘^/’ > /dev/null 2>&1; then
PRG=”$link
else
PRG=”`/usr/bin/dirname $PRG`/$link
fi
done

KVEM_BIN=`dirname $PRG`
KVEM_HOME=`cd $…{KVEM_BIN}/.. ; pwd`
KVEM_LIB=”${KVEM_HOME}/wtklib”
KVEM_API=”${KVEM_HOME}/lib”
export MMAPI_GM_SOUNDBANK=”${KVEM_API}/soundbank.dls”

${javapathtowtk}java” -Dkvem.home=”${KVEM_HOME}” /
-Djava.library.path=”${KVEM_HOME}/bin” /
-Dswing.systemlaf=”javax.swing.plaf.metal.MetalLookAndFeel” /
-cp${KVEM_LIB}/kenv.zip:${KVEM_LIB}/ktools.zip:${KVEM_BIN}/JadTool.jar:${KVEM_BIN}/MEKeyTool.jar:${KVEM_LIB}/customjmf.jar:${KVEM_API}/j2me-ws.jar:${KVEM_BIN}/schema2beansdev.jar:${KVEM_BIN}/j2me_sg_ri.jar:${KVEM_BIN}/jaxrpc-impl.jar:${KVEM_BIN}/jaxrpc-api.jar:${KVEM_BIN}/jaxrpc-spi.jar:${KVEM_BIN}/activation.jar:${KVEM_BIN}/mail.jar:${KVEM_BIN}/saaj-api.jar:${KVEM_BIN}/saaj-impl.jar:${KVEM_BIN}/xsdlib.jar:${KVEM_LIB}/nist-sip-1.2.jar:${KVEM_LIB}/JainSipApi1.1.jar:${KVEM_LIB}/jain-sip-presence-proxy.jar”
com.sun.kvem.toolbar.Main “$@

修改后的emulator文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh

javapathtowtk=/usr/java/jdk1.6.0_05/bin/

PRG=$0

# Resolve soft links
while [ -h "$PRG" ]; do
ls=`/bin/ls -ld “$PRG”`
link=`/usr/bin/expr “$ls” : ‘.*-> (.*)$’`
if /usr/bin/expr “$link” : ‘^/’ > /dev/null 2>&1; then
PRG=”$link
else
PRG=”`/usr/bin/dirname $PRG`/$link
fi
done

KVEM_BIN=`dirname$PRG”`
KVEM_HOME=`cd${KVEM_BIN}/..” ; pwd`
KVEM_LIB=”${KVEM_HOME}/wtklib”
export MMAPI_GM_SOUNDBANK=”${KVEM_HOME}/lib/soundbank.dls”

${javapathtowtk}java” -Dkvem.home=”${KVEM_HOME}” /
-Djava.library.path=”${KVEM_HOME}/bin” /
-Dswing.systemlaf=”javax.swing.plaf.metal.MetalLookAndFeel” /
-cp${KVEM_LIB}/kenv.zip:${KVEM_LIB}/ktools.zip:${KVEM_LIB}/customjmf.jar”
com.sun.kvem.environment.EmulatorWrapper “$@” 0