Friday, 20 April 2007

regular_expression

Shell Metacharacters: Special characters are interpreted by the shell for expansion unless they are quoted or escaped
  • * metacharacter means any srtings of zero or more characters, eg *.*,
  • ? matches any single character
  • [] matches any of the eclosed charcter. [a-z] or [!abc]
  • ` substitutes the output of a command.


Avoiding Shell Expansion: The character needs to be quoted or escaped

quoted:

  • "" everything between " and " is taken literally, except for : $ ` ' " .
  • '' everything between ' and ' is taken literally except for ' . we can embed another ' within a pare of ' using escaping.


Escaped: using \

  • The character following a backslash \ is taken literally.
  • Use \ within ″ ″ or ’ ’ to escape ″, $, and ′ when necessary.

p11

shell_script

Environment Variables: used by shell and by other programs:


  • [zliybsj2@unnc-cslinux ~]$ echo $PATH
  • /usr/kerberos/bin:/usr/local/bin:
  • /bin:/usr/bin:/usr/X11R6/bin:/opt/SUNWappserver/jdk/bin/:
  • /usr/NX/bin:/home/domain/zliybsj2/bi
  • [zliybsj2@unnc-cslinux ~]$ echo $TERM
  • xterm
  • [zliybsj2@unnc-cslinux ~]$ echo $HOME
  • /home/domain/zliybsj2
  • [zliybsj2@unnc-cslinux ~]$ echo $PS1
  • [\u@\h \W]\$
  1. using all capitals,
  2. using echo to get the value of a variable.
  3. variables are expanded by the shell before he command is executed.
  4. environment variables can be used by any program.
  5. variables change is only visible in the current shell.child process don't automatically inherit the environmrnt variables from their parent. using export to let proecessed get the changed value, eg export VAR=value, then $VAR in child process is value, or stay same. using : to add somthing to PATH, eg, export PATH=$PATH:new stuff

PATH:

  1. it tells UNIX where to look for executables
  2. when you type the name of a program, the shell will look for it in your PATH
  3. ecah directory seperated by a colon
  4. changed PATH can only live in current widow.

shell script:

  1. the shell is a command interpreter
  2. shell script is a text file contains all command you want to group, which is executed in a sub shell.
  3. first line is a specially comment: #!/bin/sh tell program which kind of shell will be using to execut this shell.

chomd :

  1. chmod o-r coursework
  2. chmod u+x shellscript
  3. chmod a+x shellscript
  4. chmod +x directory

input and output:

  • echo works like Java's println.
  • argument: $0, $1, $2,...... $#

conditionals:

  • if ...
  • then ...
  • else if ...
  • else ...
  • fi

read: to get input to interacte with users

can have more than one argument. will bind the first word of input to the first variable and bind the rest to the second. this acts like a list or array, so can be used with for.

controlling input:

  • using <<>
  • using <>

Thursday, 19 April 2007

SMB/CIFS

会话的建立:
SMB协议已经被发展成为可以运行于DOS操作系统,因此字节顺序将会和网络顺序相反。
SMB可以运行在TCP/IP,NetBEUI,DECnet和IPX/SPX协议之上。如果SMB执行于TCP/IP,DECnet或则是NetBEUI之上,那么NETBIOS名字必须被使用。
NETBIOS名字用来在网络上鉴别一台计算机。
SMB域名是用来鉴别一个SMB服务器上的一组资源的(用户,打印机,文件……)。
让我们假设一个这样的环境:一个客户端希望访问一台服务器上的特定资源。
1 - 开始于客户端向服务器请求一个NETBIOS会话。客户端发送它的已编码的NETBIOS名字到SMB服务器(它们在139端口监听连接请求)。服务器接收到NETBIOS名字后回复一个NETBIOS会话数据报给有效的会话连接。客户端在建立了连接之后才能进入访问。
2 - 客户端发送一个SMB negprot请求数据报(negprot是磋商协议“negotiate protocol”的简写)。客户端列出了它所支持的所有SMB协议版本。
3 - 通过磋商之后,客户端进程向服务器发起一个用户或共享的认证。(下一章中我们将会看到共享认证和用户认证之间的不同)。
这个过程是通过发送SesssetupX(SesssetupX是会话建立和X“Session setup and X”的简称)请求数据报实现的。客户端发送一对登录名/密码或一个简单密码到服务器,然后服务器通过发送一个SesssetupX应答数据报来允许或拒绝本次连接。
4 - 好了,在客户端完成了磋商和认证之后,它会发送一个TconX数据报并列出它想访问的特定网络资源的名称,之后服务器会发送一个TconX应答数据报以表示此次连接是否接受或拒绝。

