﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-有个空间</title><link>http://www.blogjava.net/roley/</link><description /><language>zh-cn</language><lastBuildDate>Fri, 17 Apr 2026 22:38:12 GMT</lastBuildDate><pubDate>Fri, 17 Apr 2026 22:38:12 GMT</pubDate><ttl>60</ttl><item><title>debian 的折磨</title><link>http://www.blogjava.net/roley/archive/2005/09/14/12984.html</link><dc:creator>有个空间</dc:creator><author>有个空间</author><pubDate>Wed, 14 Sep 2005 02:25:00 GMT</pubDate><guid>http://www.blogjava.net/roley/archive/2005/09/14/12984.html</guid><wfw:comment>http://www.blogjava.net/roley/comments/12984.html</wfw:comment><comments>http://www.blogjava.net/roley/archive/2005/09/14/12984.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/roley/comments/commentRss/12984.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/roley/services/trackbacks/12984.html</trackback:ping><description><![CDATA[<P>最近弄了台T43 2688CT1,天生就讨厌MS，打算装个linux,原先一直用slackware，装好10.1才发现kernel是2.4的好多设备都不能正常运行，找找资料，发现升级kernel最方便还是debian，于是就打算装一个干净的系统，原来的slackware和其他的发行版，都会给自己装一些一辈子都用不到几次的东西。参照一些说明如下<!--StartFragment --> </P>
<H2 class=main-title>Installation</H2><!-- begin content -->
<DIV class=node>
<DIV class=content>
<P>The notebook came pre-installed with Windows XP Professional. After finishing the Windows installation, I decided to create the recovery media first, because IBM doesn't put them in the box anymore. Better safe than sorry. Using the software in the "Access IBM" folder and two blank DVD-RWs that was quickly done.</P>
<P>Then I booted <A href="http://www.grml.org/" target=_blank>grml</A>, my favorite Linux Live-CD, and used ntfsresize and cfdisk to resize the NTFS partition (/dev/sda1) to 15GB, but left alone the recovery partition (partition type in cfdisk is "Compaq diagnostics").</P>
<P>After that I booted the Debian Sarge DVD and tried the installation using version 2.6 of the linux kernel by typing "linux26" at the boot prompt. Unfortunately that didn't work, because the harddisk is connected to a SATA controller and the installation kernel didn't recognize it. So I restarted the installation, using the standard kernel instead. This time around the harddisk was recognized, although via the old IDE-sata interface of the kernel, so the disk was called /dev/hda. But at least I could start the installation.</P>
<P>I used the Debian installer to partition the harddisk, creating a swap partition (/dev/hda5) and the root partition (/dev/hda6), 1GB each. For the rest (~36GB) I used LVM and created logical volumes for /home (10GB), /tmp (1GB), /usr (2GB) and /var (1GB).</P>
<P>Then I did a minimal installation, and rebooted into the fresh system using the installed kernel (version 2.4). Everything was working so far, but I decided to compile a new kernel from the 2.6 series to use the harddisk via the new SATA interface.<BR><!--StartFragment -->&nbsp;</P>
<H2 class=main-title>Kernel Configuration</H2><!-- begin content -->
<DIV class=node>
<DIV class=content>First I installed the necessary packages to build the kernel from source with 
<DIV class=pre><PRE>apt-get install gcc make ncurses-dev</PRE></DIV>
<P>Then I downloaded the source code of kernel 2.6.12.3 from the <A href="http://www.kernel.org/" target=_blank>Linux Kernel Archives</A>. (at first I was using 2.6.12.2, but at the time of writing I already did the small maintainance upgrade to 2.6.12.3)</P>
<P>After extracting the compressed tar archive and studying the <A href="http://www.thinkwiki.org/" target=_blank>ThinkWiki</A> a bit, I also applied <A href="http://stephen.evanchik.com/" target=_blank>the trackpoint patch</A>, a patch relevant to get powermanagement for the SATA harddisk so it plays nice with suspend-to-ram and another to make sure the infrared device is detected (both available at <A href="http://shamrock.dyndns.org/%7Eln/linux/" target=_blank>http://shamrock.dyndns.org/~ln/linux/</A>). (note: the last 2 patches are attached to this page for completeness sake only, in case the current download URL vanishes)</P>
<P>I also decided to use <A href="http://www.suspend2.net/" target=_blank>Software Suspend 2</A> (version 2.1.9.5 for kernel 2.6.12) because I used it on various other notebooks in the past with good results.</P>I used the menu configuration of the kernel via 
<DIV class=pre><PRE>make menuconfig</PRE></DIV>in the kernel source tree. Important settings to change are: 
<UL>
<LI>in "Processor type and features" select "Pentium M" for the processor familiy to optimize for the Pentium-M</LI>
<LI>in "Power management options (ACPI, APM)" enable ACPI (I don't use APM) and Software Suspend 2. Note: to use a newer version of the "IBM ThinkPad Laptop Extras" you have to compile it as module so it can be easily replaced later on.</LI>
<LI>enable CPU frequency scaling, select scaling governors ("ondemand" and "conservative" are the ones I use, but be sure to also select "userspace" if you want some external program like cpufreqd to do the frequency scaling) and enabe the processor driver for Centrino ("Intel Enhanced SpeedStep")</LI>
<LI>for the harddisk SCSI has to be enabled and in the low-level SCSI drivers section Serial ATA and "Intel PIIX/ICH SATA support" need to be selected</LI>
<LI>to get the kernel to recognize the CD-RW/DVD-RW I also needed to enable ACPI Plug'n'Play support (and of course the ATAPI/IDE CD-ROM driver)</LI></UL>My currently used kernel configuration is attached at the bottom of this page. Afterwards I compilied the kernel by issuing 
<DIV class=pre><PRE>make</PRE></DIV>and after switching to the root account I installed the kernel modules, the System.map file and the kernel image with 
<DIV class=pre><PRE>make modules_install
cp System.map /boot/System.map-2.6.12.3
cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.12.3</PRE></DIV>Then I added a new entry in the GRUB menu file in /boot/grub/menu.lst: 
<DIV class=pre><PRE>title           Debian GNU/Linux, kernel 2.6.12.3
root            (hd0,5)
kernel          /boot/vmlinuz-2.6.12.3 root=/dev/sda6 ro video=vesafb,nomtrr,ywrap vga=836 acpi_sleep=s3_bios resume2=swap:/dev/sda5 processor.max_cstate=2 elevator=cfq
</PRE></DIV>
<P>Note: not all of the kernel parameters are necessary, video and vga give a higher resolution in the text consoles (if the vesa framebuffer driver is compiled into the kernel), resume2 is for Software Resume 2, elevator=cfq selects a different scheduling mechanism more suitable for desktop use, acpi_sleep is needed to circumvent a problem with suspend-to-ram.</P>
<P>Since switching to SCSI-SATA also meant that the harddisk would be called /dev/sda after the reboot, I also changed all occurences of "/dev/hda" to "/dev/sda" in /etc/fstab.</P>One 
<DIV class=pre><PRE>init 6</PRE></DIV>
<P>later and I was running the shiny new kernel.<BR><BR>失败了3次了，编译和patch都没有问题，难道是分区格式？我用的ext2可能太老了，总之就是一种折磨阿<BR>看来还要多学习。</P></DIV></DIV></DIV></DIV><img src ="http://www.blogjava.net/roley/aggbug/12984.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/roley/" target="_blank">有个空间</a> 2005-09-14 10:25 <a href="http://www.blogjava.net/roley/archive/2005/09/14/12984.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JXTA shell</title><link>http://www.blogjava.net/roley/archive/2005/06/02/5474.html</link><dc:creator>有个空间</dc:creator><author>有个空间</author><pubDate>Thu, 02 Jun 2005 08:33:00 GMT</pubDate><guid>http://www.blogjava.net/roley/archive/2005/06/02/5474.html</guid><wfw:comment>http://www.blogjava.net/roley/comments/5474.html</wfw:comment><comments>http://www.blogjava.net/roley/archive/2005/06/02/5474.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/roley/comments/commentRss/5474.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/roley/services/trackbacks/5474.html</trackback:ping><description><![CDATA[jxta shell 基本语法<br>
man----帮助<br>
env----SHELL 变量及其对应值<br>
cat----输出变量值<br>
peers----列出所有对等体<br>
mkadv-----创建通告<br>
mkpgrp-----创建组<br>
groups-----列出所有组<br>
join-------加入组<br>
chpgrp-----改变组<br>
leave------离开组<br>
<img src ="http://www.blogjava.net/roley/aggbug/5474.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/roley/" target="_blank">有个空间</a> 2005-06-02 16:33 <a href="http://www.blogjava.net/roley/archive/2005/06/02/5474.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Use JSTL to develop jsp page</title><link>http://www.blogjava.net/roley/archive/2005/06/01/5415.html</link><dc:creator>有个空间</dc:creator><author>有个空间</author><pubDate>Wed, 01 Jun 2005 07:17:00 GMT</pubDate><guid>http://www.blogjava.net/roley/archive/2005/06/01/5415.html</guid><wfw:comment>http://www.blogjava.net/roley/comments/5415.html</wfw:comment><comments>http://www.blogjava.net/roley/archive/2005/06/01/5415.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/roley/comments/commentRss/5415.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/roley/services/trackbacks/5415.html</trackback:ping><description><![CDATA[these days i am learning jstl the Java Server Pages Standard Tag Library.<br>
<br>
<img src ="http://www.blogjava.net/roley/aggbug/5415.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/roley/" target="_blank">有个空间</a> 2005-06-01 15:17 <a href="http://www.blogjava.net/roley/archive/2005/06/01/5415.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Developing GNOME Applications with Java By Mike Petullo </title><link>http://www.blogjava.net/roley/archive/2005/06/01/5409.html</link><dc:creator>有个空间</dc:creator><author>有个空间</author><pubDate>Wed, 01 Jun 2005 06:20:00 GMT</pubDate><guid>http://www.blogjava.net/roley/archive/2005/06/01/5409.html</guid><wfw:comment>http://www.blogjava.net/roley/comments/5409.html</wfw:comment><comments>http://www.blogjava.net/roley/archive/2005/06/01/5409.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/roley/comments/commentRss/5409.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/roley/services/trackbacks/5409.html</trackback:ping><description><![CDATA[<div class="content"><p>Design your application's GUI look in XML, write the code in Java and plug the whole thing in to the GNOME desktop.</p>

<div class="article" lang="en">

<div class="simplesect" lang="en">
<div class="titlepage">
<h2 class="title"><a name="N0x850ca10.0x8573984"></a></h2>
</div>
<p>The original announcement of the GNOME Desktop Project in 1997 stated the following intention, "to use
GTK/Scheme bindings for coding small utilities and applications". Since then, the GNOME development platform
has provided tools to develop using several alternatives to C. C++, Java, Perl and Python all are supported
by the official GNOME distribution. In addition, the Mono Project provides tools necessary for developing
GNOME applications using the C# programming language. All of these options are becoming quite popular. The
GNOME interfaces for many of the system configuration tools for the Fedora Project, for example, are written
in Python, and many new applications are being written in C#. This article describes how to create GNOME
applications using the free Java compiler from the GNU Compiler Collection. Although this article focuses on
Java, the techniques described revolve around the GLADE User Interface Builder and may be used with any of
the bindings supported by the GNOME Project.</p>
<p>The GNU Compiler for the Java Programming Language (gcc-java) is a Java development environment
distributed under the GNU General Public License. Because gcc-java is free software, it is developed
independently of Sun Microsystems' Java efforts. As a result of this, gcc-java does not yet implement 100% of
the Java standard. For example, support for the Abstract Window Toolkit (AWT) is not yet complete. Despite
its current shortcomings, gcc-java shows great promise as the foundation of a completely free Java stack, and
it already can be used to build many real-world applications; see the on-line Resources for examples.</p>
<p>Unlike many Java compilers, gcc-java can produce both Java bytecode and a native, platform-specific
executable. In the latter case, the executable is linked against gcc-java's libgcj. libgcj is a library
containing the core Java class libraries and a garbage collector. In addition, libgcj contains a bytecode
interpreter so natively compiled Java applications can interact with Java bytecode libraries.</p>
</div>
<div class="simplesect" lang="en">
<div class="titlepage">
<h2 class="title"><a name="N0x850ca10.0x8573a8c"></a></h2>
</div>
<div class="sidebar">
<p class="title c1">Listing 1. HelloWorld.java</p>
<pre class="programlisting"><tt>public class HelloWorld {<br>        public static void main(String[] args) {<br>                System.out.println("Hello, World!");<br>        }<br>}<br></tt>
</pre>
</div>
<p>The simple Java source code in Listing 1 can be compiled into Java bytecode with <tt>gcj -C
HelloWorld.java</tt> and interpreted using <tt>gij HelloWorld</tt>. The same source code can be compiled into
a native executable using <tt>gcj --main=HelloWorld -o HelloWorld HelloWorld.java</tt> and executed using
<tt>./HelloWorld</tt>. This article avoids including import and other trivial statements in Java code
listings; see Resources for the full source files.</p>
</div>
<div class="simplesect" lang="en">
<div class="titlepage">
<h2 class="title"><a name="N0x850ca10.0x8573c44"></a></h2>
</div>
<div class="sidebar">
<p class="title c1">Listing 2. ExampleAWT.java Fragment</p>
<pre class="programlisting"><tt>public class ExampleAWT extends Frame {<br> ExampleAWT() {<br>  super("AWT");<br>  Label msgLabel = new Label("Quit?");<br>  Button yesButton = new Button("Yes");<br>  Button noButton = new Button("No");<br>  Panel buttonbox = new Panel();<br>  buttonbox.setLayout(new FlowLayout());<br>  buttonbox.add(yesButton);<br>  buttonbox.add(noButton);<br>  Panel msgbox = new Panel();<br>  msgbox.setLayout(new FlowLayout());<br>  msgbox.add(msgLabel);<br>  add(msgbox, BorderLayout.NORTH);<br>  add(buttonbox, BorderLayout.SOUTH);<br>    <br>  yesButton.addActionListener(new ActionListener() {<br>   public void actionPerformed(ActionEvent e) {<br>    System.exit(0);<br>  }<br>  });<br>  noButton.addActionListener(new ActionListener() {<br>   public void actionPerformed(ActionEvent e) {<br>    System.exit(1);<br>   }<br>  });<br>  addWindowListener(new WindowAdapter() {<br>   public void windowClosing(WindowEvent e) {<br>     System.exit(0);<br>   }<br>  });<br> }<br> public static void main(String[] args) {<br>  ExampleAWT frame = new ExampleAWT();<br>  frame.pack();<br>  frame.setVisible(true);<br> }<br>}<br></tt>
</pre>
</div>
<p>Sun provides two class hierarchies for developing Java applications with graphical user interfaces. The
first, the Abstract Window Toolkit, has been distributed with Java since version 1.0. A picture of a
gcc-java-compiled AWT application is shown in Figure 1. The corresponding source code is provided in Listing
2 and can be compiled with:</p>
<pre class="programlisting"><tt>gcj --main=ExampleAWT -o ExampleAWT ExampleAWT.java<br></tt>
</pre>
<br>
<br>
<div class="mediaobject"><img src="http://www.linuxjournal.com/articles/lj/0135/8111/8111f1.png">
<div class="caption">
<p>Figure 1. An AWT Application</p>
</div>
</div>
</div>
<div class="simplesect" lang="en">
<div class="titlepage">
<h2 class="title"><a name="N0x850ca10.0x8573e54"></a></h2>
</div>
<div class="sidebar">
<p class="title c1">Listing 3. ExampleSwing.java Fragment</p>
<pre class="programlisting"><tt>public class ExampleSwing {<br> public static void main(String[] args) {<br>  JFrame win = new JFrame("Swing");<br>  JLabel msgLabel = new JLabel("Quit?");<br>  JButton yesButton = new JButton("Yes");<br>  JButton noButton = new JButton("No");<br>    <br>  win.getContentPane().setLayout (new BorderLayout());<br>  JPanel buttonbox = new JPanel();<br>  buttonbox.setLayout(new FlowLayout());<br>  buttonbox.add(yesButton);<br>  buttonbox.add(noButton);<br>    <br>  win.getContentPane().add(msgLabel, "Center");        <br>  win.getContentPane().add(buttonbox, "South");  <br>    <br>  yesButton.addActionListener(new ActionListener() {<br>   public void actionPerformed(ActionEvent e) {<br>    System.exit(0);<br>   }<br>  });<br>  noButton.addActionListener(new ActionListener() {<br>   public void actionPerformed(ActionEvent e) {<br>    System.exit(1);<br>   }<br>  });<br>  win.pack();<br>  win.show();<br> }<br>}<br></tt>
</pre>
</div>
<p>The second system, Swing, made its debut in Java 1.2. Figure 2 is a picture of the gcc-java-compiled Swing
application shown in Listing 3. Listing 3 can be compiled with <tt>gcj --main=ExampleSwing -o ExampleSwing
ExampleSwing.java</tt>. AWT uses the native GUI components in the host operating system to draw itself. Swing
gives the user finer control over the look and feel of components, and most of the work is performed by
Java.</p>
<div class="mediaobject"><img src="http://www.linuxjournal.com/articles/lj/0135/8111/8111f2.png">
<div class="caption">
<p>Figure 2. A Swing application-both AWT and Swing were written so that one application would behave in a
similar manner on any platform.</p>
</div>
</div>
</div>
<div class="simplesect" lang="en">
<div class="titlepage">
<h2 class="title"><a name="N0x850ca10.0x8574064"></a></h2>
</div>
<div class="sidebar">
<p class="title c1">Listing 4. ExampleSWT.java Fragment</p>
<pre class="programlisting"><tt>public class ExampleSWT {<br> public static void main(String[] args) {<br>  Display display = new Display();<br>  Shell shell = new Shell(display);<br>  shell.setLayout(new FillLayout(SWT.VERTICAL));<br>  Composite msgbox = new Composite(shell, <br>                                   SWT.NO_TRIM);<br>  RowLayout msglayout = new RowLayout();<br>  msglayout.justify = true;<br>  msgbox.setLayout(msglayout);<br>  Label label = new Label(msgbox, SWT.NO_TRIM);<br>  label.setText("Quit?");<br>  Composite buttonbox = new Composite(shell, <br>                                      SWT.NO_TRIM);<br>  RowLayout buttonlayout = new RowLayout();<br>  buttonlayout.justify = true;<br>  buttonlayout.pack = true;<br>  buttonbox.setLayout(buttonlayout);<br>  Button yesButton = new Button(buttonbox,<br>                                SWT.PUSH); <br>  yesButton.setText("Yes");<br>  Button noButton = new Button(buttonbox,<br>                               SWT.PUSH); <br>  noButton.setText("No");<br>  yesButton.addSelectionListener(<br>                            new SelectionAdapter() {<br>   public void widgetSelected(<br>                             SelectionEvent event) {<br>    System.exit(0);<br>   }<br>  });<br>  noButton.addSelectionListener(<br>                            new SelectionAdapter() {<br>   public void widgetSelected(<br>                             SelectionEvent event) {<br>    System.exit(1);<br>   }<br>  });<br>    <br>  shell.pack();<br>  shell.open();<br>  while (! shell.isDisposed()) {<br>   if (! display.readAndDispatch()) display.sleep();<br>  }<br> }<br>}<br></tt>
</pre>
</div>
<p>IBM sponsors the Eclipse Project, an effort to produce an open-source development environment. One of the
fruits of this project is the Standard Widget Toolkit, an alternative to AWT and Swing. SWT is a peer-based,
operating system-independent interface that uses the host operating system's interface for rendering common
components. Components not supported by an operating system are implemented in Java. On Linux, the
libswt-gtk2 package provides a GTK peer for SWT. Peers also exist for other platforms, including Solaris and
Windows. SWT code can run on any platform that has an SWT peer. An example SWT application is shown in
Listing 4, which can be compiled against the GTK SWT peer with a variation of the following:</p>
<pre class="programlisting"><tt>gcj --CLASSPATH=/usr/lib/libswt-gtk2.jar -lswt-gtk2<br>-o ExampleSWT --main=ExampleSWT ExampleSWT.java<br></tt>
</pre>
<br>
<br>
<p>See Resources for more information about the Standard Widget Toolkit.</p>
<p>With three existing Java GUI toolkits, one might ask why another alternative is necessary. GNOME's Java
bindings are unique because they are tied directly to GNOME. An application written with GNOME's Java
offerings looks and behaves exactly as if it had been written using GNOME's C libraries. It integrates
seamlessly into the GNOME desktop and provides the same capabilities as any other GNOME application. The
reason for this is GNOME's Java bindings use the Java Native Interface to delegate work directly to GNOME's C
libraries.</p>
<p>Currently, GNOME's Java bindings consist of four libraries-libgconf-java, libglade-java, libgnome-java and
libgtk-java. libgtk-java and libgnome-java provide the GUI components of the bindings. libglade-java allows
Java applications to read graphical user interface descriptions created by GLADE. Investigating
libgconf-java, the Java interface to the GConf configuration system, is left as an exercise for the
reader.</p>
<p>libgtk-java and libgnome-java are similar to SWT and AWT because host code implements their graphical
components. However, the GNOME libraries are quite different from AWT, Swing and SWT-GNOME libraries make no
claim of platform-independence. GNOME applications written in Java run only in a GNOME environment. Any
platform independence is a result of the entire GNOME environment itself being platform-independent.</p>
</div>
<div class="simplesect" lang="en">
<div class="titlepage">
<h2 class="title"><a name="N0x850ca10.0x8574248"></a></h2>
</div>
<div class="sidebar">
<p class="title c1">Listing 5. ExampleGNOME.java Fragment</p>
<pre class="programlisting"><tt>public class ExampleGNOME {<br> private LibGlade libglade;<br> private static final String GLADE_FILE = <br>                               "ExampleGNOME.glade";<br> public ExampleGNOME () throws IOException {<br>  libglade = new LibGlade(GLADE_FILE, this);<br> }<br> public void on_noButton_released(GtkEvent event) {<br>  Gtk.mainQuit();<br>  System.exit(1);<br> }<br> public void on_yesButton_released(GtkEvent event) {<br>  Gtk.mainQuit();<br>  System.exit(0);<br> }<br> public static void main(String args[]) {<br>  ExampleGNOME gui;<br>  Gtk.init(args);<br>  try {<br>   gui = new ExampleGNOME();<br>  } catch (IOException e) {<br>   System.err.println(e);<br>   System.exit(1);<br>  }<br> Gtk.main();<br> }<br>}<br></tt>
</pre>
</div>
<p>A gcc-java-compiled GNOME application is captured in Figure 3. Listing 5 shows the GNOME application's
source code and can be compiled with:</p>
<pre class="programlisting"><tt><br>gcj --CLASSPATH=/usr/share/java/gtk2.4.jar:\<br>/usr/share/java/gnome2.8.jar:\<br>/usr/share/java/glade2.8.jar \<br>-lgtkjar2.4 -lgnomejar2.8 -lgladejar2.8 \<br>-o ExampleGNOME --main=ExampleGNOME \<br>ExampleGNOME.java<br></tt>
</pre>
<br>
<br>
<div class="mediaobject"><img src="http://www.linuxjournal.com/articles/lj/0135/8111/8111f3.png">
<div class="caption">
<p>Figure 3. A Java GNOME Application</p>
</div>
</div>
<p>At first glance, Listing 5 may look a little sparse compared to the others. ExampleGNOME's user interface
is defined in ExampleGNOME.glade; as a result, there is not much GUI code in the application itself. Instead,
libglade-java reads ExampleGNOME.glade and creates the application's GUI components automatically. The GUI
code is tied back to our code by event callback methods. Two of these callbacks, whose names and
corresponding signals are defined in ExampleGNOME.glade, are on_noButton_released and on_yesButton_released.
Listing 6 contains the contents of a portion of ExampleGNOME.glade.</p>
</div>
<div class="simplesect" lang="en">
<div class="titlepage">
<h2 class="title"><a name="N0x850ca10.0x8574484"></a></h2>
</div>
<div class="sidebar">
<p class="title c1">Listing 6. ExampleGNOME.glade Fragment</p>
<pre class="programlisting"><tt><br>&lt;?xml version="1.0" standalone="no"?&gt;<br>&lt;!DOCTYPE glade-interface SYSTEM <br> "http://glade.gnome.org/glade-2.0.dtd"&gt;<br>&lt;glade-interface&gt;<br>&lt;requires lib="gnome"/&gt;<br>&lt;widget class="GtkWindow" id="ExampleGNOME"&gt;<br> &lt;property name="visible"&gt;True&lt;/property&gt;<br> &lt;property name="title" translatable="yes"&gt;<br>  GNOME&lt;/property&gt;<br> &lt;property name="type"&gt;<br>  GTK_WINDOW_TOPLEVEL&lt;/property&gt;<br> &lt;property name="window_position"&gt;<br>  GTK_WIN_POS_NONE&lt;/property&gt;<br> &lt;property name="modal"&gt;False&lt;/property&gt;<br> &lt;property name="resizable"&gt;True&lt;/property&gt;<br> &lt;property name="destroy_with_parent"&gt;<br>  False&lt;/property&gt;<br> &lt;property name="decorated"&gt;True&lt;/property&gt;<br> &lt;property name="skip_taskbar_hint"&gt;<br>  False&lt;/property&gt;<br> &lt;property name="skip_pager_hint"&gt;False&lt;/property&gt;<br> &lt;property name="type_hint"&gt;<br>  GDK_WINDOW_TYPE_HINT_NORMAL&lt;/property&gt;<br> &lt;property name="gravity"&gt;<br>  GDK_GRAVITY_NORTH_WEST&lt;/property&gt;<br> &lt;child&gt;<br>  &lt;widget class="GtkVBox" id="vbox1"&gt;<br>   &lt;property name="visible"&gt;True&lt;/property&gt;<br>   &lt;property name="homogeneous"&gt;False&lt;/property&gt;<br>   &lt;property name="spacing"&gt;0&lt;/property&gt;<br>...<br>   &lt;child&gt;<br>    &lt;widget class="GtkHBox" id="hbox1"&gt;<br>     &lt;property name="visible"&gt;True&lt;/property&gt;<br>     &lt;property name="homogeneous"&gt;False&lt;/property&gt;<br>     &lt;property name="spacing"&gt;0&lt;/property&gt;<br>     &lt;child&gt;<br>      &lt;widget class="GtkButton" id="yesButton"&gt;<br>       &lt;property name="visible"&gt; True&lt;/property&gt;<br>       &lt;property name="can_focus"&gt;True&lt;/property&gt;<br>       &lt;property name="label"&gt;gtk-yes&lt;/property&gt;<br>       &lt;property name="use_stock"&gt;True&lt;/property&gt;<br>       &lt;property name="relief"&gt;<br>        GTK_RELIEF_NORMAL&lt;/property&gt;<br>       &lt;property name="focus_on_click"&gt;<br>        True&lt;/property&gt;<br>       &lt;signal name="released" <br>        handler="on_yesButton_released" <br>        last_modification_time=<br>        "Sun, 21 Nov 2004 19:10:01 GMT"/&gt;<br>      &lt;/widget&gt;<br>      &lt;packing&gt;<br>       &lt;property name="padding"&gt;0&lt;/property&gt;<br>       &lt;property name="expand"&gt;True&lt;/property&gt;<br>       &lt;property name="fill"&gt;False&lt;/property&gt;<br>      &lt;/packing&gt;<br>     &lt;/child&gt;<br>...<br>    &lt;/child&gt;<br>   &lt;/widget&gt;<br> &lt;/child&gt;<br>&lt;/widget&gt;<br>&lt;/glade-interface&gt;<br></tt>
</pre>
</div>
<p>The GLADE system provides a User Interface Builder that makes creating definitions such as
ExampleGNOME.glade simple. Figure 4 shows an example GLADE User Interface Builder session. Listing 8 contains
some of the interface description being edited. Essentially, GLADE allows you to create a user interface
component, name the component so it can be referenced by the corresponding program, provide method names for
component signal handlers and define various properties for the component.</p>
<div class="mediaobject"><a href="http://www.linuxjournal.com/articles/lj/0135/8111/8111f4.png"><img src="http://www.linuxjournal.com/articles/lj/0135/8111/8111f4.inline.png"></a>
<div class="caption">
<p>Figure 4. Designing a user interface in GLADE keeps code and layout separate.</p>
</div>
</div>
<p>Designing the GUI using GLADE and allowing libglade-java to do the heavy lifting significantly reduces the
work of an application developer.</p>
</div>
<div class="simplesect" lang="en">
<div class="titlepage">
<h2 class="title"><a name="N0x850ca10.0x8574694"></a></h2>
</div>
<div class="sidebar">
<p class="title c1">Listing 7. GnomeSesameFormat.java Fragment</p>
<pre class="programlisting"><tt>public class GnomeSesameFormat {<br>...<br>private void init() throws IOException {<br> glade = new LibGlade(System.getProperty("GLADE_FILE"), this);<br> // Default values.<br> isDryRun = false;<br> cipher = new<br> AES256();<br> fs = new Ext3();<br> passphrase = null;<br> volName = null; <br> // References to various windows used by<br> // application.<br> topLevel = (Window) glade.getWidget("topLevel");<br> devSelUI = (FileSelection) glade.getWidget("devSelUI");<br> errUI = (Window) glade.getWidget("errUI");<br> progressUI = (Window) glade.getWidget("progressUI");<br>}<br>...<br>public GnomeSesameFormat() throws IOException {<br> init();<br> device = null;<br> Label l = (Label) <br>                 glade.getWidget("displayedDevice");<br> l.setText("none selected");<br>}<br>...<br>public void onFormatButtonClicked(GtkEvent event) {<br> Entry entry;<br> entry = (Entry)<br> glade.getWidget("entryPassphrase");<br> passphrase = entry.getText();<br> entry = (Entry) glade.getWidget("entryVolumeName");<br> volName = entry.getText();<br> if (topLevelInputOk ()) {<br>  ProgressBar p = (ProgressBar) glade.getWidget<br>                              ("progressBarFormat");<br>  Label l = (Label) glade.getWidget("labelFormat");<br>  ProgressBarUpdater pU = new ProgressBarUpdater(p); <br>  topLevel.setSensitive(false);<br>  progressUI.show();<br>  if (! isDryRun) {<br>   l.setText("Formatting " + device);<br>   pU.start();<br>   execSesameFormat();<br>   pU.stopReq();<br>   try {<br>    pU.join();<br>   }<br>   catch (java.lang.InterruptedException e) {}<br>  } else {<br>   l.setText("[Simulated] Formatting " + device);<br>   pU.start();<br>   try {<br>    Thread.sleep(1000);<br>   } catch (java.lang.InterruptedException e) {}<br>  pU.stopReq();<br>  try {<br>   pU.join();<br>  } catch (java.lang.InterruptedException e) {}<br> }<br> progressUI.hide(); topLevel.setSensitive(true);<br>}<br>...<br>private void error(String msg) {<br> Label l = (Label) glade.getWidget("labelErr");<br> l.setText(msg);<br> topLevel.setSensitive(false);<br> errUI.show();<br>}<br>public void onErrOkButtonClicked(GtkEvent event) {<br> errUI.hide();<br> topLevel.setSensitive(true);<br>}<br>...<br>public static void main(String args[]) {<br> GnomeSesameFormat gui = null;<br> Gtk.init(args);<br> LongOpt[] longOpt = new LongOpt[2];<br> longOpt[0] = new LongOpt("help", <br>                    LongOpt.NO_ARGUMENT, null, 'h');<br> longOpt[1] = new LongOpt("dry-run", <br>                    LongOpt.NO_ARGUMENT, null, 'd');<br> Getopt g = new Getopt("gnome-sesame-format", args,<br>                       "hd", longOpt);<br>                <br> int c;<br> boolean optDryRun = false;<br> while ((c = g.getopt()) != -1)<br>  switch (c) {<br>   case 'h':<br>    printUsage(0, null, null);<br>   case 'd':<br>    optDryRun = true;<br>    break;<br>   default:<br>    printUsage(1, null, null);<br>  }<br> try {<br>  int i = g.getOptind();<br>  if (i == 1)<br>   gui = new GnomeSesameFormat(args[i]);<br>  else if (i &gt; 1)<br>   printUsage(1, null, null);<br>  else<br>   gui = new GnomeSesameFormat();<br>   gui.setDryRun(optDryRun);<br>  Gtk.main();<br> } catch (Exception e) {<br>  System.err.println(e);<br>  System.exit(1);<br> }<br>}<br>...<br></tt>
</pre>
</div>
</div>
<div class="simplesect" lang="en">
<div class="titlepage">
<h2 class="title"><a name="N0x850ca10.0x881e3b0"></a></h2>
</div>
<div class="sidebar">
<p class="title c1">Listing 8. GnomeSesameFormat.glade Fragment</p>
<pre class="programlisting"><tt><br>...<br>&lt;widget class="GtkButton" id="buttonFormat"&gt;<br>...<br> &lt;signal name="clicked" <br>  handler="onFormatButtonClicked"<br>  last_modification_time=<br>   "Wed, 02 Feb 2005 19:16:35 GMT"/&gt;<br>...<br>&lt;widget class="GtkDialog" id="errUI"&gt;<br>  &lt;child internal-child="vbox"&gt;<br>    &lt;widget class="GtkVBox" id="vboxErr"&gt;<br>...<br>      &lt;child internal-child="action_area"&gt;<br>        &lt;widget class="GtkHButtonBox" <br>         id="hboxErrOk"&gt;<br>...<br>          &lt;child&gt;<br>            &lt;widget class="GtkButton" <br>             id="buttonErrOk"&gt;<br>...<br>             &lt;signal name="clicked" <br>              handler="onErrOkButtonClicked"<br>              last_modification_time=<br>               "Wed, 02 Feb 2005 19:22:48 GMT"/&gt;<br>...<br>            &lt;/widget&gt;<br>          &lt;/child&gt;<br>        &lt;/widget&gt;<br>      &lt;/child&gt;<br>      &lt;child&gt;<br>        &lt;widget class="GtkHBox" id="hboxStop"&gt;<br>...<br>          &lt;child&gt;<br>            &lt;widget class="GtkImage" id="imageStop"&gt;<br>...<br>            &lt;/widget&gt;<br>          &lt;/child&gt;<br>          &lt;child&gt;<br>            &lt;widget class="GtkLabel" id="labelErr"&gt;<br>...<br>            &lt;/widget&gt;<br>          &lt;/child&gt;<br>        &lt;/widget&gt;<br>      &lt;/child&gt;<br>    &lt;/widget&gt;<br>  &lt;/child&gt;<br>&lt;/widget&gt;<br></tt>
</pre>
</div>
<p>Listing 7 displays some of the corresponding Java source code for GnomeSesameFormat. Listing 8 contains a
portion of GnomeSesameFormat's interface definition.</p>
<p>GnomeSesameFormat is a simple application I developed, and most of its work is done by executing an
external program called sesame-format. sesame-format formats a disk to contain an encrypted filesystem.
GnomeSesameFormat simply provides a GUI wrapper for this command-line tool. GnomeSesameFormat can be executed
with its --dry-run option to facilitate testing and experimenting. As of this writing, it's probably a bad
idea to format a disk using this tool. A screenshot of GnomeSesameFormat is shown in Figure 5.</p>
<div class="mediaobject"><a href="http://www.linuxjournal.com/articles/lj/0135/8111/8111f5.png"><img src="http://www.linuxjournal.com/articles/lj/0135/8111/8111f5.inline.png"></a>
<div class="caption">
<p>Figure 5. GnomeSesameFormat gives you an easy-to-use front end for setting up and using encrypted disk
partitions.</p>
</div>
</div>
<p>The GnomeSesameFormat application is implemented in a single class, GnomeSesameFormat. The
GnomeSesameFormat class' main function initializes the GTK libraries using the Gtk.init method, creates a new
GnomeSesameFormat instance and releases control to the GTK event loop by calling Gtk.main.</p>
<p>The interesting work begins in the GnomeSesameFormat class' constructor. In the constructor, a LibGlade
object is instantiated. It reads a GLADE user interface description and instantiates its corresponding
objects. A reference to these objects can be retrieved by name using the LibGlade object's getWidget method.
Once we have a reference to an interface component, we can use them as if we created them ourselves. The
GnomeSesameFormat class also contains the signal handling methods referenced in GnomeSesameFormat.glade.</p>
<p>In developing GnomeSesameFormat, I used the four steps presented above. For example, a button was defined
using GLADE as part of the application's GUI (step 1). The button was named buttonFormat (step 2). Again
using GLADE, a method name of onButtonFormatClicked was designated to handle the button's clicked symbol
(step 3). Finally, the onButtonFormatClicked method was implemented in GnomeSesameFormat's Java source code
(step 4).</p>
<p>In order to manipulate components further, libglade can provide a reference to an individual component. A
LibGlade object's getWidget method provides this capability. To illustrate this, we can investigate
GnomeSesameFormat's errUI component. The errUI component is a Window that displays error messages for the
user. The errUI window was defined in GLADE (step 1) and named (step 2). Because we know the name of errUI,
we can get a reference to it by calling getWidget(errUI). Once we receive a reference to the component, any
GTK method may be invoked. GnomeSesameFormat uses errUI's show and hide methods.</p>
<p>The GNOME Project provides the ability to develop applications in C, C++, Java, Python and Perl. In
addition, external projects such as Mono provide even more diversity. When used with several of these
alternatives, the GLADE User Interface Builder makes it possible to write applications quickly with a
graphical user interface for the GNOME platform. Once the graphical components are defined, an application
shell and signal handlers all are that remain to be implemented. This implementation can be done using any
programming language.</p>
<p><span class="bold"><b>Resources for this article:</b></span> <a href="http://www.linuxjournal.com/article/8274" target="_top">www.linuxjournal.com/article/8274</a>.</p>
</div>
</div>
<p>Mike Petullo currently is working at WMS Gaming and pursuing a Master's degree at DePaul University. He
has been tinkering with Linux since 1997 and welcomes your comments sent to <a href="mailto:lj@flyn.org">lj@flyn.org</a>. Thank you to Noah Alcantara for helping to review this article.</p></div>
<img src ="http://www.blogjava.net/roley/aggbug/5409.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/roley/" target="_blank">有个空间</a> 2005-06-01 14:20 <a href="http://www.blogjava.net/roley/archive/2005/06/01/5409.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我得到的和我失去的</title><link>http://www.blogjava.net/roley/archive/2005/06/01/5403.html</link><dc:creator>有个空间</dc:creator><author>有个空间</author><pubDate>Wed, 01 Jun 2005 04:53:00 GMT</pubDate><guid>http://www.blogjava.net/roley/archive/2005/06/01/5403.html</guid><wfw:comment>http://www.blogjava.net/roley/comments/5403.html</wfw:comment><comments>http://www.blogjava.net/roley/archive/2005/06/01/5403.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/roley/comments/commentRss/5403.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/roley/services/trackbacks/5403.html</trackback:ping><description><![CDATA[



<p><span style="font-size: 9pt;">一直以来我发现自己总是没什么延续性，</span></p>
<p><span style="font-size: 9pt;">似乎我的生活总在某个事件之后出现了断代，就好像中国的历史，没办法完整的衔接。</span><span style="font-size: 9pt; font-family: Tahoma;" lang="EN-US"><o:p></o:p></span></p>


<p><span style="font-size: 9pt;">但是我还是活在这个世界上，我还得继续活在这个世界上。</span><span style="font-size: 9pt; font-family: Tahoma;" lang="EN-US"><o:p></o:p></span></p>


<p><span style="font-size: 9pt;">很多东西已经从记忆里模糊了，重新找回来也不可能了。</span><span style="font-size: 9pt; font-family: Tahoma;" lang="EN-US"><o:p></o:p></span></p>


<p><span style="font-size: 9pt;">有的时候真的发现自己一无所有，真的什么都没有了</span><span style="font-size: 9pt; font-family: Tahoma;" lang="EN-US">……<o:p></o:p></span></p>

<img src ="http://www.blogjava.net/roley/aggbug/5403.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/roley/" target="_blank">有个空间</a> 2005-06-01 12:53 <a href="http://www.blogjava.net/roley/archive/2005/06/01/5403.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>