create a swing application

September 11th, 2009
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
 
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
 
public class Test3 extends JApplet {
 
	public void init() {
		Container contentPane = getContentPane();
 
		Icon icon = new ImageIcon(ClassLoader.getSystemResource("swing.gif")); 
		JLabel label = new JLabel(icon);
//		java.net.URL codebase = getClass().getResource("../swing.gif");
//		JLabel label = new JLabel(new ImageIcon(codebase));
 
		contentPane.setLayout(new FlowLayout());
		contentPane.add(label);
	}
 
	public static void main(String args[]) {
		final JFrame f = new JFrame();
		JApplet applet = new Test3();
 
		applet.init();
 
		f.setContentPane(applet.getContentPane());
		f.setBounds(100, 100, 308, 199);
		f.setTitle("An Application");
		f.setVisible(true);
 
		f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
 
		f.addWindowListener(new WindowAdapter() {
			public void windowClosed(WindowEvent e) {
				System.exit(0);
			}
		});
	}
}

how to read a url

September 1st, 2009
String s = request.getRequestURL().toString();
URL url = new URL(s);
BufferedReader bf = new BufferedReader(new InputStreamReader(url.openStream()));

use kill with awk

August 27th, 2009

kill `ps -ef | awk ‘{if($11~/WorkOrderProcessor/) print$2}’`

VI command - D & x

August 10th, 2009

D

The D command deletes from the cursor position to the end of the line. (D is a shortcut for d$.)

x

Often you want to delete only one or two characters. Just as r is a special change command to replace a single character, x is a special delete command to delete a single character. x deletes only the character the cursor is on.

VI command - dw&dd

August 9th, 2009

dw

dw deletes a word beginning where the cursor is positioned. Notice that the space following the word is deleted.

dd

The dd command deletes the entire line that the cursor is on. dd will not delete part of a line. Like its complement, cc, dd is a special command.

VI command - (~)

August 5th, 2009

~

Changing the case of a letter is a special form of replacement. The tilde (~) command will change a lowercase letter to uppercase or an uppercase letter to lowercase. Position the cursor on the letter whose case you want to change, and type a ~. The case of the letter will change, and the cursor will move to the next character.

VI command - r & s

August 4th, 2009

r

One other replacement edit is given by the r command. r replaces a single character with another single character. You do not have to press ESC to return to command mode after making the edit.

s

The S command, as is usually the case with uppercase commands, lets you change whole lines. In contrast to the C command, which changes the rest of the line from the current cursor position, the S command deletes the entire line, no matter where the cursor is. vi puts you in insert mode at the beginning of the line. A preceding count replaces that many lines.

Both s and S put you in insert mode; when you are finished entering new text, press ESC.

VI command - cw&cc

August 3rd, 2009

cw

To change a word, combine the c (change) command with w for word. You can replace a word (cw) with a longer or shorter word (or any amount of text). cw can be thought of as “delete the word marked and insert new text until ESC is pressed.”

cc

To replace the entire current line, use the special change command, cc. cc changes an entire line, replacing that line with any amount of text entered before pressing ESC . It doesn’t matter where the cursor is located on the line; cc replaces the entire line of text.

print diff result

July 15th, 2009

find src|awk ‘{print “diff “$0″ bak/” $0 “>diff/”$0}’|less

how to build .properties

July 2nd, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
if (null == transactionCodeConfig) {
	transactionCodeConfig = new Properties();
	transactionCodeConfig.load(Obj2XMLBuilderXSD.class
			.getResourceAsStream("/config/transactionCodeConfig.properties"));
	xsdMap = new HashMap();
	for (Iterator iterator = transactionCodeConfig.entrySet().iterator(); iterator.hasNext();) {
		Entry entry = (Entry) iterator.next();
		BufferedReader br = new BufferedReader(new InputStreamReader(
				Obj2XMLBuilderXSD.class.getResourceAsStream("/config/xsd/" + entry.getValue())));
		String aLine;
		StringBuffer xsdContent = new StringBuffer("");
		aLine = br.readLine();
		while (null != aLine) {
			xsdContent.append(aLine);
			aLine = br.readLine();
		}
		br.close();
		xsdMap.put(entry.getKey(), xsdContent.toString());
	}
}