SMB的安全等级
第一种是“共享”级的安全模式。这种安全模式需要一个访问网络上共享资源的密码。用户通过这个正确的密码来访问网络资源(IPC,磁盘,打印机)。他可以是网络上任何一个知道共享资源服务器名字的用户。
第二种是“用户”级的安全模式。这是在第一种模式上的增强版。它坚持使用一对登录名/密码来访问共享资源。所以如果一个用户想访问这种类型的共享资源,就必须同时提供登录名和密码。这种

密码
在SMB协议中,如果你想进行一次在服务器上的请求认证,你的密码可以以原码或加密后的形式发送到服务器端。如果服务器支持加密属性,客户端必须发送一个应答信号。在negprot应答数据报中,服务器会给客户端发送一个密钥。然后,客户端将密码加密并通过SesssetupX请求数据报发送到服务器端。服务器将会核查密码的有效性,并由此允许或拒绝客户端的访问。
你必须知道一个SMB密码(未加密)的最大长度是14位。密钥的长度一般为8位,加密过后的口令长度为24位。在ANSI密码中,密码中的所有位都转换成大写的形式然后再加密。
密码是以DEC编码方式进行加密的。

几种SMB数据报的描述
SMB数据报的常规特征
通常情况下,SMB运行于TCP/IP协议组之上。那么我们就假设SMB运行在TCP层之上。在TCP层上面,你常常会发现NETBIOS(NBT)头部。在NBT上面,有SMB基础报文头部。在SMB基础报文头部之上,就是另一种依赖于特定请求命令的头部。
----------------------
│ TCP Header │
----------------------
│ NETBIOS Header │
----------------------
│ SMB Base Header │----------------------
│ SMB Command Header │----------------------
│ DATA │----------------------
“SMB Base header”包含了几种信息,像接收缓冲区的长度,允许的最大连接数目……它也包含了一个鉴别请求命令的数字。
“SMB Command header”包含了所有的请求命令的参数(像磋商协议版本命令……)。
“DATA”容纳了请求命令的数据。
我们把“SMB packet”看成:NETBIOS Header + SMB Base Header + SMB Command Header+ DATA。
注意:我将使用这个定义:
typedef unsigned char UCHAR; // 8 unsigned bitstypedef unsigned short USHORT; // 16 unsigned bitstypedef unsigned long ULONG; // 32 unsigned bits
而STRING被定义为以空字符结束的ASCII字符串。
NETBIOS与SMB
NETBIOS(NETwork Basic Input and Output System)在微软的网络系统中被广泛使用。它是一个软件接口和命名系统。每台主机都有一个长度为15个字符的NETBIOS名字,且第十六个字符用来标志主机的类型(域名服务器,工作站……)。
第十六个字符的选择:
0x00 基础电脑,工作站。0x20 资源共享服务器。
这还有一些其他的值可选,不过我们对这两个最感兴趣。第一个(0x00)鉴定一台工作站,第二个(0x20)鉴定服务器。
在一个SMB数据报中,NETBIOS头部对应NETBIOS会话头部。
定义如下:
UCHAR Type; // Type of the packetUCHAR Flags; // FlagsUSHORT Length; // Count of data bytes (netbios header not included)
“Flags”域的值总是被置为0。
“Type”域有几种可能的选择:
0x81 对应一个NETBIOS会话请求。这个代码在客户端发送它的NETBIOS名字到服务器是使用。
0x82 对应一个NETBIOS会话应答。这个代码在服务器向客户端批准NETBIOS会话时使用。
0x00 对应一个会话消息。这个代码总是在SMB会话中被使用。
“Length”域包含了数据字节的长度(NETBIOS头部没有被包含在内)。数据包含在NETBIOS头部以上的所有部分(它可能是 SMB Base Header + SMB Command Header + DATA 或 NETBIOS名字)。
NETBIOS名字与编码。
NETBIOS编码名字的长度为32字节。
NETBIOS名字总是以大写的形式存在的。
编码一个NETBIOS名字非常的简单。例如我的计算机的NETBIOS名字是“BILL”,它是一个工作站,所以它的第十六个字符为“0x00”。
首先,如果一个NETBIOS名字比15字节短,就会在右边补填上空格。
“BILL “
十六进制为: 0x42 0x49 0x4c 0x4c 0x20 0x20 ......0x00
每个字节都分裂为4位一组:
0x4 0x2 0x4 0x9 0x4 0xc 0x4 0xc 0x2 0x0 .......
而且每个4位都要添加ASCII码‘A’的值(0x41)。
0x4 + 0x41 = 0x45 -> ASCII value = E0x2 + 0x41 = 0x43 -> ASCII value = C……
最后NETBIOS名字被编码为32字节长。
注意:
SMB可以直接运行于TCP之上而无须NBT(在Windows 2k和XP上它们使用455端口)。此时,NETBIOS名字没有被限制在15字符以内

