Tomcat 4/JSP Getting Started
Catalina Servlet engine with the emergence of so-called Tomcat fourth enhance its performance, makes it a worthy of consideration Servlet / JSP container. However, can help you begin to understand the document Tomcat resources are few, only a few books, but also in Jakarta some of the information on the Web site is not very clear.
Let us step by step understanding of the installation process Tomcat, and then discuss the use of some of the functions of Tomcat 4/JSP to construct Web applications.
What is the Tomcat?
Tomcat is an open-source operating servlet and JSP Web application software is Java-based Web application software containers. Apache Tomcat from Jakarta sub-supported by the open source code from the Java community volunteers for maintenance. Tomcat Server servlet and JSP is based on the implementation of the norms, we can say Tomcat Server also introduced Apache-Jakarta standards than most commercial applications and the server software is better.
Installation of Tomcat 4
To start using Tomcat 4, you at least want to download Java Development Kit (JDK) version 1.2 and Tomcat 4 install They are ZIP files and the Windows installation data packets. Once you have installed these two data packets, you must add two environment variables: JAVA_HOME and TOMCAT_HOME. JDK will be installed in JAVA_HOME directory, and Tomcat TOMCAT_HOME 4 will be installed in the directory.
If it is installed through the Windows installation procedures, then you can use the menu option to start Tomcat, or open up a command prompt window, entered TOMCAT_HOME \ bin directory, run startup.bat / sh document. Then open a browser and enter the URL http://localhost:8080. Tomcat the default pages will appear in your eyes.
Web applications primer
Before we proceed, we have to look at a Web application software includes components. Java Servlet specification Web application software defined as servlets, HTML pages, and other categories from a number of marketing in the number of containers on the resources tied up and run a set. In Tomcat, these resources have been placed in the TOMCAT_HOME \ webapps folder following a special directory structure. For a sample Web application software (myapp), the directory structure is this:
TOMCAT_HOME \ webapps \ myapp \ WEB-INF \ classes \ lib
Myapp directory is regarded as Web application's root directory, all the JSP, HTML, JavaScript documents and other resources are located in the directory under. WEB-INF directory contains application software used by the resources, but the WEB-INF not in the public file in the root directory. In this directory contained in the document can not be asked by the client visit. Directory category (under WEB-INF) contains the necessary operation myapp servlets, beans and utility category. In some cases (log4j), attributes documents were placed in the category of the directory. Lib directory (under WEB-INF) includes Java archive files (JARs), such as JDBC driver or tag library, which is myapp rely on. If a class appears in the JAR file and in the category of the directory, type loader will be recorded in that category in a directory.
Java source code Gobang network (1)
Java source code Gobang network (1)
[Source: CSDN hits: 555 Author: NA]
Below the source code is divided into four documents;
ChessClient.java: Client main program.
ChessInterface.java: Client interface.
ChessPad.java: the drawing board.
ChessServer.java: server-side.
Can accommodate 50 people at the same time online playing chess, chatting.
Notes with no detail, but can definitely run through j2sdk1.4.
/************************************************* The following
1.chessClient.java
************************************************** ********************************************/
Import java.awt .*;
Import java.awt.event .*;
Import java.io. *;
Import java.net .*;
Import java.util .*;
Class clientThread extends Thread
(
ChessClient chessclient;
ClientThread (chessClient chessclient)
(
This.chessclient = chessclient;
)
Public void acceptMessage (String recMessage)
(
If (recMessage.startsWith ( "/ userlist"))
(
StringTokenizer userToken = new StringTokenizer (recMessage, "");
Int userNumber = 0;
Chessclient.userpad.userList.removeAll ();
Chessclient.inputpad.userChoice.removeAll ();
Chessclient.inputpad.userChoice.addItem ( "all");
While (userToken.hasMoreTokens ())
(
String user = (String) userToken.nextToken ( "");
If (userNumber> 0 & &! User.startsWith ( "[inchess]"))
(
Chessclient.userpad.userList.add (user);
Chessclient.inputpad.userChoice.addItem (user);
)
UserNumber + +;
)
Chessclient.inputpad.userChoice.select ( "all");
)
Else if (recMessage.startsWith ( "/ yourname"))
(
Chessclient.chessClientName = recMessage.substring (10);
Chessclient.setTitle ( "Java client Gobang" + "ID:" + chessclient.chessClientName);
)
Else if (recMessage.equals ( "/ reject"))
(
Try
(
Chessclient.chesspad.statusText.setText ( "can not join the game");
Chessclient.controlpad.cancelGameButton.setEnabled (false);
Chessclient.controlpad.joinGameButton.setEnabled (true);
Chessclient.controlpad.creatGameButton.setEnabled (true);
)
Catch (Exception ef)
(
Chessclient.chatpad.chatLineArea.setText ( "chessclient.chesspad.chessSocket.close not closed");
)
Chessclient.controlpad.joinGameButton.setEnabled (true);
)
Else if (recMessage.startsWith ( "/ peer"))
(
Chessclient.chesspad.chessPeerName = recMessage.substring (6);
If (chessclient.isServer)
(
Chessclient.chesspad.chessColor = 1;
Chessclient.chesspad.isMouseEnabled = true;
Chessclient.chesspad.statusText.setText ( "Please Heiji 13361");
)
Else if (chessclient.isClient)
(
Chessclient.chesspad.chessColor =- 1;
Chessclient.chesspad.statusText.setText ( "have joined the games, waiting for the other 13361 …");
)
)
Else if (recMessage.equals ( "/ youwin"))
(
Chessclient.isOnChess = false;
Chessclient.chesspad.chessVictory (chessclient.chesspad.chessColor);
Chessclient.chesspad.statusText.setText ( "each other out, please give up the game from connecting points");
Chessclient.chesspad.isMouseEnabled = false;
)
Else if (recMessage.equals ( "/ OK"))
(
Chessclient.chesspad.statusText.setText ( "Creating successful game, waiting for others to join …");
)
Else if (recMessage.equals ( "/ error"))
(
Chessclient.chatpad.chatLineArea.append ( "transmission error: Please withdraw from the process, to re-enter \ n");
)
Else
(
Chessclient.chatpad.chatLineArea.append (recMessage + "\ n");
Chessclient.chatpad.chatLineArea.setCaretPosition (
Chessclient.chatpad.chatLineArea.getText (). Length ());
)
)
Public void run ()
(
String message = "";
Try
(
While (true)
(
Chessclient.in.readUTF message = ();
AcceptMessage (message);
)
)
Catch (IOException es)
(
)
)
)
Public class chessClient extends Frame implements ActionListener, KeyListener
(
UserPad userpad = new userPad ();
ChatPad chatpad = new chatPad ();
ControlPad controlpad = new controlPad ();
ChessPad chesspad = new chessPad ();
InputPad inputpad = new inputPad ();
Socket chatSocket;
DataInputStream in;
DataOutputStream out;
String chessClientName = null;
String host = null;
Int port = 4331;
Boolean isOnChat = false; / / chatting?
Boolean isOnChess = false; / / chess?
Boolean isGameConnected = false; / / chess the client?
Boolean isServer = false; / / If this is a chess game console
Boolean isClient = false; / / If the client is a chess game
Panel southPanel = new Panel ();
Panel northPanel = new Panel ();
Panel centerPanel = new Panel ();
Panel westPanel = new Panel ();
Panel eastPanel = new Panel ();
ChessClient ()
(
Super ( "Gobang Java Client");
SetLayout (new BorderLayout ());
Host = controlpad.inputIP.getText ();
WestPanel.setLayout (new BorderLayout ());
WestPanel.add (userpad, BorderLayout.NORTH);
WestPanel.add (chatpad, BorderLayout.CENTER);
WestPanel.setBackground (Color.pink);
Inputpad.inputWords.addKeyListener (this);
Chesspad.host = controlpad.inputIP.getText ();
CenterPanel.add (chesspad, BorderLayout.CENTER);
CenterPanel.add (inputpad, BorderLayout.SOUTH);
CenterPanel.setBackground (Color.pink);
Controlpad.connectButton.addActionListener (this);
Controlpad.creatGameButton.addActionListener (this);
Controlpad.joinGameButton.addActionListener (this);
Controlpad.cancelGameButton.addActionListener (this);
Controlpad.exitGameButton.addActionListener (this);
Controlpad.creatGameButton.setEnabled (false);
Controlpad.joinGameButton.setEnabled (false);
Controlpad.cancelGameButton.setEnabled (false);
SouthPanel.add (controlpad, BorderLayout.CENTER);
SouthPanel.setBackground (Color.pink);
AddWindowListener (new WindowAdapter ()
(
Public void windowClosing (WindowEvent e)
(
If (isOnChat)
(
Try
(
ChatSocket.close ();
)
Catch (Exception ed)
(
)
)
If (isOnChess | | isGameConnected)
(
Try
(
Chesspad.chessSocket.close ();
)
Catch (Exception ee)
(
)
)
System.exit (0);
)
Public void windowActivated (WindowEvent ea)
(
)
));
Add (westPanel, BorderLayout.WEST);
Add (centerPanel, BorderLayout.CENTER);
Add (southPanel, BorderLayout.SOUTH);
Pack ();
SetSize (670,548);
SetVisible (true);
SetResizable (false);
Validate ();
)
Public boolean connectServer (String serverIP, int serverPort) throws Exception
(
Try
(
ChatSocket = new Socket (serverIP, serverPort);
In = new DataInputStream (chatSocket.getInputStream ());
Out = new DataOutputStream (chatSocket.getOutputStream ());
ClientThread clientthread = new clientThread (this);
Clientthread.start ();
IsOnChat = true;
Return true;
)
Catch (IOException ex)
(
Chatpad.chatLineArea.setText ( "chessClient: connectServer: unable to connect the proposed restart procedures \ n");
)
Return false;
)
Public void actionPerformed (ActionEvent e)
(
If (e.getSource () == controlpad.connectButton)
(
Host = = chesspad.host controlpad.inputIP.getText ();
Try
(
If (connectServer (host, port))
(
Chatpad.chatLineArea.setText ("");
Controlpad.connectButton.setEnabled (false);
Controlpad.creatGameButton.setEnabled (true);
Controlpad.joinGameButton.setEnabled (true);
Chesspad.statusText.setText ( "a successful connection, create a game or join the game");
)
)
Catch (Exception ei)
(
Chatpad.chatLineArea.setText ( "controlpad.connectButton: unable to connect the proposed restart procedures \ n");
)
)
If (e.getSource () == controlpad.exitGameButton)
(
If (isOnChat)
(
Try
(
ChatSocket.close ();
)
Catch (Exception ed)
(
)
)
If (isOnChess | | isGameConnected)
(
Try
(
Chesspad.chessSocket.close ();
)
Catch (Exception ee)
(
)
)
System.exit (0);
)
If (e.getSource () == controlpad.joinGameButton)
(
String selectedUser = userpad.userList.getSelectedItem ();
If (selectedUser == null | | selectedUser.startsWith ( "[inchess]") | |
SelectedUser.equals (chessClientName))
(
Chesspad.statusText.setText ( "must first select an effective user");
)
Else
(
Try
(
If (! IsGameConnected)
(
If (chesspad.connectServer (chesspad.host, chesspad.port))
(
IsGameConnected = true;
IsOnChess = true;
IsClient = true;
Controlpad.creatGameButton.setEnabled (false);
Controlpad.joinGameButton.setEnabled (false);
Controlpad.cancelGameButton.setEnabled (true);
Chesspad.chessthread.sendMessage ( "/ joingame" userpad.userList.getSelectedItem + () + "" + chessClientName);
)
)
Else
(
IsOnChess = true;
IsClient = true;
Controlpad.creatGameButton.setEnabled (false);
Controlpad.joinGameButton.setEnabled (false);
Controlpad.cancelGameButton.setEnabled (true);
Chesspad.chessthread.sendMessage ( "/ joingame" userpad.userList.getSelectedItem + () + "" + chessClientName);
)
)
Catch (Exception ee)
(
IsGameConnected = false;
IsOnChess = false;
IsClient = false;
Controlpad.creatGameButton.setEnabled (true);
Controlpad.joinGameButton.setEnabled (true);
Controlpad.cancelGameButton.setEnabled (false);
Chatpad.chatLineArea.setText ( "chesspad.connectServer can not connect \ n" + ee);
)
)
)
If (e.getSource () == controlpad.creatGameButton)
(
Try
(
If (! IsGameConnected)
(
If (chesspad.connectServer (chesspad.host, chesspad.port))
(
IsGameConnected = true;
IsOnChess = true;
IsServer = true;
Controlpad.creatGameButton.setEnabled (false);
Controlpad.joinGameButton.setEnabled (false);
Controlpad.cancelGameButton.setEnabled (true);
Chesspad.chessthread.sendMessage ( "/ creatgame" + "[inchess]" + chessClientName);
)
)
Else
(
IsOnChess = true;
IsServer = true;
Controlpad.creatGameButton.setEnabled (false);
Controlpad.joinGameButton.setEnabled (false);
Controlpad.cancelGameButton.setEnabled (true);
Chesspad.chessthread.sendMessage ( "/ creatgame" + "[inchess]" + chessClientName);
)
)
Catch (Exception ec)
(
IsGameConnected = false;
IsOnChess = false;
IsServer = false;
Controlpad.creatGameButton.setEnabled (true);
Controlpad.joinGameButton.setEnabled (true);
Controlpad.cancelGameButton.setEnabled (false);
Ec.printStackTrace ();
Chatpad.chatLineArea.setText ( "chesspad.connectServer can not connect \ n" + ec);
)
)
If (e.getSource () == controlpad.cancelGameButton)
(
If (isOnChess)
(
Chesspad.chessthread.sendMessage ( "/ giveup" + chessClientName);
Chesspad.chessVictory (-1 * chesspad.chessColor);
Controlpad.creatGameButton.setEnabled (true);
Controlpad.joinGameButton.setEnabled (true);
Controlpad.cancelGameButton.setEnabled (false);
Chesspad.statusText.setText ( "create a game or join the game");
)
If (! IsOnChess)
(
Controlpad.creatGameButton.setEnabled (true);
Controlpad.joinGameButton.setEnabled (true);
Controlpad.cancelGameButton.setEnabled (false);
Chesspad.statusText.setText ( "create a game or join the game");
)
IsServer isClient = = false;
)
)
Public void keyPressed (KeyEvent e)
(
TextField inputWords = (TextField) e.getSource ();
If (e.getKeyCode () == KeyEvent.VK_ENTER)
(
If (inputpad.userChoice.getSelectedItem (). Equals ( "all"))
(
Try
(
Out.writeUTF (inputWords.getText ());
InputWords.setText ("");
)
Catch (Exception ea)
(
Chatpad.chatLineArea.setText ( "chessClient: KeyPressed unable to connect, to re-connect \ n");
Userpad.userList.removeAll ();
Inputpad.userChoice.removeAll ();
InputWords.setText ("");
Controlpad.connectButton.setEnabled (true);
)
)
Else
(
Try
(
Out.writeUTF ("/"+ inputpad.userChoice.getSelectedItem () + "" + inputWords.getText ());
InputWords.setText ("");
)
Catch (Exception ea)
(
Chatpad.chatLineArea.setText ( "chessClient: KeyPressed unable to connect, to re-connect \ n");
Userpad.userList.removeAll ();
Inputpad.userChoice.removeAll ();
InputWords.setText ("");
Controlpad.connectButton.setEnabled (true);
)
)
)
)
Public void keyTyped (KeyEvent e)
(
)
Public void keyReleased (KeyEvent e)
(
)
Public static void main (String args [])
(
ChessClient chessClient = new chessClient ();
)
)
/************************************************* Attachments
Below are: chessInteface.java
************************************************** ****************************************/
Import java.awt .*;
Import java.awt.event .*;
Import java.io. *;
Import java.net .*;
Class userPad extends Panel
(
List userList = new List (10);
UserPad ()
(
SetLayout (new BorderLayout ());
For (int i = 0; i <50; i + +)
(
UserList.add (i +"."+" without user ");
)
Add (userList, BorderLayout.CENTER);
)
)
Class chatPad extends Panel
(
TextArea chatLineArea = new TextArea ( "", 18, 30, TextArea.SCROLLBARS_VERTICAL_ONLY);
ChatPad ()
(
SetLayout (new BorderLayout ());
Add (chatLineArea, BorderLayout.CENTER);
)
)
Class controlPad extends Panel
(
Label IPlabel = new Label ( "IP", Label.LEFT);
TextField inputIP = new TextField ( "localhost", 10);
Button connectButton = new Button ( "connect mainframe");
Button creatGameButton = new Button ( "Establishment of the game");
Button joinGameButton = new Button ( "Join the game");
Button cancelGameButton = new Button ( "abandon the game");
Button exitGameButton = new Button ( "Close procedures");
ControlPad ()
(
SetLayout (new FlowLayout (FlowLayout.LEFT));
SetBackground (Color.pink);
Add (IPlabel);
Add (inputIP);
Add (connectButton);
Add (creatGameButton);
Add (joinGameButton);
Add (cancelGameButton);
Add (exitGameButton);
)
)
Class inputPad extends Panel
(
TextField inputWords = new TextField ( "", 40);
Choice userChoice = new Choice ();
InputPad ()
(
SetLayout (new FlowLayout (FlowLayout.LEFT));
For (int i = 0; i <50; i + +)
(
UserChoice.addItem (i +"."+" without user ");
)
UserChoice.setSize (60,24);
Add (userChoice);
Add (inputWords);
)
)
/************************************************* *********************************************
Below are: chessPad.java
************************************************** ********************************************/
Import java.awt .*;
Import java.awt.event .*;
Import java.io. *;
Import java.net .*;
Import java.util .*;
Class chessThread extends Thread
(
ChessPad chesspad;
ChessThread (chessPad chesspad)
(
This.chesspad = chesspad;
)
Public void sendMessage (String sndMessage)
(
Try
(
Chesspad.outData.writeUTF (sndMessage);
)
Catch (Exception ea)
(
System.out.println ( "chessThread.sendMessage:" + ea);
)
)
Public void acceptMessage (String recMessage)
(
If (recMessage.startsWith ( "/ chess"))
(
StringTokenizer userToken = new StringTokenizer (recMessage, "");
String chessToken;
ChessOpt String [] = ( "-1", "-1", "0");
Int chessOptNum = 0;
While (userToken.hasMoreTokens ())
(
ChessToken = (String) userToken.nextToken ( "");
If (chessOptNum> = 1 & & chessOptNum <= 3)
(
ChessOpt [chessOptNum-1] = chessToken;
)
ChessOptNum + +;
)
Chesspad.netChessPaint (Integer.parseInt (chessOpt [0]), Integer.parseInt (chessOpt [1]), Integer.parseInt (chessOpt [2]));
)
Else if (recMessage.startsWith ( "/ yourname"))
(
Chesspad.chessSelfName = recMessage.substring (10);
)
Else if (recMessage.equals ( "/ error"))
(
Chesspad.statusText.setText ( "error: there is no such users, please withdraw from the process, to re-enter");
)
Else
(
/ / System.out.println (recMessage);
)
)
Public void run ()
(
String message = "";
Try
(
While (true)
(
Chesspad.inData.readUTF message = ();
AcceptMessage (message);
)
)
Catch (IOException es)
(
)
)
)
Class chessPad extends Panel implements MouseListener, ActionListener
(
Int chessPoint_x =- 1, chessPoint_y =- 1, chessColor = 1;
Int chessBlack_x [] = new int [200];
Int chessBlack_y [] = new int [200];
Int chessWhite_x [] = new int [200];
Int chessWhite_y [] = new int [200];
Int chessBlackCount = 0, chessWhiteCount = 0;
Int chessBlackWin = 0, chessWhiteWin = 0;
Boolean isMouseEnabled = false, isWin = false, isInGame = false;
TextField statusText = new TextField ( "Please connects to the server");
Socket chessSocket;
DataInputStream inData;
DataOutputStream outData;
String chessSelfName = null;
String chessPeerName = null;
String host = null;
Int port = 4331;
ChessThread chessthread = new chessThread (this);
ChessPad ()
(
SetSize (440,440);
SetLayout (null);
SetBackground (Color.pink);
AddMouseListener (this);
Add (statusText);
StatusText.setBounds (40,5,360,24);
StatusText.setEditable (false);
)
Public boolean connectServer (String ServerIP, int ServerPort) throws Exception
(
Try
(
ChessSocket = new Socket (ServerIP, ServerPort);
InData = new DataInputStream (chessSocket.getInputStream ());
OutData = new DataOutputStream (chessSocket.getOutputStream ());
Chessthread.start ();
Return true;
)
Catch (IOException ex)
(
StatusText.setText ( "chessPad: connectServer: unable to connect \ n");
)
Return false;
)
Public void chessVictory (int chessColorWin)
(
This.removeAll ();
For (int i = 0; i <= chessBlackCount; i + +)
(
ChessBlack_x [i] = 0;
ChessBlack_y [i] = 0;
)
For (int i = 0; i <= chessWhiteCount; i + +)
(
ChessWhite_x [i] = 0;
ChessWhite_y [i] = 0;
)
ChessBlackCount = 0;
ChessWhiteCount = 0;
Add (statusText);
StatusText.setBounds (40,5,360,24);
If (chessColorWin == 1)
(ChessBlackWin + +;
StatusText.setText ( "Heiji-black: white" chessBlackWin +":"+ chessWhiteWin + + ", re-start, and wait for the Baiji 13361 …");
)
Else if (chessColorWin ==- 1)
(
ChessWhiteWin + +;
StatusText.setText ( "Baiji-black: white" chessBlackWin +":"+ chessWhiteWin + + ", re-start, and wait for Heiji 13361 …");
)
)
Public void getLocation (int a, int b, int color)
(
If (color == 1)
(
ChessBlack_x [chessBlackCount] = a * 20;
ChessBlack_y [chessBlackCount] = b * 20;
ChessBlackCount + +;
)
Else if (color ==- 1)
(
ChessWhite_x [chessWhiteCount] = a * 20;
ChessWhite_y [chessWhiteCount] = b * 20;
ChessWhiteCount + +;
)
)
Public boolean checkWin (int a, int b, int checkColor)
(
Int step = 1, chessLink = 1, chessLinkTest = 1, chessCompare = 0;
If (checkColor == 1)
(
ChessLink = 1;
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessBlackCount; chessCompare + +)
(
If (((a + step) * 20 == chessBlack_x [chessCompare]) & & ((b * 20) == chessBlack_y [chessCompare]))
(
ChessLink chessLink = +1;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessBlackCount; chessCompare + +)
(
If (((a-step) * 20 == chessBlack_x [chessCompare]) & & (b * 20 == chessBlack_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
ChessLink = 1;
ChessLinkTest = 1;
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessBlackCount; chessCompare + +)
(
If ((a * 20 == chessBlack_x [chessCompare]) & & ((b + step) * 20 == chessBlack_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessBlackCount; chessCompare + +)
(
If ((a * 20 == chessBlack_x [chessCompare]) & & ((b-step) * 20 == chessBlack_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
ChessLink = 1;
ChessLinkTest = 1;
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessBlackCount; chessCompare + +)
(
If (((a-step) * 20 == chessBlack_x [chessCompare]) & & ((b + step) * 20 == chessBlack_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessBlackCount; chessCompare + +)
(
If (((a + step) * 20 == chessBlack_x [chessCompare]) & & ((b-step) * 20 == chessBlack_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
ChessLink = 1;
ChessLinkTest = 1;
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessBlackCount; chessCompare + +)
(
If (((a + step) * 20 == chessBlack_x [chessCompare]) & & ((b + step) * 20 == chessBlack_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessBlackCount; chessCompare + +)
(
If (((a-step) * 20 == chessBlack_x [chessCompare]) & & ((b-step) * 20 == chessBlack_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
)
Else if (checkColor ==- 1)
(
ChessLink = 1;
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare + +)
(
If (((a + step) * 20 == chessWhite_x [chessCompare]) & & (b * 20 == chessWhite_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare + +)
(
If (((a-step) * 20 == chessWhite_x [chessCompare]) & & (b * 20 == chessWhite_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
ChessLink = 1;
ChessLinkTest = 1;
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare + +)
(
If ((a * 20 == chessWhite_x [chessCompare]) & & ((b + step) * 20 == chessWhite_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare + +)
(
If ((a * 20 == chessWhite_x [chessCompare]) & & ((b-step) * 20 == chessWhite_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
ChessLink = 1;
ChessLinkTest = 1;
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare + +)
(
If (((a-step) * 20 == chessWhite_x [chessCompare]) & & ((b + step) * 20 == chessWhite_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare + +)
(
If (((a + step) * 20 == chessWhite_x [chessCompare]) & & ((b-step) * 20 == chessWhite_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
ChessLink = 1;
ChessLinkTest = 1;
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare + +)
(
If (((a + step) * 20 == chessWhite_x [chessCompare]) & & ((b + step) * 20 == chessWhite_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
For (step = 1; step <= 4; step + +)
(
For (chessCompare = 0; chessCompare <= chessWhiteCount; chessCompare + +)
(
If (((a-step) * 20 == chessWhite_x [chessCompare]) & & ((b-step) * 20 == chessWhite_y [chessCompare]))
(
ChessLink + +;
If (chessLink == 5)
(
Return (true);
)
)
)
If (chessLink == (chessLinkTest +1))
ChessLinkTest + +;
Else
Break;
)
)
Return (false);
)
Public void paint (Graphics g)
(
For (int i = 40; i <= 380; i = i +20)
(
G.drawLine (40, i, 400, i);
)
G.drawLine (40,400,400,400);
For (int j = 40; j <= 380; j = j +20)
(
G.drawLine (j, 40, j, 400);
)
G.drawLine (400,40,400,400);
G.fillOval (97,97,6,6);
G.fillOval (337,97,6,6);
G.fillOval (97,337,6,6);
G.fillOval (337,337,6,6);
G.fillOval (217,217,6,6);
)
Public void chessPaint (int chessPoint_a, int chessPoint_b, int color)
(
ChessPoint_black chesspoint_black = new chessPoint_black (this);
ChessPoint_white chesspoint_white = new chessPoint_white (this);
If (color == 1 & & isMouseEnabled)
(
GetLocation (chessPoint_a, chessPoint_b, color);
IsWin = checkWin (chessPoint_a, chessPoint_b, color);
If (isWin == false)
(
Chessthread.sendMessage ("/"+ chessPeerName + "/ chess" chessPoint_a + + "" + chessPoint_b + "" + color);
This.add (chesspoint_black);
Chesspoint_black.setBounds (chessPoint_a * 20-7, 20-7,16,16 chessPoint_b *);
StatusText.setText ( "black (" + + chessBlackCount "Step)" chessPoint_a + + "" + chessPoint_b + ", please Baiji 13361");
IsMouseEnabled = false;
)
Else
(
Chessthread.sendMessage ("/"+ chessPeerName + "/ chess" chessPoint_a + + "" + chessPoint_b + "" + color);
This.add (chesspoint_black);
Chesspoint_black.setBounds (chessPoint_a * 20-7, 20-7,16,16 chessPoint_b *);
ChessVictory (1);
IsMouseEnabled = false;
)
)
Else if (color & isMouseEnabled ==- 1)
(
GetLocation (chessPoint_a, chessPoint_b, color);
IsWin = checkWin (chessPoint_a, chessPoint_b, color);
If (isWin == false)
(
Chessthread.sendMessage ("/"+ chessPeerName + "/ chess" chessPoint_a + + "" + chessPoint_b + "" + color);
This.add (chesspoint_white);
Chesspoint_white.setBounds (chessPoint_a * 20-7, 20-7,16,16 chessPoint_b *);
StatusText.setText ( "White (" + + chessWhiteCount "Step)" chessPoint_a + + "" + chessPoint_b + ", please Heiji 13361");
IsMouseEnabled = false;
)
Else
(
Chessthread.sendMessage ("/"+ chessPeerName + "/ chess" chessPoint_a + + "" + chessPoint_b + "" + color);
This.add (chesspoint_white);
Chesspoint_white.setBounds (chessPoint_a * 20-7, 20-7,16,16 chessPoint_b *);
ChessVictory (-1);
IsMouseEnabled = false;
)
)
)
Public void netChessPaint (int chessPoint_a, int chessPoint_b, int color)
(
ChessPoint_black chesspoint_black = new chessPoint_black (this);
ChessPoint_white chesspoint_white = new chessPoint_white (this);
GetLocation (chessPoint_a, chessPoint_b, color);
If (color == 1)
(
IsWin = checkWin (chessPoint_a, chessPoint_b, color);
If (isWin == false)
(
This.add (chesspoint_black);
Chesspoint_black.setBounds (chessPoint_a * 20-7, 20-7,16,16 chessPoint_b *);
StatusText.setText ( "black (" + + chessBlackCount "Step)" chessPoint_a + + "" + chessPoint_b + ", please Baiji 13361");
IsMouseEnabled = true;
)
Else
(
This.add (chesspoint_black);
Chesspoint_black.setBounds (chessPoint_a * 20-7, 20-7,16,16 chessPoint_b *);
ChessVictory (1);
IsMouseEnabled = true;
)
)
Else if (color ==- 1)
(
IsWin = checkWin (chessPoint_a, chessPoint_b, color);
If (isWin == false)
(
This.add (chesspoint_white);
Chesspoint_white.setBounds (chessPoint_a * 20-7, 20-7,16,16 chessPoint_b *);
StatusText.setText ( "White (" + + chessWhiteCount "Step)" chessPoint_a + + "" + chessPoint_b + ", please Heiji 13361");
IsMouseEnabled = true;
)
Else
(
Chessthread.sendMessage ("/"+ chessPeerName + "/ victory" + color);
This.add (chesspoint_white);
Chesspoint_white.setBounds (chessPoint_a * 20-7, 20-7,16,16 chessPoint_b *);
ChessVictory (-1);
IsMouseEnabled = true;
)
)
)
Public void mousePressed (MouseEvent e)
(
If (e.getModifiers () == InputEvent.BUTTON1_MASK)
(
ChessPoint_x = (int) e.getX ();
ChessPoint_y = (int) e.getY ();
Int a = (chessPoint_x +10) / 20, b = (chessPoint_y +10) / 20;
If (chessPoint_x/20 <2 | | chessPoint_y/20 <2 | | chessPoint_x/20> 19 | | chessPoint_y/20> 19)
()
Else
(
ChessPaint (a, b, chessColor);
)
)
)
Public void mouseReleased (MouseEvent e) ()
Public void mouseEntered (MouseEvent e) ()
Public void mouseExited (MouseEvent e) ()
Public void mouseClicked (MouseEvent e) ()
Public void actionPerformed (ActionEvent e)
(
)
)
Class chessPoint_black extends Canvas implements MouseListener
(
ChessPad chesspad = null;
ChessPoint_black (chessPad p)
(
SetSize (20,20);
Chesspad = p;
AddMouseListener (this);
)
Public void paint (Graphics g)
(
G.setColor (Color.black);
G.fillOval (0,0,14,14);
)
Public void mousePressed (MouseEvent e)
(
/ / If (e.getModifiers () == InputEvent.BUTTON3_MASK)
/ / (
/ / Chesspad.remove (this);
/ / Chesspad.chessColor = 1;
/ / Chesspad.text_2.setText ("");
/ / Chesspad.text_1.setText ( "Please Heiji 13361");
/ /)
)
Public void mouseReleased (MouseEvent e) ()
Public void mouseEntered (MouseEvent e) ()
Public void mouseExited (MouseEvent e) ()
Public void mouseClicked (MouseEvent e) ()
)
Class chessPoint_white extends Canvas implements MouseListener
(
ChessPad chesspad = null;
ChessPoint_white (chessPad p)
(
SetSize (20,20);
AddMouseListener (this);
Chesspad = p;
)
Public void paint (Graphics g)
(
G.setColor (Color.white);
G.fillOval (0,0,14,14);
)
Public void mousePressed (MouseEvent e)
(
/ / If (e.getModifiers () == InputEvent.BUTTON3_MASK)
/ / (
/ / Chesspad.remove (this);
/ / Chesspad.chessColor =- 1;
/ / Chesspad.text_2.setText ( "Please white flag 13361");
/ / Chesspad.text_1.setText ("");
/ /)
)
Public void mouseReleased (MouseEvent e) ()
Public void mouseEntered (MouseEvent e) ()
Public void mouseExited (MouseEvent e) ()
Public void mouseClicked (MouseEvent e)
(
/ / If (e.getClickCount ()> = 2)
/ / Chesspad.remove (this);
)
)
PHP reference commonly used procedures (UNIX operating system)
PHP reference commonly used procedures (UNIX operating system) 2004-06-24 click: 68 common procedures PHP reference (UNIX operating system)
Common Reference (UNIX operating system) 1, Database Connection documents: conn.php (connecting MYSQL database configuration file) <?
/ / This document is connected to the database configuration file, in this connection parameters defined
$ Host = "localhost";
$ User ="******";// you need modify here, replace your database's account
$ Passwd ="******";// also modify here, replace your database's password
$ Dbname ="******";// and modify here, replace your database's name if (! $ Link = mysql_connect ( "$ host", "$ user", "$ pwd")) / / start connect your database
(
Print 'Could not connect to database';
Exit;
)
Mysql_select_db ( "$ dbname") or die ( "Could not select database");
–> 2, the database table files: list_alltb.php (list all the tables in the database name)
<?
/ / Demonstration of how a list of all the database tables
Include ( "conn.php");
$ Result = mysql_list_tables ($ dbname);
If (! $ Result) (
Print "DB Error, could not list tables \ n";
Print 'MySQL Error:'. Mysql_error ();
Exit;
)
$ I = 0;
Echo "$ dbname database in the table is as follows: <br >";// the code below start tolist all the tables in the database";
Echo "<table border=1>";
While ($ i <mysql_num_rows ($ result)) (
$ Tb_names [$ i] = mysql_tablename ($ result, $ i);
Echo "<tr> <td> $ tb_names [$ i] </ td> </ tr> \ n";
$ I + +;
)
Echo "</ table>";
Mysql_free_result ($ result); / / free the resource at the end
–>
3, database query documents: selectdb.php (database query, display of results) <? Php
/ / Demonstrate how to query the database
Include ( "conn.php");
/ * * The implementation of SQL query /
$ Query = "SELECT * FROM my_table";
$ Result = mysql_query ($ query) or die ( "Query failed");
/ * In HTML print the results * /
Print "<table> \ n";
While ($ line = mysql_fetch_array ($ result, MYSQL_ASSOC)) (
Print "\ t <tr> \ n";
Foreach ($ line as $ col_value) (
Print "\ t \ t <td> $ col_value </ td> \ n";
)
Print "\ t </ tr> \ n";
)
Print "</ table> \ n";
/ * Release resources * /
Mysql_free_result ($ result);
/ * Disconnect * /
Mysql_close ($ link);
–>
4, database manipulation of documents: operatedb.php (database records to add, delete, modify) <?
/ / Demonstration of how the data in the database to insert, update and delete operations
Include ( "conn.php");
$ Sql = "insert into user (ID, PW, Name, Sex, Email, Title, Info) values ( '$ userid', '$ userpw', '$ usernam
E ',' $ usersex ',' $ usermail ',' $ usertitle ',' phrase inserted $ userinfo')";//
Mysql_query ($ sql) or die (mysql_error ());// implementation insert operation
$ Sql = "delete from user where ID = '$ userid'"; / / delete statements
Mysql_query ($ sql) or die (mysql_error ()) / / delete the implementation of Operation
$ Sql = "update user set PW = '$ userpw' Name = '$ username' Sex = '$ usersex' Email = '$ usermail'
Title = '$ usertitle', Type = '$ usertype' Info = '$ userinfo' where ID = '$ userid' "; / / update statements
Mysql_query ($ sql) or die (mysql_error ()) / / delete the implementation of Operation
Mysql_close ($ link); / / disconnect
–>
5, document procedures: fileoperate.php (the most common file operations) <?
$ Filename ="****";// to the operation of the file name
/ / Read operation, read out a document to all the contents of a string variable
$ Content = file ($ filename);
$ Content = join ("",$ content);
Print $ content;
/ / A string of characters to write the contents of the original document
If (! $ Fp = fopen ($ filename, "w "))//" w" method to open the file, if the file does not exist, create the document if it exists, the original documents are covered
(
Die ( "open file $ filename error!");
)
Fputs ($ fp, $ content, strlen ($ content));
Fclose ($ fp); / / finished after closing documents must be promptly handle
/ / Added to the document at the end of
If (! $ Fp = fopen ($ filename, "a "))// added to the document at the end," a "way to open
(
Die ( "open file $ filename error!");
)
Fputs ($ fp, $ content, $ strlen ($ content));
Fclose ($ fp);
/ / Delete files
If (is_file ($ filename))
(
Unlink ($ filename) or die ( "delete files failure");
)
Java data types
I would like to you, the type of data should not be regarded as strange, unless you that the programming language knowledge never contacted, but also do not know even what to do, because Below I will first tell us about the knowledge, Of course if you are very familiar with the data types, then you can skip this part below.
The concept of data type data types is the literal meaning of the data type.
Data is recorded information entities, such as 25000000, Pharaoh, and so on, but figures and other data and some of the most primitive symbols is not the same data in general should be meaningful, for instance, the number of 2500, we have only From the figures point of view, it is an integer math, but the data for 2500, it might mean a province's total grain output, may also refer to a company's profit, and so on.
Type is a very basic terms, it is used to a certain thing of the different attributes of components, such as some abstract said, I think you understand how the original now also understand how, it should be no mistake.
Therefore, the data types refers to the classification of data attributes. We know that the data can take many forms, such as the types of digital data 35 (may mean a class size), 100 (may be a subject that a personal score), for example, the character data type A (possibly on behalf of a multiple-choice The first option), San (possibly on behalf of a personal name) and so on. Obviously, these different types of data regardless of its form or its scope are best described in his own limitations, so to them in order to effectively use the distinction that people put forward the concept of data type.
I think you own the meaning of data types should be more clear now, although I am not an expert in this field, but I feel that my expression is not too obscure As it difficult.
Java data types (for the case of 32-bit CPU)
Java data types from the major area is divided into two parts: the basic data types and object data type.
Basic data types, it is more simple to express some basic information about the type of data, which includes the following categories:
Byte bytes in a computer-general of 8 bytes (in what is the meaning, I introduced below)
Char character of the two bytes, which is 16
2 short of the short two-byte integer, which is 16
Int shaping of the four bytes, which is 32
Long long integer of 8 bytes, which is 64
Single-precision real-float, after the decimal point seven effective retention figures, accounting for 32
Double-precision real-double, and after the decimal point to retain effective number 15, representing 64
Boolean Boolean, or a byte, 8-to tell us about the information bar. We know that all the data in the computers are 0 and 1 to a combination of storage, such as a plastic figure in the computer in the form of actual storage:
00000000 00000000 00000000 00000001
Above a 0 or a 1 have been called a bit.
Below a table in the form of the table tell us about all the basic data types
Type bytes median range for example byte 8 1 negative 2 of 7 to 2 7-th-th integer -128,54127 short 16 2 negative 2 of the 15-th to the 15 th power of 2 integer 1348 , 6543 int 32 4 negative 2 of the 31-th to the 31 th power of two integers 0, -10000,345678 long 64 8 negative 2 of the 63-th to the 63 th power of 2 integer 987657897, -12 float 32 4 negative 2 of the 31-th to the 31 th power of 2 Real 23.987,87 F double 64 8 negative 2 of the 63-th to the 63 th power of 2 Real 2.0231,0.456 D char 16 2 negative 2 15 2, the 15-th to the integer 400, A, z, x, -23 boolean 8 1 true, false
Variables used in conjunction with the definition of the following examples:
Byte myByte = 49;
Byte myByte2 = 128; / / (error range too large)
Short myShort = 2345;
Int myInt = 123;
Int myInt2 = 012; / / (012 hexadecimal is using the figures 8 to 0 figures represent the beginning of the 8-band)
Int myInt3 = 0×12E5F; / / (0×12E5F using hexadecimal number of 16 to 0 x figures represent the beginning of the 8-band)
Long myLong = 23;
Long myLong2 = 245L; / / (L said that the value is at the end of a long integer)
Float myFloat = 456.56F; / / (F at the end said that the figure for the single-precision real-)
Double myDouble = 23.56789D; / / (D said that the figure for the end of double-precision real-)
If your 8-band and 16-band and 10 hex conversion is not clear, and I suggest that you do not have to rush in, I think in most cases the programming and less than fundamental. However, I still think that a few examples of conversion is good.
We must first know that 8-band and 16 members of the basic band, we know that 10 band members to its basic
0 1 2 3 4 5 6 7 8 9
Remember the basic 8 band members and 16 members of the basic band:
8 basic band members: 0 1 2 3 4 5 6 7
16 hexadecimal basic: 0 1 2 3 4 5 6 7 8 9 ABCDEF (which ABCDEF representing 10 11 12 13 14 15)
8 to 10 hex hex:
8 hexadecimal number 345, for example, convert 10 hexadecimal number: 0 of 5 × 8 × 8-th +4 in a 2D +3 × 8 2D.
16 to 10 hex hex:
For example, the hexadecimal number 45, converted into 10 hexadecimal number: 0 of 5 × 16 × 16-th +4 th power of a good basic data types such bar on the first, we briefly talk about the subject of data types java .
Java Object Data Types
Java is an object-oriented programming language, java types of data included in the object data type. For example String object, and an array of objects Date object, and so on. Like the example below:
String username = "zhang san" / / String object
Date time = new Date () / / 8 date with the object of the basic data types Correspondingly, there are eight kinds of java in the corresponding object data types, namely:
Byte Short Integer Long Float Double Character Boolean
In addition, there are many other java object type, it will slowly mentioned, of course, is also a major peacetime practice more your own, slowly through the use of a common type, skilled your program design.
2004-3-5
Programming language Java industry popularity ranking topped
Popular programming language industry rankings
Http://www.tiobe.com/index.htm?tiobe_index
Click on the link above, we can see that the latest programming language prevalence of the industry rankings. We will learn from some references.
I am surprised that the country did not have a similar ranking, but not the authority or. As to whether this authority, it is supposed to come from the data, we have no effort to verify only as a learning language reference.
See that the top 50 languages, whimsical turns, when there will be Made in China?
This is the top ten languages, basically before the 2006-2007 top five languages are not changed, namely the java, c, c + +, php, VB.
Position
Apr 2007 Position
Apr 2006 Delta in Position Programming Language Ratings
Delta Apr 2007
Status 1 Apr 2006
Java 18.360% -2.92% A 2 2
C 14.937% -2.75% A 3 3
C + + 10.718% -0.18% A 4 4
PHP 8.639% -2.24% A 5 5
(Visual) Basic 8.280% -1.83% A 6 6
Perl 6.039% +0.19% A 7 8
Python 3.814% +1.05% A 8 7
C # 3.551% -0.40% 9 9 A
JavaScript 3.137% +1.57% A 10 17 





Ruby 2.798% +2.31% A
Data sources (2007.4.23 http://www.tiobe.com/index.htm?tiobe_index)
Language future trends, java, c, c + + still holds the position.
Long term trends
The long term trends for the first 10 programming languages can be found in the line diagram below.
Data sources (2007.4.23 http://www.tiobe.com/index.htm?tiobe_index)
Conclusion: Although ranked above language learning can be a reference, but consider that this is the foreign technical communities by the report. It is of a certain surface, but the domestic situation there are many exceptions, expected the birth of a similar analysis of the site and give us a detailed, the report continued.
See "java programming thinking," notes (5-6)
The previous chapter is now a few days before the record, the following chapter slowly released. For this month, I read this book, many of my notes read by the experience, there may be some wrong expression. If it is so, Please correct me.
Chapter V
1. Java original documents, can have more than one category, but there can be only one public category, and the name and documentation of the same name.
2. Running java explained when it first went classpath environment variables, these variables in the path of java explanation for these directories will go first class document root directory. But if you use jar package, you need to document names will be added to the middle of environment variables. If the name of the same type, it can clash, this time need to clearly specify the location category. CLASSPATH capital needs
3. Java in the public, private, protect access control at the three, should be placed on every member of the definition of the front. Whether members of this data or methods, a visit to control it at the back just a member, not as like c + +. Java does not write access control at the three, it will use the default control authority.
4. Default control authority (package access): with a bag of the class can access. Public: Any person can access the members. Private: that in addition to this category (which includes members of this category), the other can not be visited. Protect: base class can access method, but other types can not visit
5. Each document (compiled modules), there can be only one public category, but can also support a number of functions, if a file in two or more categories of the public, will compiler error. Public needs of the name of the same name and documents, including letters to the same case. Otherwise, the compiler will also error. Document can be no public category, although this rare document names at this time can easily take.
6. Category, it is not private and protect, there are only two types of class, the public and package type. If you do not want others to visit this class, you can structure will be set up for private functions, such people will not be able to create the object of this class, you can provide a method to create a static object. (Note 1: Another impact of such private constructor function is similar. Then it can not be inherited. Note 2: Internal category will enable private and protected. (Some do not, the back sections to be understood))
7. Visit to the control of two reasons: one is to prohibit users touch things they should not touch. This will simplify the understanding of their category. Class II is to be the designers, programmers do not bothered to amend class library under the premise of the internal operation mechanism.
Chapter VI
1. In the design of a basic principle. Design for private data types. Will be designed for public type. Of course meet exceptional circumstances can be adjusted.
2. Derived class may change in the method of a base class (such as draw ()), when still need to call the base class's method, you can use super.draw ()
3. Derived class constructor for will be automatically call the base class constructor function without parameters. If the base class constructor is not the default (non-parametric structural function), we must use the appropriate parameters and super clear call to the corresponding base class constructor function, and the statement must be on the forefront derived class constructor function, the compiler will first implementation of base class constructor, in the implementation of the derived class constructor function.
4. Final has three purposes, namely for data (data), the method (method), and type (class)
L Final for data, when the original data type is type of data that this is a constant. When the data type is the object reference, the reference that this is a constant, once connected to a reference object, can no longer connect to other objects. However, the data object itself can be amended (the only one static), the final data, in a statement when the assignment data can also function in the structure assignment. We can use in the final parameters, the reference to participate in this operation can not point to other objects
L Final for Method: There are two ways for the final effect, a method is locked to prohibit derived class changes, the efficiency of two reasons is that if the method is final. So the compiler to call for the conversion of (inline)) (the compiler will automatically determine whether the ITU)
L Final for categories: mean that you do not inherit this class, you also not allowed other people to inherit this class. As can not inherit this class, like all of the implicit methods into final
5. In the category of the succession of initialization: first-class initialization of the static, and then the static is derived class. Then create the object, then the original target of all types of variable initial values will be translated into all become null reference, and then call the base class constructor is called in the derived class constructor
Java network programming - from the voice network access
Java from the network and access to sound files of audio programming method there are two types, the first play using Java (URL) and play (URL, String) Direct broadcast sound files on the network, and the other is through getAudioClip ( URL) or getAudioClip (URL, String) first network access to audio files, and generate AudioClip type of object, and then the object to operate.
The former format is the use of:
String Audur = "node URL";
Try (
Play (new URL (Audur));
) Catch (Exception e) ()
Or
String Audur = "node URL";
Try (
Play (new URL (Audur), sound files);
) Catch (Exception e) ()
The latter use of the format is:
String Audur = "node URL";
AudioClip loopClip;
Try (
GetAudioClip loopClip = (new URL (Audur));
)
Catch (Exception e) (
System.out.println ( "Can't open the URL");
)
Or
String Audur = "node URL";
AudioClip loopClip;
Try (
GetAudioClip loopClip = (new URL (Audur), sound files);
)
Catch (Exception e) (
System.out.println ( "Can't open the URL");
)
The four are above format will generate some URL object - "new URL (url)" as a direct or getAudioClip play the parameters before and dealt with the case of images, but also could be used "new URL (url)" access a URL object, then pass play or
GetAudioClip. On the first play (URL) format can be applied in the following programming format:
URL Audur = null;
Try (
Audur = new URL ( "node URL");
) Catch (Exception e) (
System.out.println ( "Can't open the URL");
)
Play (Audur);
Below the aforementioned four from the network to access and audio format of the document cite a simple example, for programming reference:
â— procedures for a 4 format
Import java.applet .*;
Import java.awt .*;
Import java.net .*;
Public class sound1 extends Applet
(AudioClip loopClip;
Public void paint (Graphics g) (
String Audur = "http://www.shu.edu.cn/ ~ xyx / java / Animator / audio / bark.au";
Try (
Play (new URL (Audur));
) Catch (Exception e) ()
)
)
â— 5 format two procedures
Import java.applet .*;
Import java.awt .*;
Import java.net .*;
Public class sound2 extends Applet
(AudioClip loopClip;
Public void paint (Graphics g) (
String Audur = "http://www.shu.edu.cn/ ~ xyx / java / Animator / audio /";
Try (
Play (new URL (Audur), "bark.au");
) Catch (Exception e) ()
)
)
â— procedures format 6 3
Import java.applet .*;
Import java.awt .*;
Import java.net .*;
Public class sound extends Applet (
AudioClip loopClip;
Public void init () (
String Audur = "http://www.shu.edu.cn/ ~ xyx / java / Animator / audio / bark.au";
Try (
GetAudioClip loopClip = (new URL (Audur));
) Catch (Exception e) ()
)
Public void paint (Graphics g) (
LoopClip.loop ();
)
)
â— 7 format four procedures
Import java.applet .*;
Import java.awt .*;
Import java.net .*;
Public class sound0 extends Applet (
AudioClip loopClip;
URL auur;
Public void init () (
Try (
Auur = new URL ( "http://www.shu.edu.cn/ ~ xyx / java / Animator / audio /");
)
Catch (MalformedURLException e) (
System.out.println ( "Can't open the URL");
)
LoopClip = getAudioClip (auur, "bark.au");
)
Public void paint (Graphics g) (
LoopClip.loop ();
)
)
CVS management guidelines
1. The creation of cvs
CVS server landing system administrator to create CVS repository storage directory, such as C: \ cvs \ cvsrep. "Cvs-d / cvs / cvsrep init" initialization directory, the command will automatically create CVSROOT, such as CVS directory. Then, in the CVS configuration files, the library at the same time an alias, such as / cvs / cvsrep to prevent users know that the real system directory results. Synonym settings, Unix, it is in the / etc / cvsnt / PServer document; Windows, CVSNT Control Panel can be conducted.
To simplify the operation, we first set environment variables, such as "set cvsroot = c: \ cvs \ cvsrep." In this way, no need for the location of each of the designated CVSROOT.
2. Cvs to create the administrator
The system administrator using the passwd command to build users (at the same time set up the initial password), then new users included in the CVSROOT / admin, these users will become the CVS repository administrator.
For example, through "cvs passwd-r cvsuser-u repadmin" is the creation of a repadmin users. Here, cvs server cvsuser there must be a system user, the user must have the C: \ cvs \ cvsrep complete access. Cvsuser account for the number of users sharing cvs. Repadmin cvs on the remote access, the identity of a cvsuser running.
System administrators use chacl ordered the root directory is read as a provincial competence, nowrite, nocontrol, nocreate, notag. These, of course, can also be the administrator to take cvs.
For example: cvs chacl-a read, nowrite, nocontrol, nocreate, notag
If the subdirectory to set permissions not automatically inherit the parent directory permissions.
Emai by the system administrator account, password, and the path CVSROOT cvs sent to the administrator.
Cvs database management cvs for remote access, for example, by pserver agreement.
Environment variable settings, set cvsroot =: pserver: @ servername repadmin: / cvs / cvsrep.
To the working directory, landing, and initialization of the current directory
Cd workdir
Cvs login
Cvs co.
Change Password
Cvs passwd
3. Ordinary users to create
Cvs library administrators passwd to create users, set up at the same time the initial password, and then inform email-related information.
Cvs passwd-a-r cvsuser-u testuser
4. Create directory tree
Cvs import library administrators to create order and add directory tree, and use chacl order to the user assign permissions.
Can be ordered through lsacl to check the distribution of competence.
Add a directory
Cvs add subdir
Testuser allocated to the read-write access subdir
Cvs chacl a read-and write-u testuser subdir
5. Check in / Check out
Ordinary users can now check out the use of data and revised and submitted.
Set cvsroot =: pserver: testuser @ servername: / cvs / cvsrep.
Cd workdir
Cvs co.
… Modify files…
Cvs commit-m "do some change"
Conclusion:
1. We do not need to cvs server administrator to the root account. And need only one public, can access the directory cvs account can be. The accounts do not even need to disclose your password, nor does it allow remote login.
2. We do not need to create user for every cvs server system cvs account, and need not, rely on the file system access control.
3. We can be designated for each cvs for the administrator, who on their respective cvs library users and the creation of the distribution of competences.
4. Ordinary Users can modify the password cvs account without administrator intervention.
5. Cvs server administrator's job is mainly to create cvs repository (the system can create specific accounts cvs responsible for the creation and management, do not root account), and is responsible for the day-to-day server maintenance, and day-to-day management of cvs from the respective cvs Administrators completed.
Reference:
1. "CVSNT Manual"
2. Http://www.cvsnt.org/wiki/InstallationTips
Ãjava ¢ msxml «xml ת Éhtml
Converting XML to HTML Using Sun's Java API for XML Processing and Microsoft's MSXML 3.0 API
By Robert Galante
Introduction
This article describes two solutions that I have employed in applications to generate custom reports. My solutions convert XML data to HTML using XSL Transformations (XSLT). XML is an eXtensible Markup Language that is used as a data-exchange format between applications. XSL is an eXtensible Stylesheet Language that is used to present and lay out XML data in a browser. XSLT is a programming language that facilitates the transformation of XML data to its HTML equivalent before it is displayed in a browser.
The first solution uses Sun's Java API for XML Processing (JAXP) to convert XML to HTML. The latest production version of the JAXP is version 1.1. The second solution uses Microsoft's MSXML 3.0 API to convert XML to HTML. (Microsoft XML [MSXML) is an XSLT processor that works with the Internet Explorer browser and includes an XML parser and XPath processor.)
Some of the benefits of these implementations follow.
- XML data is derived from the existing application. As a result, the same XML data may be used by other applications, making the application and the data more useful.
- The presentation layer of the reports is separated from the business objects layer. Consequently, the report-generation utility may be used by other applications, including a Web server application.
- If the layout of the report is modified, the application does not have to be recompiled and linked. Only the XSL templates have to be modified.
After I describe each solution, I present some of my observations and suggestions.
Note: This article assumes that the reader already has some knowledge of XML and XSL. See the links at the bottom of this article for references to technical reports about XML and XSL.
JAXP 1.1 consists of three class libraries. These libraries exist in Java Archive file format (JAR) files. Their file names are jaxp.jar, crimson.jar, and xalan.jar. The final release supports the latest XML standards, including version 2.0 of the Simple API for XML (SAX 2.0), and Level 2 of the Document Object Model (DOM Level 2) Also, it includes integrated support for XSL Transformations (XSLT).
I recommend that you install version 1.3 of the Java Development Kit (JDK) when using JAXP 1.1. When I use version 1.2 of the JDK, my application displays a minor, non-fatal error message when it shuts down. This behavior is caused by the JDK, not the application, and version 1.3 resolves this problem.
JAXP Installation
Decompress the zip or tar file and copy the three JAR files to the following subdirectory in your system's JDK directory. On my Windows machine the subdirectory is as follows.
You must add these JAR files to your CLASSPATH in order to use them. Remember to observe case in the filenames. Alternatively, you may copy the three class libraries to the Java extensions directory - C: \ jdk1.3 \ jre \ lib \ ext. I prefer the former installation location, but you are free to choose.C: \ jdk1.3 \ lib
Report Generator Class - RepGen.java and RepGen.class
The report generator is a very simple class that wraps the functionality of the JAXP Transformer object. Applications create an instance of the report generator object and request reports with the buildReport method. The buildReport method takes an XML data string and the name of the XSL template file, which will be used to convert the XML data. It builds the requested report using the JAXP Transformer object, and displays it in the default browser on the target machine. The user prints the HTML page with the standard browser print function. The user saves the HTML page to another file from the browser window, using the "Save As" menu option in the browser's File menu.
The RepGen class is a Java Bean. It has properties that allow the user to get and set the XML data string and the XSL template filename. It has two methods that allow the user to build the HTML page. Both methods have the name buildReport. The first method allows the user to specify the XML data string and XSL template filename as parameters. The second method uses the XML data string and XSL template filename that are set by the properties. The source code for the RepGen class follows.
Package com.fleet.utilities.repgen; / / Imported JAXP Transformer (TraX) classesimport javax.xml.transform.TransformerFactory; import javax.xml.transform.Transformer; import javax.xml.transform.stream.StreamSource; import javax.xml . transform.stream.StreamResult; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerConfigurationException; / / Imported java classesimport java.io.StringReader; import java.io.FileReader; import java.io.BufferedReader; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.Serializable; / / Import the BrowserLauncher classimport com.fleet.utilities.repgen.BrowserLauncher; / * * Use the TraX interface to perform a transformation in the simplest manner possible * (3 statements) * / public class RepGen implements Serializable (String sXML; String sXSLTemplate; public String getXML () (return sXML;) synchronized public void setXML (String sXMLData) (sXML = sXMLData;) public String getXSLTemplate () (return sXSLTemplate;) synchronized public void setXSLTemplate (String sXSLFile) = (sXSLTemplate sXSLFile;) / / Make sure the buildReport method is thread-safe. synchronized public void buildReport (String sXMLData, String sXSLFile ) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException (/ / Create an output file with the same name as the XSL template file, / / but with an extension of. "html." String sOutFile; sXSLFile.lastIndexOf int iDot = (. " "); if (iDot! = -1) (sXSLFile.substring sOutFile = (0, iDot) +." html ";) else (sOutFile = sXSLFile +." html ";) / / Initialize the Bean properties. sXML = sXMLData; sXSLTemplate = sXSLFile; / / Use the static TransformerFactory.newInstance () method to instantiate / / a TransformerFactory. The javax.xml.transform.TransformerFactory / / system property setting determines the actual class to instantiate - / / org.apache . xalan.transformer.TransformerImpl. TransformerFactory tFactory = TransformerFactory.newInstance (); / / Use the TransformerFactory to instantiate a transformer that will work with / / the style sheet you specify. This method call also processes the style sheet / / into a compiled Templates object. Transformer transformer = tFactory.newTransformer (new StreamSource (sXSLTemplate)); / / Use the transformer to apply the associated templates object to an XML document / / and write the output to a file with the same name as the XSL template file that / / was passed in sXSLFile. transformer.transform (new StreamSource (new StringReader (sXML)), new StreamResult (new FileOutputStream (sOutFile))) / / Now, launch the default browser with the HTML result. BrowserLauncher.openURL ( sOutFile);) / / Make sure the buildReport method is thread-safe. synchronized public void buildReport () throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException (/ / Create an output file with the same name as the XSL template file, / / but with an extension of. "html." String sOutFile; int iDot = sXSLTemplate.lastIndexOf ("."); if (iDot! = -1) (sXSLTemplate.substring sOutFile = (0, iDot) +. "html";) else (sOutFile = sXSLTemplate +. "html";) / / Use the same three lines to transform the XML string to HTML. TransformerFactory tFactory = TransformerFactory.newInstance (); Transformer transformer = tFactory.newTransformer (new StreamSource (sXSLTemplate)); transformer.transform (new StreamSource (new StringReader (sXML)), new StreamResult (new FileOutputStream (sOutFile))) / / Now, launch the default browser. BrowserLauncher.openURL (sOutFile);) / / constructor public RepGen () ( ) / / Include a static main function for testing. public static void main (String [] args) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException (if (args.length! = 2) (System.err.println ( "usage: java com.fleet.utilities.repgen.RepGen source stylesheet "); System.exit (1);) RepGen rgObject = new RepGen (); BufferedReader br = new BufferedReader (new FileReader (args [0])); String sLine; StringBuffer sBuffer = new StringBuffer (); while ((sLine = br.readLine ())! = null) (sBuffer.append (sLine + "\ n");) rgObject.buildReport (sBuffer.toString (), args [1]) ;)) The buildReport method performs the transformation from XML to HTML. First, the method creates an instance of the TransformerFactory class. Then, it requests a Transformer object from the class factory. The Transformer object has a "transform" method that uses a StreamSource object for input and a StreamResult object for output. The JAXP Transformer classes define and implement these stream classes. See the import statements in the code above for a list of the classes that are imported by the RepGen class.
The StreamSource class has many constructors. One of these constructors takes a StringReader object and converts it to a StreamSource object. We pass our XML string through the StringReader object's constructor when we create the StreamSource object.
The StreamResult class has many constructors. One of these constructors outputs text to a FileOutputStream object. The buildReport method produces an HTML filename from the XSL template filename, but changes the extension to. "Html." Then, it passes this HTML filename to the FileOutputStream object's constructor, which is passed to the transform method via a new StreamResult object. The transform method converts the XML string to HTML and writes the results to the output file.
See the JAXP documentation that comes with the distribution for more details on these classes. Or click on the following link to view various references to JAXP online documentation.
Http://java.sun.com/xml/xml_jaxp.html
Our example displays the results in a Web browser using the BrowserLauncher class. The BrowserLauncher class is a simple utility that encapsulates the details about launching the default browser. A programmer named Eric Albert was kind enough to publish this class on his Stanford University Web site. I have included this class in the RepGen JAR file. See the links below to download the source for the BrowserLauncher class. On Windows machines, the BrowserLauncher class uses the default browser. On Unix machines, the BrowserLauncher class assumes that Netscape is the default browser .
The RepGen class is distributed as a JAR file, which is called RepGen.jar. Add this jar file to your CLASSPATH. Test the RepGen class with the following command.
Java com.fleet.utilities.repgen.RepGen Report.xml Report.xsl
You will see results displayed as shown below in your browser.
I have included the sample XML and XSL files with the source code download. As you can see in the command above, they are called Report.xml and Report.xsl. Make sure these files are in the current directory when you execute the command. Otherwise, you will have to specify the complete system path and filename for each file.
The following code fragment illustrates an example of how to use the RepGen class.
Import com.fleet.utilities.repgen .*; static public void main (String args []) (RepGen rgObject; StringBuffer sXML = new StringBuffer (); StringBuffer sXSLFile = new StringBuffer (); / / Add some code here to build the XML string / / This code will be different in your application / / For now, hard-code some data. sXML.append ( "<? xml version = \" 1 \ "encoding = \" UTF-8 \ "? > "); sXML.append ("…"); / / Code removed for brevity. sXSLFile =" SalesReport.xsl "try (rgObject = new RepGen () / / This method transforms the XML to HTML and pops up the default browser. rgObject.buildReport (sXML, sXSLFile);) catch (FileNotFoundException e) () catch (TransformerConfigurationException e) () catch (TransformerException e) () catch (Exception e) ()) The RepGen class is very simple to use. First, create your XSL template file and your XML data string. Then create an instance of the RepGen class. Finally, call the buildReport method to display the HTML results in a browser.
Exceptions
The transform method fires a TransformerException when an error is encountered in the XML data or the XSL template file. The following code fragment shows how to use the TransformerException class.
Try (rgObject = new RepGen () / / This method transforms the XML to HTML and pops up the default browser. RgObject.buildReport (sXML, sXSLFile);) catch (TransformerException e) (/ / See if a SourceLocator object is available . If it is, display the location / / of the error in the XML data stream. Otherwise, just display the error message. if (e.getLocator ()! = null) (System.out.println ( "Error in XML document at line "+ e.getLocator (). getLineNumber () +" and column "+ e.getLocator (). getColumnNumber () +" \ n ");) else (System.out.println (e.getMessage ()) ;)) catch (Exception e) (System.out.println (e.getMessage ());} If the error occurs in the XML data stream, the getLocator method in the TransformerException class allows an exception handler to determine the source of the error. It returns a SourceLocator object that has two useful methods. The first method - getLineNumber - returns the line number of the offending node. The second method - getColumnNumber - returns the column number where the error occurred. These methods get you close to the location of the error, but I have found that it depends on the error. For example, if you forget a closing tag for one of the subnodes in the XML file, the line number overshoots to the next node's closing tag, and the column number is set to -1.
Generally, the SourceLocator object returns useful information. However, most of my errors occur in the XSL template file, not the XML data stream. The SourceLocator does not locate syntax errors in XSL directives. But the TransformerException object does provide information about the location of errors in the XSL template file. Sometimes the error message is not very informative. You may get an error message, such as "identifier must be quoted," if you forget to put double quotes around a tag's value. But you have to find the location of the missing double quote yourself.
While the SourceLocator object is not very useful for finding XSL errors, I have found that the TransformerException generates enough information about the source of errors in XSL templates, including line numbers, to be useful in most cases. So all is not lost. In spite of these minor shortcomings, the TransformerException is quite useful for debugging XML and XSL files.
Observations and Suggestions
The Java solution is platform independent, which is a good thing. Furthermore, the RepGen object can be instantiated from a Java server page. You may want to add additional methods that return the results as a string, rather than launch a web browser to view the results. This way you can display the HTML dynamically. Also, you may want to compare the XML data string and XSL template file with the values that were passed to the buildReport method previously in order to skip a transformation that has already been done. I'll leave these suggestions as an exercise for the reader.
I've noticed that the first transformation that executes takes significantly longer than the next. I attribute these results to the fact that the RepGen class and the JAXP classes are loading and compiling to native code during the first pass. If I convert the code to an Enterprise Java Bean, I suspect that this will no longer be a problem. On one real-world implementation, I compiled the code to Win32 native mode, and it ran quite well.
When the transform method encounters an error in the XML data stream, the SourceLocator object can be used to return the line number and column number where the error occurred. It would have been nice if the SourceLocator object returned the source of errors in XSL template files too. When the transform method encounters an error in the XSL template file, the TransformerException error message returns information about the source of the error in most cases, but not all. Sometimes it tells you what the error is, but you have to find it yourself.
The RepGen class can only be used in Java environments. If the client's platform of choice is Windows, then why not take advantage of the Microsoft MSXML 3.0 API? The next sections cover this solution in more detail.
Using Microsoft's MSXML 3.0 API to Transform XML to HTMLMicrosoft makes the MSXML 3.0 API available for free from its download site. Go to the following URL and search with the criteria "XML."
Http://www.microsoft.com/downloads/search.asp
You have to specify your target operating system and "All Downloads." Then download the "MS XML Parser 3.0 Service Pack 1 release." This selection downloads a file called msxml3sp1.exe. Execute this file and follow the installation wizard to complete the installation .
Microsoft has released a preview version of the MSXML 4.0 API, but I have not had the chance to evaluate it. The example in this article uses version 3.0 and has been tested with the original release of the MSXML 3.0 API and with service pack 1.
If you like, you may download my XMLReports Browser utility, which handles the complete installation for you. If you do this, you get the MSXML3.0 API, which has been packaged with a simple browser utility that displays HTML in the MS Web Browser control.
XMLReports Browser Utility
The XMLReports Browser utility is a convenience tool that was developed to handle custom reporting in Visual Basic and ASP applications. The XMLReports Browser utility is a wrapper object that exposes the transformation feature of the Microsoft MSXML 3.0 API, and optionally displays the results in a simple browser. The user supplies the XML document and the XHTML /
