给你一些提示,具体的你自己去完成。
public static String toHtmlSpace(String strValue) {
try {
if (strValue == null) return "";
//strValue = new String(strValue.getBytes("ISO8859_1"), "GBK");
strValue = transNullToStr(strValue);
String strTemp = "";
if (strValue.length() != 0) {
char[] c = new char[strValue.length()];
c = strValue.toCharArray();
for (int i = 0; i < c.length; i++) {
if (c[i] == ' ') {
strTemp = strTemp + " ";
} else {
strTemp = strTemp + c[i];
}
}
strValue = strTemp;
}
} catch (Exception Ex) {
}
return strValue;
} public static String transNullToStr (String str) {
try {
if (str == null) {
return "";
} else {
str = str.trim();
return str;
}
} catch (Exception Ex) {
return "";
}
}
public static String toHtmlSpace(String strValue) {
try {
if (strValue == null) return "";
//strValue = new String(strValue.getBytes("ISO8859_1"), "GBK");
strValue = transNullToStr(strValue);
String strTemp = "";
if (strValue.length() != 0) {
char[] c = new char[strValue.length()];
c = strValue.toCharArray();
for (int i = 0; i < c.length; i++) {
if (c[i] == ' ') {
strTemp = strTemp + " ";
} else {
strTemp = strTemp + c[i];
}
}
strValue = strTemp;
}
} catch (Exception Ex) {
}
return strValue;
} public static String transNullToStr (String str) {
try {
if (str == null) {
return "";
} else {
str = str.trim();
return str;
}
} catch (Exception Ex) {
return "";
}
}
String result=new String();
for (int i=0;i<string.length();i++)
{int temp=ch[i];
if(temp>48&&temp<59)
{if(ch[i+1]){for (int j=0;j<Integer.getInteger(string,i);j++)
{result+=ch[i];}
result+="_";
}
else result+=ch[i];
result+="_";}
else
if(ch[i]=="_")
{result+="\UL";}
else
{result+=ch[i];}
result+="_";}
return result;
这是encode()
decode()原理一样自己写吧
有些没看懂。
我试了一会儿,
用Character类应该是可以的。
import java.io.*;public class enCodeTest {
public static void main(String[] args) {
String readIn = "24ab_2t2";
String result = encode(readIn);
System.out.println(result);
} public static String encode(String str) {
String result = "";
char ch = 'a';
int count = 0;
for (int i = 0; i < str.length(); i++) {
try {
ch = str.charAt(i);
int temp = Integer.parseInt("" + ch);
System.out.println("" + count);
if (i == str.length() - 1) { //no char then sample copy
result = result + ch;
result = result;
}
else {
if (count != 0) {
for (int j = 0; j <= count; j++) {
result = result + ch;
}
result = result + "_";
}
count = temp;
}
}
catch (Exception ex) {
if (ch == '_') {
result = result.substring(0, result.length() - 1);
result = result + "\\UL";
result = result + "_";
}
else {
for (int j = 0; j <= count; j++) {
result = result + ch;
}
result = result + "_";
if (count > 0) {
result = result + ch + "_";
}
}
count = 0;
}
}
return result;
} public static String decode(String str) {
return str;
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import misEmployee.*;
import javax.swing.border.*;public class misEployeeFrame
extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanelCtrl = new JPanel();
JButton addButton = new JButton();
JButton check = new JButton();
JPanel jPanelInput = new JPanel();
JTextField addName = new JTextField(8);
JTextField addID = new JTextField(8);
JTextField addGender = new JTextField(8);
JPanel jPanelDisplay = new JPanel();
JTextArea textName = new JTextArea(1, 8);
JTextArea TextID = new JTextArea(1, 8);
JTextArea textGender = new JTextArea(1, 8);
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
TitledBorder titledBorder1;
TitledBorder titledBorder2;
TitledBorder titledBorder3;
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
Component component1;
JLabel jLabel9 = new JLabel(); //Construct the frame
public misEployeeFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} //Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel)this.getContentPane();
titledBorder1 = new TitledBorder("");
titledBorder2 = new TitledBorder("");
titledBorder3 = new TitledBorder("");
component1 = Box.createHorizontalStrut(8);
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 150));
this.setTitle("misEployeeFrame");
addButton.setFont(new java.awt.Font("Dialog", 0, 12));
addButton.setForeground(Color.black);
addButton.setAlignmentX( (float) 0.0);
addButton.setActionCommand("");
addButton.setText("添加成员");
addButton.addActionListener(new misEployeeFrame_addButton_actionAdapter(this));
check.setFont(new java.awt.Font("Dialog", 0, 12));
check.setRolloverEnabled(false);
check.setText("察看");
check.addActionListener(new misEployeeFrame_check_actionAdapter(this));
addName.setText("");
addID.setText("");
addGender.setText(""); jPanelInput.setAlignmentY( (float) 0.5);
jPanelInput.setBorder(BorderFactory.createEtchedBorder());
textName.setEditable(false);
textName.setText("");
TextID.setBackground(Color.white);
TextID.setBorder(BorderFactory.createLineBorder(Color.black));
TextID.setDoubleBuffered(false);
TextID.setText("");
textGender.setDoubleBuffered(false);
textGender.setEditable(false);
textGender.setText("");
jPanelDisplay.setFont(new java.awt.Font("Dialog", 0, 11));
jPanelDisplay.setForeground(Color.black);
jPanelDisplay.setBorder(titledBorder3);
jPanelDisplay.setDoubleBuffered(true);
jPanelDisplay.setMinimumSize(new Dimension(200, 28));
jPanelDisplay.setOpaque(true);
jLabel1.setText("Name:");
jLabel2.setText("ID:");
jLabel3.setText("Gender");
jLabel4.setText("Name:");
jLabel5.setFont(new java.awt.Font("SansSerif", 0, 12));
jLabel5.setText("的成员");
jLabel6.setText("Gender:");
jLabel7.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel7.setMinimumSize(new Dimension(25, 16));
jLabel7.setText("添加:");
jLabel8.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel8.setRequestFocusEnabled(true);
jLabel8.setText("查询:");
jLabel9.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel9.setText("ID为");
jPanelCtrl.setBorder(BorderFactory.createEtchedBorder());
jPanelDisplay.add(jLabel8, null);
jPanelDisplay.add(jLabel4, null);
jPanelDisplay.add(textName, null);
jPanelDisplay.add(jLabel6, null);
jPanelDisplay.add(textGender, null);
jPanelDisplay.add(component1, null);
jPanelCtrl.add(addButton, null);
jPanelCtrl.add(check, null);
jPanelCtrl.add(jLabel9, null);
jPanelCtrl.add(TextID, null);
jPanelCtrl.add(jLabel5, null);
contentPane.add(jPanelInput, BorderLayout.NORTH);
jPanelInput.add(jLabel7, null);
jPanelInput.add(jLabel1, null);
jPanelInput.add(addName, null);
jPanelInput.add(jLabel2, null);
jPanelInput.add(addID, null);
jPanelInput.add(jLabel3, null);
jPanelInput.add(addGender, null);
contentPane.add(jPanelCtrl, BorderLayout.SOUTH);
contentPane.add(jPanelDisplay, BorderLayout.CENTER);
} //Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
} void addButton_actionPerformed(ActionEvent e) {
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
"employee_obj.ser"));
Employee[] newStaff = (Employee[]) in.readObject();
in.close(); Employee one = new Employee(addName.getText(),
Integer.parseInt(addID.getText()),
addGender.getText());
newStaff[Integer.parseInt(addID.getText())] = one; ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
"employee_obj.ser"));
out.writeObject(newStaff);
out.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
addName.setText(""); addID.setText(""); addGender.setText("");
} void check_actionPerformed(ActionEvent e) {
String n = null;
String g = null;
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
"employee_obj.ser"));
Employee[] newStaff = (Employee[]) in.readObject();
n = newStaff[Integer.parseInt(TextID.getText())].getName();
g = newStaff[Integer.parseInt(TextID.getText())].getGender();
if (n == null) {
n = "查无此人";
}
if (g == null) {
g = n;
}
in.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
textName.setText(n);
textGender.setText(g);
}}class misEployeeFrame_addButton_actionAdapter
implements java.awt.event.ActionListener {
misEployeeFrame adaptee; misEployeeFrame_addButton_actionAdapter(misEployeeFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.addButton_actionPerformed(e);
}
}class misEployeeFrame_check_actionAdapter
implements java.awt.event.ActionListener {
misEployeeFrame adaptee; misEployeeFrame_check_actionAdapter(misEployeeFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.check_actionPerformed(e);
}
}
public static String encode(String str) {
String result = "";
char ch = 'a';
int count = 0;
for (int i = 0; i < str.length(); i++) {
try {
ch = str.charAt(i);
int temp = Integer.parseInt("" + ch);
if (i == str.length() - 1) { //no char then sample copy
result = result + ch;
result = result;
}
else {
if (count != 0) {
for (int j = 0; j <= count; j++) {
result = result + ch;
}
result = result + "_";
}
count = temp;
}
}
catch (Exception ex) {
if (ch == '_') {
if (!result.equals("")) {
result = result.substring(0, result.length() - 1);
}
result = result + "\\UL";
result = result + "_";
}
else {
for (int j = 0; j <= count; j++) {
result = result + ch;
}
result = result + "_";
if (count > 0) {
result = result + ch + "_";
}
count = 0;
} }
}
return result;
}
也谢谢其他XD的帮忙
我手头过几天可能有一个GIS系统的小活,哪位高手有时间干的话可以留言
注:
要用到ORACLE下的spatial data
你JAVA到什么程度啊,你说个正确的定位,我推荐你几个地方。
每天都有进步就可以。你看看Servlet和JSP的
你打63906340,你就说你懂JAVA尤其是Servlet和JSP、CSS看他们还招不招。
有考试的啊,做好准备啊
到时候再找你:)
我已经再MSN上加你了