STDIN

yesterday, with Ye_Yuan together to try to work out how to decrypt by most stupid way.. however, we find it is impossible to guess this passward, because it need many year. however, it help me to over some UNIX problem.
first is that, I can write script to using STDIN instand of type in by hand. for example, there is a command: smb -U username password servicename. it can lead us into the windows share dirve on Linux service platform. however, when we get into this sharedrive, we need to type command into this program, which means we are in this program. but how can I use script to execute command in sequence? using STDIN. there are two ways, first is like this to write in script:
  1. smb -U zliybsj2 $1 //10.2.1.21/Central_Application_Center <<>
  2. ls
  3. exit
  4. EOF

first, script will using $1 as possward to login Central_Application_Center, then input ls, run it and exit, run again and finish to goto the next command. here EOF is a labell.

another way to write is creating another file, such as com1, we write what we want to do after we get into Central_Application_Center. so, as follow:

  1. smb -U zliybsj2 $1 //10.2.1.21/Central_Application_Center <>

in com1:

  1. ls
  2. exit

There is another way to test when a script or program is runing well by using returning number. as follow:

  1. succ=0
  2. smb -U zliybsj2 $1 //10.2.1.21/Central_Application_Center <>
  3. if [ succ -ed $? ]; then
  4. echo running_well
  5. else
  6. echo some_mistakes_happened
  7. fi

here, $? stands for the retunring number of last program. so if we can complete the left part, such as however to create a pasward, the do this loop to guess, this is the most stupid way to decrypt, if for us time is not a problem. just a joking.

awk

what does awk do:

  1. deal with text file which is thought of as being made up of records and fields. we can write programing by awk to do anything we want.
  2. we can:execute UNIX command from within a script; process the output from UNIX commands; work with multiple input streams; define functions.
  3. we can combined with sed and shell scripting. compared: shell is very easy and quick to write, but lacks functionality. sed, awk, and shell are designed to be integrated.

invoke:

  1. awk [options] 'script' var=value file(s)
  2. awk [options] -f scriptfile var=value file(s) : we can have more than one -f scriptfile.
assigning values to variables can be:

  1. a literal: awk -f scriptFile count=5
  2. a shell variable: awk -f scriptFile count=$count
  3. A command substitution: awk -f scriptFile count=`who wc-l`

set filed seperator:

  1. using -F
  2. one line can be sperated into different filed and can be refered by variables $1, $2 etc. $0 means the whole record.

