#
下一个步骤是找出程序中对于旧函数的所有引用(reference)点,并修改它们,让它们改用新函数. 下面是原本的程序:
class Customer...
public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Enumeration rentals = _rentals.elements();
String result = "Rental Record for * " + getName() + "\n";
while(rentals.hasMoreElements()) {
double thisAmount = 0;
Rental each = (Rental)rentals.nextElement(); //取得一笔租借记录
thisAmount = amountFor(each);
// add frequent renter points(累加常客积点)
frequentRenterPoints ++;
if((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) &&
each.getDaysRented() > 1)
frequentRenterPoints ++;
result += "\t" + each.getMovie().getTitle() + "\t" +
String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}
// add footer lines(结尾打印)
result += "Amount owed is " + String.valueOf(totalAmount) + " \n";
result += "You earned " + String.valueOf(frequentRenterPoints) +
"frequent renter points";
return result;
}
本例之中,这个步骤很简单,因为我才刚刚产生新函数,只有一个地方使用了它.一般情况下你得在可能运用该函数的所有classes中查找一遍.
class Customer
public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Enumeration rentals = _rentals.elements();
String result = "Rental Record for * " + getName() + "\n";
while(rentals.hasMoreElements()) {
double thisAmount = 0;
Rental each = (Rental)rentals.nextElement(); //取得一笔租借记录
thisAmount = each.getCharge();
// add frequent renter points(累加常客积点)
frequentRenterPoints ++;
if((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) &&
each.getDaysRented() > 1)
frequentRenterPoints ++;
result += "\t" + each.getMovie().getTitle() + "\t" +
String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}
// add footer lines(结尾打印)
result += "Amount owed is " + String.valueOf(totalAmount) + " \n";
result += "You earned " + String.valueOf(frequentRenterPoints) +
"frequent renter points";
return result;
}
搬移[金额计算]代码
观察amountFor()时,我发现这个函数使用了来自Rental class的信息,却没有使用来自Customer class的信息.
class Customer...
public double amountFor(Rental aRental) {
double result = 0;
switch(aRental.getMovie().getPriceCode()) { //取得影片出租价格
case Movie.REGULAR: //普通片
result+= 2;
if(aRental.getDaysRented() > 2)
result+= (aRental.getDaysRented() - 2) * 1.5;
break;
case Movie.NEW_RELEASE: //新片
result+= aRental.getDaysRented() * 3;
break;
case Movie.CHILDRENS: //儿童片
result+= 1.5;
if(aRental.getDaysRented() > 3)
result+= (aRental.getDaysRented() - 3) * 1.5;
break;
}
return result;
}
这立刻使我怀疑它是否被放错了位置.大多数情况下,函数应该放在它使用的数据的所属object(或说class)内,所以amountFor()应该移
到Rental class去.为了这么做,我要运用Move Method(142).首先把代码拷贝到Rental
class内,调整代码使之适应新家,然后重新编译.下面这样:
class Rental...
double getCharge() {
double result = 0;
switch(getMovie().getPriceCode()) { //取得影片出租价格
case Movie.REGULAR: //普通片
result+= 2;
if(getDaysRented() > 2)
result+= (getDaysRented() - 2) * 1.5;
break;
case Movie.NEW_RELEASE: //新片
result+= getDaysRented() * 3;
break;
case Movie.CHILDRENS: //儿童片
result+= 1.5;
if(getDaysRented() > 3)
result+= (getDaysRented() - 3) * 1.5;
break;
}
return result;
}
这个例子里,[适应新家]意味去掉参数.此外,我还要在搬移的同时变更函数名称.
现在我可以测试新函数是否正常工作.只要改变Customer.amountFor()函数内容,使它委托(delegate)新函数即可:
class Customer...
private double amountFor(Rental aRental) {
return aRental.getCharge();
}
实例代码:
public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Enumeration rentals = _rentals.elements();
String result = "Rental Record for * " + getName() + "\n";
while(rentals.hasMoreElements()) {
double thisAmount = 0;
Rental each = (Rental)rentals.nextElement(); //取得一笔租借记录
switch(each.getMovie().getPriceCode()) { //取得影片出租价格
case Movie.REGULAR: //普通片
thisAmount += 2;
if(each.getDaysRented() > 2)
thisAmount += (each.getDaysRented() - 2) * 1.5;
break;
case Movie.NEW_RELEASE: //新片
thisAmount += each.getDaysRented() * 3;
break;
case Movie.CHILDRENS: //儿童片
thisAmount += 1.5;
if(each.getDaysRented() > 3)
thisAmount += (each.getDaysRented() - 3) * 1.5;
break;
}
// add frequent renter points(累加常客积点)
frequentRenterPoints ++;
if((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) &&
each.getDaysRented() > 1)
frequentRenterPoints ++;
result += "\t" + each.getMovie().getTitle() + "\t" +
String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}
// add footer lines(结尾打印)
result += "Amount owed is " + String.valueOf(totalAmount) + " \n";
result += "You earned " + String.valueOf(frequentRenterPoints) +
"frequent renter points";
return result;
}
第一步骤是找出代码的逻辑泥团并运用Extract Method(110).本例一个明显的逻辑泥团就是switch语句,把它提炼(extract)到独立函数中似乎比较好.
首先我得在这段代码里头找出函数内的局部变量(local
variables)和参数(parameters).我找到了两个:each和thisAmount,前者并未被修改,后者会被修改.任何不会被修改的
变量都可以被我当成参数传入新的函数,至于会被修改的变量就需格外小心.如果只有一个变量会被修改,我可以把它当作返回值.thisAmount是个临时
变量,其值在每次循环起始处被设为0,并且在switch语句之前不会改变,所以我可以把新函数的返回值赋予它.
public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Enumeration rentals = _rentals.elements();
String result = "Rental Record for * " + getName() + "\n";
while(rentals.hasMoreElements()) {
double thisAmount = 0;
Rental each = (Rental)rentals.nextElement(); //取得一笔租借记录
thisAmount = amountFor(each);
// add frequent renter points(累加常客积点)
frequentRenterPoints ++;
if((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) &&
each.getDaysRented() > 1)
frequentRenterPoints ++;
result += "\t" + each.getMovie().getTitle() + "\t" +
String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}
// add footer lines(结尾打印)
result += "Amount owed is " + String.valueOf(totalAmount) + " \n";
result += "You earned " + String.valueOf(frequentRenterPoints) +
"frequent renter points";
return result;
}
public double amountFor(Rental each) {
double thisAmount = 0;
switch(each.getMovie().getPriceCode()) { //取得影片出租价格
case Movie.REGULAR: //普通片
thisAmount += 2;
if(each.getDaysRented() > 2)
thisAmount += (each.getDaysRented() - 2) * 1.5;
break;
case Movie.NEW_RELEASE: //新片
thisAmount += each.getDaysRented() * 3;
break;
case Movie.CHILDRENS: //儿童片
thisAmount += 1.5;
if(each.getDaysRented() > 3)
thisAmount += (each.getDaysRented() - 3) * 1.5;
break;
}
return thisAmount;
}
现在,已经把原本的函数分为两块,可以分别处理它们.我不喜欢amountFor()内的某些变量名称,现在是修改它们的时候.
下面是原本的代码:
public double amountFor(Rental each) {
double thisAmount = 0;
switch(each.getMovie().getPriceCode()) { //取得影片出租价格
case Movie.REGULAR: //普通片
thisAmount += 2;
if(each.getDaysRented() > 2)
thisAmount += (each.getDaysRented() - 2) * 1.5;
break;
case Movie.NEW_RELEASE: //新片
thisAmount += each.getDaysRented() * 3;
break;
case Movie.CHILDRENS: //儿童片
thisAmount += 1.5;
if(each.getDaysRented() > 3)
thisAmount += (each.getDaysRented() - 3) * 1.5;
break;
}
return thisAmount;
}
下面是易名后的代码:
public double amountFor(Rental aRental) {
double result = 0;
switch(aRental.getMovie().getPriceCode()) { //取得影片出租价格
case Movie.REGULAR: //普通片
result += 2;
if(aRental.getDaysRented() > 2)
result += (aRental.getDaysRented() - 2) * 1.5;
break;
case Movie.NEW_RELEASE: //新片
result += aRental.getDaysRented() * 3;
break;
case Movie.CHILDRENS: //儿童片
result += 1.5;
if(aRental.getDaysRented() > 3)
result += (aRental.getDaysRented() - 3) * 1.5;
break;
}
return result;
}
1.逻辑泥团(logical clump),这里是指类似下面的逻辑混在一起的代码:
...
switch(each.getMovie().getPriceCode()) {
case Movie.REGULAR:
thisAmount += 2;
.....
case Movie.CHILDRENDS:
thisAmount += 1.5;
if(each.getDaysRented() > 3)
thisAmount += (each.getDaysRented() - 3)*1.5;
break;
}
...
2.重构名录(refactoring catalog)是指常用的重构方法列出的名录.
快速而随性地(quick and dirty)地设计一个简单的程序并没有错.
1.首先,把windows的simsun.ttc文件考到指定目录,重命名为simsun.ttf.
2.注册字体:到JAVA_HOME下的jre/lib/fonts下.编辑fonts.dir.具体如下:第一行的数字加一.在最后一行加入一句:
simsun.ttf -default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
可选字体的还有:
simsun.ttf -SungtiL GB-medium-r-normal--0-0-0-0-c-0-gb2312.1988-0
simsun.ttf
-misc-SimSun-medium-r-normal--*-%d-*-*-c-*-iso10646-1
3.修改JAVA_HOME下的jre/lib/的font.properties文件(这里的font.properties文件最好做备份). ($cp -v font.properties.zh_CN.Sun font.properties)
修改的地方有三处:
A.类似如下的 serif.0=-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1
serif.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0
看到xxxx.1=后面的字体全部改成已经注册的字体.
B.类似如下的 fontset.serif.plain=\
-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0
fontset.serif.plain=\后的第二行字体全部改成注册的字体.
C.最后一行:appendedfontpath=/usr/share/fonts/truetype.这里的/usr/share/fonts/truetype是simsun.ttf的考到的目录名.
具体文件如下:
# @(#)font.properties.zh_CN.Sun.linux 1.1 03/07/14
# Copyright 2003 Sun Microsystems, Inc. All rights reserved.
#
# Component Font Mappings For Linux zh_CN
#
serif.0=-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1
serif.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
serif.italic.0=-b&h-lucidabright-medium-i-normal--*-%d-*-*-p-*-iso8859-1
serif.italic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
serif.bold.0=-b&h-lucidabright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1
serif.bold.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
serif.bolditalic.0=-b&h-lucidabright-demibold-i-normal--*-%d-*-*-p-*-iso8859-1
serif.bolditalic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
sansserif.0=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
sansserif.italic.0=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.italic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
sansserif.bold.0=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bold.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
sansserif.bolditalic.0=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bolditalic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
monospaced.0=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
monospaced.italic.0=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.italic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
monospaced.bold.0=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bold.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
monospaced.bolditalic.0=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bolditalic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
dialog.0=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
dialog.italic.0=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.italic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
dialog.bold.0=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bold.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
dialog.bolditalic.0=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bolditalic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
dialoginput.0=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
dialoginput.italic.0=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.italic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
dialoginput.bold.0=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bold.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
dialoginput.bolditalic.0=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bolditalic.1=-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
# Missing Glyph Character
#
default.char=274f
# Component Font Character Encodings
#
fontcharset.serif.0=sun.io.CharToByteISO8859_1
fontcharset.serif.1=sun.io.CharToByteGBK
fontcharset.sansserif.0=sun.io.CharToByteISO8859_1
fontcharset.sansserif.1=sun.io.CharToByteGBK
fontcharset.monospaced.0=sun.io.CharToByteISO8859_1
fontcharset.monospaced.1=sun.io.CharToByteGBK
fontcharset.dialog.0=sun.io.CharToByteISO8859_1
fontcharset.dialog.1=sun.io.CharToByteGBK
fontcharset.dialoginput.0=sun.io.CharToByteISO8859_1
fontcharset.dialoginput.1=sun.io.CharToByteGBK
# Exclusion Ranges
#
# XFontSet Information
#
fontset.serif.plain=\
-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.serif.italic=\
-b&h-lucidabright-medium-i-normal--*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.serif.bold=\
-b&h-lucidabright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.serif.bolditalic=\
-b&h-lucidabright-demibold-i-normal--*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.sansserif.plain=\
-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.sansserif.italic=\
-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.sansserif.bold=\
-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.sansserif.bolditalic=\
-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.monospaced.plain=\
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.monospaced.italic=\
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.monospaced.bold=\
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.monospaced.bolditalic=\
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.dialog.italic=\
-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.dialog.bold=\
-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.dialog.bolditalic=\
-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.dialog.plain=\
-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.dialoginput.italic=\
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.dialoginput.bold=\
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.dialoginput.bolditalic=\
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.dialoginput.plain=\
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
fontset.default=\
-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1,\
-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.
filename.-default-simsun-medium-r-normal--*-100-*-*-c-*-gb2312.1980-0.=/usr/share/fonts/truetype/simsun.ttf
appendedfontpath=/usr/share/fonts/truetype
public class ReaderInputStream extends InputStream {
protected Reader reader;
protected ByteArrayOutputStream byteArrayOut;
protected Writer writer;
protected char[] chars;
protected byte[] buffer;
protected int index, length;
/**
* 带Reader参数构造函数
*
* @param reader - InputStream使用的Reader
*/
public ReaderInputStream(Reader reader) {
this.reader = reader;
byteArrayOut = new ByteArrayOutputStream();
writer = new OutputStreamWriter(byteArrayOut);
chars = new char[1024];
}
/**
* 带Reader和字符编码格式参数的构造函数
*
* @param reader - InputStream使用的Reader
* @param encoding - InputStream使用的字符编码格式.
* @throws 如果字符编码格式不支持,则抛UnsupportedEncodingException异常
*/
public ReaderInputStream(Reader reader, String encoding)
throws UnsupportedEncodingException {
this.reader = reader;
byteArrayOut = new ByteArrayOutputStream();
writer = new OutputStreamWriter(byteArrayOut, encoding);
chars = new char[1024];
}
/**
* @see java.io.InputStream#read()
*/
public int read() throws IOException {
if (index >= length)
fillBuffer();
if (index >= length)
return -1;
return 0xff & buffer[index++];
}
protected void fillBuffer() throws IOException {
if (length < 0)
return;
int numChars = reader.read(chars);
if (numChars < 0) {
length = -1;
} else {
byteArrayOut.reset();
writer.write(chars, 0, numChars);
writer.flush();
buffer = byteArrayOut.toByteArray();
length = buffer.length;
index = 0;
}
}
/**
* @see java.io.InputStream#read(byte[], int, int)
*/
public int read(byte[] data, int off, int len) throws IOException {
if (index >= length)
fillBuffer();
if (index >= length)
return -1;
int amount = Math.min(len, length - index);
System.arraycopy(buffer, index, data, off, amount);
index += amount;
return amount;
}
/**
* @see java.io.InputStream#available()
*/
public int available() throws IOException {
return (index < length) ? length - index :
((length >= 0) && reader.ready()) ? 1 : 0;
}
/**
* @see java.io.InputStream#close()
*/
public void close() throws IOException {
reader.close();
}
}
1. 启动emacs.
2.打开jde-mode方式.
3.在打开jde-abbrev-mode方式.
然后输入if,接着按空格键(输入if的条件);展开if语句.
if(i == 0) {
} // end of if (i == 0)
表 1. Abbreviations 语句 | Abbreviation |
---|
if-then | if | else | else | if-then-else | ife | else-if | eif | while | while | for | for | for (int
I=0;I<UL;I++) | fori | for (Iterator i = c.iterator();
i.hasNext();) | foriter | main method | main | switch | switch | case | case | try | try | catch | catch | try finally | tryf | finally | finally |
首先,需打开jde模式.(M-x jde-mode)
在JDEE里注册一个新的jdk:
打开emacs. 输入 M-x customize-variable 并回车. Emacs 提示你要自定义的变量名. 输入 jde-jdk-registry 并回车. jde-jdk-registry 的配置界面. 按 INS 按钮. 显示 JDK 项. 输入JDK的版本号 和 JDK 的安装路径. 重复先前的步骤. 按 State 按钮. State 菜单显示. 选择 Save for Future Sessions . NoteThis saves the setting of jde-jdk-registry
in your .emacs file. 按 Finish button保存.
选择 JDK: 输入 M-x customize-variable 并回车.
Emacs 提示你要自定义的变量. 输入 jde-jdk 并回车. jde-jdk 的配置界面. 缓冲区里显示注册的jdk的列表. 按radio button 选择你要使用的jdk. 按State 按钮. State 菜单显示. 选择 Save for Future Sessions. 按 Finish 按钮 保存设置.
我的java是jre1.4.2的.
首先是进入firefox的插件目录.我的是~/.mozilla/plugins.
然后是确定jre的插件目录.我的是~/programs/j2sdk1.4.2_08/jre/plugin/i386/ns610-gcc32.这里是使用gcc32的系统.
最后是做连接.具体如下:
$cd ~/.mozilla/plugins
$ln -s ~/programs/j2sdk1.4.2_08/jre/plugin/i386/ns610-gcc32/libjavaplugin_oji.so
重起firefox,确定插件是否安装成功.在firefox输入about:plugins.有就成功了.
|