awk script consist of patterns and procedure:

  1. a pattern can be : /regular expression/, eg /^...:/ or relational expression, eg $1=="gdm". ~ means match, !~ means don't match, eg awk -F: '$1 ~ /.dm.*/ {print $0}' /etc/passwd. BEGIN specifies procedure to take place before the first input line is processed, END as well, eg awk ‘BEGIN {print “Version 1.0”}’ dataFile. pattern missing, the procedure applies all lines
  2. procedure is arround by {} and seperated by newlines or semi-colons. can be: commands, functions and veriable assignment. procedure missing, printed all lines matched by pattern.

commands used with procedures: 5 types

  1. Assignments of variables or arrays
  2. Commands that print
  3. Built-in functions
  4. Control-flow commands
  5. User-defined functions (in nawk only)


awk Built-in Variables:

  1. FILENAME - current filename
  2. FS - Field separator
  3. NF - Number of fields in current record
  4. NR - Number of current record
  5. RS - Record separator
  6. $0 - Entire input record
  7. $n - nth field in current record

awk operators: $_++_ --_ +_-_!_*_/_%_<_<=_>=_>_!=_==_~_!~_in_$$__?:_=_+=_-+_*=_/=_%=

two ways to usingarrays in awk:

  1. in an assignment statement: myArray[i]++
  2. split() function : n=splict(input,words," ") : splict this input by " "(whitespace) into words.

functions in awk: works in the same way as java: calling a function, no sapce between function name and left bracket.

Wednesday, 18 April 2007

Graphical User Interface Programming

finished

Introduction to GUI Programming

Event-driven Programming: program responds to these events. The order of the events is determined by the user, not the program. This is similar to going to a hardware store to get components for your home improvement project. Most of the components you need already exist. All you need to do is to install them.
Java GUI Programming:A user interacts with a GUI application by causing events. The application must respond to events in the order they arrive.
Three Parts of a GUI Program:
  1. Graphical Components make up the Graphical User Interface.
  2. Listener methods receive the events and respond to them.
  3. Application methods do useful work for the user.

The graphical components are Swing objects. You may use them without change or may extend them to make your own classes. Listener methods and application methods are Java methods that you write. Listener methods respond to events by calling application methods. Application methods are ordinary Java methods that perform useful computations. They receive data from the GUI and send data to the GUI to be displayed, but are not usually themselves concerned with the user interface.

To write a GUI application, keep these three types of software separated (while keeping the big picture in mind). In a big software project an entire team of programmers is assigned to each of the tasks.

Container Classes: A GUI program consists of a collection of graphical components that are all placed inside one or more windows. A container is an object that can hold other GUI components. In Java terminology, a window (such as the browser window you are looking at) is a container. The buttons, sliders, icons and other GUI components are contained (by the container).

AWT Hierarchy: Some of the AWT classes derived from Component are Button, Canvas, and Container. The JComponent class is derived from Container and is one of the base classes of Swing. The JFrame class is derived from the AWT Frame class. It is usually the main container for a GUI application.

JComponent class: Objects of classes based on Container have common characteristics. They can contain components, they themselves can be placed inside containers, they can be displayed on the monitor, they generate events, they register event listeners, and so on. Since all Swing classes have Container as an ancestor, all Swing objects have these characteristics.

Swing JFrames:

Frames: In Java, a frame is a window that has nice borders, various buttons along the top border, and other features. What you usually call a "window" Java calls a "frame". A frame is a container object, so GUI components can be placed in it. a frame object is actually a section of main memory that holds information and methods. With the help of the operating system and the graphics board.

Small GUI Program

First a JFrame is created by invoking its constuctor. The argument to the constructor sets the title of the frame. The setSize(200,100) method call makes the rectangular area 200 pixels wide by 100 pixels high.
The setVisible(true) method call makes the frame appear on the screen. If you forget to do this, the frame object will exist as an object in memory, but no picture will appear on the screen. A call to setVisible(false) makes the frame invisible, but does not destroy the software object.
It is easy to forget to include setVisible(true). If you run your GUI program, and nothing happens, check that you have called this method.

The setDefaultCloseOperation() method picks the action to perform when the "close" button of the frame is clicked. This is the little button usually at the top right of the frame. If you forget to call this method with the appropriate constant, clicks on the close button will be ignored.

Running the GUI Program:

The usual way of writing a GUI is to define your own class by extending the JFrame class.

The drawString() method: When the Java system needs to paint a MyFrame object it first draws most of the picture and then calls paint() in the MyFrame object to do whatever extra the programmer wants. The first part of the work is vital. It involves interacting with the graphics of the computer system and controling the graphics board. The parameter g is a reference to a Graphics object. The Graphics object represents the part of the frame that you can draw on. When the system calls paint(), the system provides a value for this parameter. One of the methods of Graphics is drawString(String st, int X, int Y) which draws a string on the graphics area at location starting X pixels from the left and Y pixels from the top.

Buttons and Actions

JButton->AbstractButton->JComponent->Container->Component->Onject

To construct a JButton object, use new. Then add the button to the frame's content pane. The content pane is a container that represents the main rectangle of the frame. To get a reference to the content pane, use the getContentPane() method of the frame. The add method of a content pane puts a JButton (or other component) into the frame.

The ButtonFrame class does not to define a paint() method because everything in the frame is a Swing component. The system will automatically paint all components in a container when it needs to. If special processing is needed, (as with drawString() in the previous chapter), then you need to override paint().
The program in the previous chapter did not define a constructor because the constructor it inherited from its parent class JFrame was enough to do the job. ButtonFrame adds a components, and this should be done in a constructor.

Layout Manager:

When you add() buttons (and other components) to a content pane, a layout manager automatically decides what size they will be and where they will go. This is convenient, because you can add components without worrying about the details. The layout manager is like a little artist inside the computer. You say what components you want and the layout manager lays them out in the picture.
The layout manager sometimes makes odd choices. However, there are several kinds of layout managers. Each layout manager has a different style of positioning components. Usually there is a layout manager that will do the job you want. If you don't specify otherwise, a default layout manager is used.

Our program will look better if it uses the FlowLayout manager. The FlowLayout manager puts components into the frame row by row in the order they are added.

Event Listener Object

For a program to respond to an event there must be an event listener object for it. The event listener object contains listener methods for various types of events

Event Object

An event listener is an object that "listens" for events from a GUI component, like a button. An event is represented as an object. When the user generates an event, the system creates an event object, which is then sent to the listener that has been registered for the GUI component.

To be able to respond to events, a program must first:
Create an event listener object for the type of event.
Register the listener object with the GUI component that generates the event (or with a component that contains it).

ActionListener

A button listener class must implement the ActionListener interface. ActionListener is an interface (not a class) that contains the single method: public void actionPerformed( ActionEvent evt) ;
The ActionEvent parameter is an Event object that represents an event (a button click). It contains information that can be used in responding to the event. Since ActionListener is an interface, you use it with a class that will implement the actionPerformed() method. It is common to implement the interface in the same class that contains the button(s):

For the ActionListener interface, there is only one method: actionPerformed().

The repaint() method called in actionPerformed()tells the system to repaint the screen sometime soon because we have changed something. The system will do this when it is ready. Don't call paint().

The frame will be the listener for the button.

button's life in a frame:

  • JButton newButton=new JButton(***) ; //create a new JButton object and assign to newButton
  • newButton.addActionListener(this);//addactionlistener
  • getContentPane().add(newButton);//add into JRame
  • public void actionPerformed(ActionEven e){***}//action performeed. everytime, when a even happened, such as mouce moved, if such kind of event has been registed, than a even object is created and have certain action performeed, after performed, then program executes next statement or event, or this performemt will not stop. so we can see is a button is released on show which means relevant actionPerformed has been successed done. if this even is not registed, system just ingnore them.

Buttons and Action Events

setActionCommand() and getActionCommand() method refer to different action, it will pass or return String to distingish different button event. which can help us to deal with different event in actionPerformed() method.

Swing Text Fields and Labels:

A Swing Component: JTextField

A JTextField is a box that contains text. The user can type text into the box and the program can get it and then use it as data. The program can write the results of a calculation to a JTextField.

To enter text into the field you must first click the mouse pointer inside of it. This gives the field the keyboard focus (usually just called focus). When a component has focus, characters from the keyboard are directed to that component. A component gets focus by various means. The user might click it, or the program might give it focus.

JTextArea+JTextField+JEditorPane -> JTextComponent->JComponent->Container->Component->Object

The JLabel Class

In a typical application with a graphical interface, about 40% of the code manages the user interface. The rest of the code is for the application--the reason the program was written. Usually the application code is kept separate from the code that manages the interface. In a big application it would be confusing to mix the two together.

The GUI components from Swing can be used by applets.

It is a good idea to keep the GUI code and the application code in separate modules to help in debugging and understanding the program. This is also helpful if you later need to make changes to the program, say changing it from an application to an applet. The application code can be carried over without change.

The user can type into a JTextField even if it does not have a listener. getText() will still work

JPanel and BoxLayout

Each panel uses its own layout manager for the components it contains. The default layout manager of JPanel is flow layout, which is often ideal. But you may use another layout manager if appropriate.

BoxLayout Layout Manager

BoxLayout. This layout manager aligns components either horizontally or vertically within a pane. BoxLayout(Container box, int axis)
box: the container this layout manager is for axis: BoxLayout.X_AXIS -- for left to right alignment BoxLayout.Y_AXIS -- for top to bottom alignment . box is a reference to the container which will be managed by this layout manager. Often the container is a content pane.

This idea of nesting panels is a powerful one. It may look complicated and tedious, but it is much less so than laying out a design on graph paper and specifying the exact size and location of all the components. Such a design has no flexibility. What happens if you want to add or delete a component? Everything must change. With Java's layout managers everything is dynamically adjusted.

Radio Buttons, BorderLayout, and Glue

Radio Buttons
Usually radio buttons are placed in (1) a panel, to control how they are displayed, and (2) a button group, to control which buttons may be active simultaneously. A button group is an object which must be constructed. Radio buttons are then added to it.

Radio buttons generate action events which require a registered action listener. Do this as with JButtons. Use setActionCommand() to assign a command string to each button. Use addActionListener() to register a listener for each button, usually the same listener for all the buttons in a group. Use getActionCommand() in the action listener to determine which button was pushed.

BorderLayout

BorderLayout.is a frequently used layout manager. The container it manages corresponds to a rectangle on the screen. That rectangle is divided up into five regions:

  • BorderLayout.NORTH,
  • BorderLayout.SOUTH,
  • BorderLayout.EAST,
  • BorderLayout.WEST,
  • BorderLayout.CENTER.

Each region may hold only one component, although that component may be a panel (and usually is). The panel may contain several components. The layout manager adjusts the size of the regions depending on what is in them. You don't have to put a component in each region. If a region has no component in it, it shrinks to a small area.

Class Box

Layout managers sometimes jam components together in a way that makes the layout look cramped. The class Box can help in this situation. A Box object is a container similar to a panel, but lacking some features. The default layout manager of Box is BoxLayout. However, the most useful features of class Box are its methods that create invisible components. These components correspond to rectangular areas of the screen. They are used as spacers to separate the visible components. If you have ever set type you know how useful spacers are in creating an attractive page. To create a fixed-sized invisible component use the method: Box.createRigidArea( new Dimension( int width, int height ) )
The parameter to createRigidArea()is a Dimension object, which does little more than hold a width and a height.

All GUI components have a getSize() method that is used to determine the dimensions of the component. The dimensions may change as a program executes, so this is a useful method. To determine the current size of a frame, use: Dimension JFrame.getSize()
Then it can look at the height and width fields of the Dimension object. Using this data it can create a rigid area of appropriate size. If this is too complicated, then use glue.
The glue component is another invisible component that class Box creates. Think of glue as stretchy caulking between components. It keeps them separated, but expands or shrinks as needed.
To create glue use one of the following:

  • Box.createHorizontalGlue()
  • Box.createVerticalGlue()

Class JSlider

JSlider( int orientation, int min, int max, int init )
orientation: SwingConstants.HORIZONTAL or SwingConstants.VERTICAL
min: the minimum value. The value when the slider is at the extreme left (or very bottom) of its range.
max: the maximum value. The value when the slider is at the extreme right (or very top) of its range.
init: the initial value of the slider

  1. JSlide silderV=new JSlide(SwingConstants.HORIZONTAL, 0, 100, 79)
  2. slideV.setMajorTickSpacing(10);
  3. slideV.setMinorTickSpacing(10);
  4. sliderV.setPaintTicks(true);
  5. sliderV.setPaintLabels(true);
  6. sliderV.setSnapToTicks(true);

setPreferredSize()

The layout managers have control over the size of components, but often do their job better if you indicate a preferred size. This is done with setPreferredSize( new Dimension( int width, int height )
If this is not used, the graphical representation of a slider often has its labels and tick marks crowded together

A listener for a slider implements the ChangeListener interface. This interfaces has a single method: public void stateChanged(ChangeEvent evt)
An object that implements the interface must be registered with the slider in order to receive events: slider.addChangeListener( ChangeListener lstn )
There may be several sliders in your user interface. They all generate change events. If one change listener listens to all these events it is convenient to give the sliders names so that the events can be sorted out correctly. (Another way is to register its own listener with each slider). A name is a string that can be assigned to any object that inherits from class Component. Assign it using: component.setName( String name )
Of course you must make sure that components that share the same listener have unique names.

The Object getSource() Method

An event object contains a reference to the component that generated the event. To extract that reference from the event object use: Object getSource()
Since the return type of getSource() is Object you typically use a type cast with it: // listener method
public void stateChanged( ChangeEvent evt )
{
JSlider source;
source = (JSlider)evt.getSource();
. . . .
}
Now that you have a reference to whichever slider caused the event you can use any of the slider's methods.

Assume that the slider has a name you have set using setName(). The name of the slider is a string that is stored as part of its data. To ask the slider for its name use: String getName()
Then, to get the value of the slider use int getValue()
The value is an int between the minimum and maximum value of the slider.

In the previous application the number in the text box changes continuously as the knob is moved. Usually this is desirable. But sometimes the application calls for a great deal of work and you don't want to do it for each change event. There are (potentially) hundreds of change events generated in moving the knob from one value to the next. While the value is still changing the listener should discard the event. boolean getValueIsAdjusting()
This method returns true while the knob is still moving.

Tuesday, 17 April 2007

sed

introduction:

before this we have two method to deal with text. one is to search by using grep, however we can only show the orgainal text on screan, no modify; the other is to edit using emacs, however we need to open a new window, and all behaviour will be record which means the orgainal one can be changed easly. now, we have another one named sed which can combine both advantages.


character:

  1. work on terminal as command, so will not need to open a new window.
  2. deal with file stored in your computer or online.
  3. it is a lightweight stream editor, so will not using too much memoy, the result will show on scream as stdout
  4. Sed works by performing any number of user-specified editing operations ("commands") on the input data. Sed is line-based, so the commands are performed on each line in order. And, sed writes its results to standard output (stdout); it doesn't modify any input files.

what does sed do:

  1. edit input stream. the orgainal source stay same, only patch match be modified.
  2. produce results on standard output. modifed date can show on scream or pipled.

how does sed work:

  1. make a copy of orginal file. and the left steps are works on this copy not the orgainal one
  2. input the first line into internal bufffer.
  3. act command on this line and print result on scream or file. if there are more than one command being act on one line, it will execute it in sequence, which means the result of former command can be picked by the next command.
  4. input the next line and repeat step 2 and 3 until the while file has been acted.

how to run it from command line:

  1. sed [-n] [-e] 'command' file(s)
  2. sed [-n] -f scriptfile file(s)

formating : using regular excpressions

  1. ^, $, ., *, ?, [], [^]
  2. \{m, n\} :repeat m or more than m times, but no more than n times.
  3. \(, \) : group operator or regin of interest, and alwoys using with \n. often \n appear after \(, \), \n mean nth of \(, \).

sed command syntax: sed [address[,address]] [!]command [arguments]

  1. sed can have 0, 1, or 2 address. and can be line number, symbol or regular expression in slash. no address means applying to each input line. one address meanwhile applying to any line match this address. twp comma_separated address means form one certain line to another certain line. an address followed by ! means DO NOT match this address.
  2. we can put more than one sed element in a command. if first command change the buffer, the will refer to this new stuff.

flag to command:

  1. g: global or all occurences of something
  2. p: print pattern space to stdout if substitution succeddful
  3. n: replace the nth occurence of pattern with replacement text.
  4. w filename: write the pattern space of line that are changed to resultsfile if substitution succcessful.

example:

  1. sed '/^#/d' myfile delecte all line starting with # as comment.
  2. sed '/on/,/5050/d' xinetd.confsed will print the text after 5050. sed -n '/on/,/5050/d' xinetd.confsed will print nothing. sed -n '/on/,/5050/p' xinetd.confsed will print out text between on and 5050. sed '/on/,/5050/p' xinetd.confsed will print the line between on and 5050 each for twice, becasue we first print current line into buffer again, then in 5050, print again.
  3. s/.*// means subtitute all text found for an empty string
  4. who sed -n ‘s/.*(\(.*\))/\1/p’ sort > machines.txt

using different delimiters:

  1. sed tries to match the longest expression!
  2. using non-'>' character: sed -e 's/<[^>]*>//g' UST.html

character classes-posix compliant sed:

  1. sed ‘s/[[:space:]]//g’ myfile
  2. how can we just select but not subtitution or other?



Monday, 16 April 2007

google_doc

I am so happy to finish my job today to create all elements i will need later, including all posts post today and all labels.
In this process, I find a quite fine tool and have to admire how great google is, that is google doc&document, which means you can use word, excell, and so on online, compared to OFFICE, we need to instal and maintain them, however you do not need to worried about these, only to using it and save online, when we using OFFICE, one problem is that the font we using on this pc maybe not instal on that pc, your word and others will fail to appear. however, it does not happened again, because all google doc&document are using same standand. maybe it will completely take market, because it can implement nearly all functions which OFFICE have, and the speed is fast at least when I use in IT_room. The favor is that we can create pdf by this, which is OFFICE can not succee. I can write pdf, modify it and read it then save on google. quite funny.
welcome to using it:http://docs.google.com/

Ubiquitous_link

at the begaining of this semester, Donlad know i am internesting in Ubiquitous computer, so he gave me links to his two friends.
London Knowledge Lab
Mark Levene
George Roussos
meanwhile, there are several link to some conferences:
Ubicomp 2007
Ubiquitous Computing (UC)
Pervasive & Ubiquitous Computing Course

dbs_notes

bonny_wong's_notes_in_cn

language_teacher

when I come to Uk, maybe this web will be quite usefull, because it can not only help me to know more friends, but also more money. I search on this, and many people in nottinghame where I will head to, wish to learn Mandarin.
weblink here.

鸟哥的linux

鸟哥的linux

mit_open_course

mit_open_course:麻省理工开放课程

convention_c_code_and_mips_code

a few days ago, i did a really stupid thing to do convention between c and mips code. I should pay more attention not to do such things again
Cconvention_c_code_and_mips_code.doc

computer_science_architecture_tool

liyang_hu's_webprogrammed_introduction_to_MIPS_assembly_language
MIPS architecture
计算机项目研究所列表

link_to_other_or_link_to_me

me:
name:en_version==Shao_Jianhua; cn_version==邵建华
nickname==Dustin
msn==dustin_shaojianhua@hotmail.com
mail==dustin.shaojianhua@gmail.com
qq==175190516
this_web_link==http://shaojianhua.bloggerspaces.com

==============================================
**********************************************************
==============================================
friends
wu_chengdong: crystal

haskell_tool

haskell_98_report
Learning Haskell
hoogle
Haskell Reference

java_review_and_exam_review

java_review_last_semester
java_exam_review
both of them has be sant to my mailbox

java_learning_tool

java api 1.5 en
java_api_1.5_cn
java_game_tutorial
free_game_source_code_in_java
Dictionary_of_Algorithms_and_Data_Structures
Bruce_Eckel's_book_page
java_office_web_training

blog_this_song

http://www.blogthissong.com/index.php