java代碼搞笑注釋 java代碼注釋有哪些

JAVA代碼,幫忙加點(diǎn)注釋,分不多了

看到這種我完全能解決,卻不知道解決什么的問題,我真的是頭痛非常

創(chuàng)新互聯(lián)公司主營磁縣網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶App定制開發(fā),磁縣h5成都微信小程序搭建,磁縣網(wǎng)站營銷推廣歡迎磁縣等地區(qū)企業(yè)咨詢

以我的理解?你是要我寫一個ServerThread類么?來處理連接到client的socket對象?但是怎么處理你又沒講?是向client回復(fù)一個消息啊?還是執(zhí)行一段內(nèi)部命令?拜托說清楚點(diǎn)吧?

我就按我的理解簡單寫下吧

public?class?Server?{

public?static?void?main(String[]?args)?throws?IOException?{

ServerSocket?server?=?new?ServerSocket(7675);

Socket?socket?=?null;

ExecutorService?pool?=?Executors.newFixedThreadPool(100);

while?(true)?{

//每一個客戶端的請求過來都創(chuàng)建一個socket對象

socket?=?server.accept();

//創(chuàng)建一個固定大小的線程池,比傳統(tǒng)new?Thread()要更有效率,如不能理解

//可以用new?Thread(new?ServerThread(socket))代替

pool.execute(new?ServerThread(socket));

}

}

}

public?class?ServerThread?implements?Runnable

{

/*

*?該類繼承Runnable接口,run方法中做的事情是,接收客戶商的消息并打印

*?向客戶端發(fā)送一個消息

*/

private?Socket?socket;

public?ServerThread(Socket?socket)?{

this.socket?=?socket;

}

@Override

public?void?run()?{

try

{

//向客戶端發(fā)送一個消息

socket.getOutputStream().write("hello,this?is?server".getBytes());

InputStream?input?=?socket.getInputStream();

byte[]?b?=?new?byte[1024];

int?len=0;

//打印客戶端發(fā)來的消息

while((len=input.read(b))!=-1){

System.out.println(new?String(b,0,len));

}

}catch(Exception?e)

{

e.printStackTrace();

}

}

}

JAVA游戲代碼注釋

import javax.swing.*;import java.awt.*;import java.awt.event.*;public class lianliankan implements ActionListener{JFrame mainFrame; //主面板Container thisContainer;JPanel centerPanel,southPanel,northPanel; //子面板JButton diamondsButton[][] = new JButton[6][5];//游戲按鈕數(shù)組JButton exitButton,resetButton,newlyButton; //退出,重列,重新開始按鈕JLabel fractionLable=new JLabel("0"); //分?jǐn)?shù)標(biāo)簽JButton firstButton,secondButton; //分別記錄兩次被選中的按鈕int grid[][] = new int[8][7];//儲存游戲按鈕位置static boolean pressInformation=false; //判斷是否有按鈕被選中int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位置坐標(biāo)int i,j,k,n;//消除方法控制public void init(){mainFrame=new JFrame("JKJ連連看");thisContainer = mainFrame.getContentPane();thisContainer.setLayout(new BorderLayout());centerPanel=new JPanel();southPanel=new JPanel();northPanel=new JPanel();thisContainer.add(centerPanel,"Center");thisContainer.add(southPanel,"South");thisContainer.add(northPanel,"North");centerPanel.setLayout(new GridLayout(6,5));for(int cols = 0;cols 6;cols++){for(int rows = 0;rows 5;rows++ ){diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));diamondsButton[cols][rows].addActionListener((java.awt.event.ActionListener) this);centerPanel.add(diamondsButton[cols][rows]);}}exitButton=new JButton("退出");exitButton.addActionListener((java.awt.event.ActionListener) this);resetButton=new JButton("重列");resetButton.addActionListener((java.awt.event.ActionListener) this);newlyButton=new JButton("再來一局");newlyButton.addActionListener((java.awt.event.ActionListener) this);southPanel.add(exitButton);southPanel.add(resetButton);southPanel.add(newlyButton);fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));northPanel.add(fractionLable);mainFrame.setBounds(280,100,500,450);mainFrame.setVisible(true);}public void randomBuild() {int randoms,cols,rows;for(int twins=1;twins=15;twins++) {randoms=(int)(Math.random()*25+1);for(int alike=1;alike=2;alike++) {cols=(int)(Math.random()*6+1);rows=(int)(Math.random()*5+1);while(grid[cols][rows]!=0) {cols=(int)(Math.random()*6+1);rows=(int)(Math.random()*5+1);}this.grid[cols][rows]=randoms;}}}public void fraction(){fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));}public void reload() {int save[] = new int[30];int n=0,cols,rows;int grid[][]= new int[8][7];for(int i=0;i=6;i++) {for(int j=0;j=5;j++) {if(this.grid[i][j]!=0) {save[n]=this.grid[i][j];n++;}}}n=n-1;this.grid=grid;while(n=0) {cols=(int)(Math.random()*6+1);rows=(int)(Math.random()*5+1);while(grid[cols][rows]!=0) {cols=(int)(Math.random()*6+1);rows=(int)(Math.random()*5+1);}this.grid[cols][rows]=save[n];n--;}mainFrame.setVisible(false);pressInformation=false; //這里一定要將按鈕點(diǎn)擊信息歸為初始init();for(int i = 0;i 6;i++){for(int j = 0;j 5;j++ ){if(grid[i+1][j+1]==0)diamondsButton[i][j].setVisible(false);}}}public void estimateEven(int placeX,int placeY,JButton bz) {if(pressInformation==false) {x=placeX;y=placeY;secondMsg=grid[x][y];secondButton=bz;pressInformation=true;}else {x0=x;y0=y;fristMsg=secondMsg;firstButton=secondButton;x=placeX;y=placeY;secondMsg=grid[x][y];secondButton=bz;if(fristMsg==secondMsg secondButton!=firstButton){xiao();}}}public void xiao() { //相同的情況下能不能消去。仔細(xì)分析,不一條條注釋if((x0==x (y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)(y0==y))){ //判斷是否相鄰remove();}else{for (j=0;j7;j++ ) {if (grid[x0][j]==0){ //判斷第一個按鈕同行哪個按鈕為空if (yj) { //如果第二個按鈕的Y坐標(biāo)大于空按鈕的Y坐標(biāo)說明第一按鈕在第二按鈕左邊f(xié)or (i=y-1;i=j;i-- ){ //判斷第二按鈕左側(cè)直到第一按鈕中間有沒有按鈕if (grid[x][i]!=0) {k=0;break;}else{ k=1; } //K=1說明通過了第一次驗(yàn)證}if (k==1) {linePassOne();}}if (yj){ //如果第二個按鈕的Y坐標(biāo)小于空按鈕的Y坐標(biāo)說明第一按鈕在第二按鈕右邊f(xié)or (i=y+1;i=j ;i++ ){ //判斷第二按鈕左側(cè)直到第一按鈕中間有沒有按鈕if (grid[x][i]!=0){k=0;break;}else { k=1; }}if (k==1){linePassOne();}}if (y==j ) {linePassOne();}}if (k==2) {if (x0==x) {remove();}if (x0x) {for (n=x0;n=x-1;n++ ) {if (grid[n][j]!=0) {k=0;break;}if(grid[n][j]==0 n==x-1) {remove();}}}if (x0x) {for (n=x0;n=x+1 ;n-- ) {if (grid[n][j]!=0) {k=0;break;}if(grid[n][j]==0 n==x+1) {remove();}}}}}for (i=0;i8;i++ ) { //列if (grid[i][y0]==0) {if (xi) {for (j=x-1;j=i ;j-- ) {if (grid[j][y]!=0) {k=0;break;}else { k=1; }}if (k==1) {rowPassOne();}}if (xi) {for (j=x+1;j=i;j++ ) {if (grid[j][y]!=0) {k=0;break;}else { k=1; }}if (k==1) {rowPassOne();}}if (x==i) {rowPassOne();}}if (k==2){if (y0==y) {remove();}if (y0y) {for (n=y0;n=y-1 ;n++ ) {if (grid[i][n]!=0) {k=0;break;}if(grid[i][n]==0 n==y-1) {remove();}}}if (y0y) {for (n=y0;n=y+1 ;n--) {if (grid[i][n]!=0) {k=0;break;}if(grid[i][n]==0 n==y+1) {remove();}}}}}}}public void linePassOne(){if (y0j){ //第一按鈕同行空按鈕在左邊f(xié)or (i=y0-1;i=j ;i-- ){ //判斷第一按鈕同左側(cè)空按鈕之間有沒按鈕if (grid[x0][i]!=0) {k=0;break;}else { k=2; } //K=2說明通過了第二次驗(yàn)證}}if (y0j){ //第一按鈕同行空按鈕在與第二按鈕之間for (i=y0+1;i=j ;i++){if (grid[x0][i]!=0) {k=0;break;}else{ k=2; }}}}public void rowPassOne(){if (x0i) {for (j=x0-1;j=i ;j-- ) {if (grid[j][y0]!=0) {k=0;break;}else { k=2; }}}if (x0i) {for (j=x0+1;j=i ;j++ ) {if (grid[j][y0]!=0) {k=0;break;}else { k=2; }}}}public void remove(){firstButton.setVisible(false);secondButton.setVisible(false);fraction();pressInformation=false;k=0;grid[x0][y0]=0;grid[x][y]=0;}public void actionPerformed(ActionEvent e) {if(e.getSource()==newlyButton){int grid[][] = new int[8][7];this.grid = grid;randomBuild();mainFrame.setVisible(false);pressInformation=false;init();}if(e.getSource()==exitButton)System.exit(0);if(e.getSource()==resetButton)reload();for(int cols = 0;cols 6;cols++){for(int rows = 0;rows 5;rows++ ){if(e.getSource()==diamondsButton[cols][rows])estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);}}}public static void main(String[] args) {lianliankan llk = new lianliankan();llk.randomBuild();llk.init();}}

請采納。

給Java代碼的的每一句做一個注釋,很簡單的

還是給你貼在下面

代碼一:

public?class?Animal?{????定義動物類

public?void?breath(){??????定義呼吸方法

System.out.println("Breathing...");?}}???具體的實(shí)現(xiàn)是Breathing...

代碼二:public?class?Fish?extends?Animal?{????定義魚類?繼承動物類

public?void?breath()?{?????定義呼吸方法

System.out.println("Bubbling...");?}}???具體的實(shí)現(xiàn)是?Bubbling...

代碼三:public?class?LungFish?extends?Fish{??定義肺魚類繼承魚類

public?void?breath()?{??????定義呼吸方法???

System.out.println("Breathing...");?}}???具體的實(shí)現(xiàn)是Breathing...

代碼四:public?class?Test?{?public?static?void?main(String[]?args)?{??

Animal?animal1?=?new?Animal();?????實(shí)例化一個動物類

animal1.breath();????調(diào)用呼吸方法

Animal?animal2?=?new?Fish();????實(shí)例化一個魚類

animal2.breath();????調(diào)用呼吸方法

Animal?animal3?=?new?LungFish();???實(shí)例化一個肺魚類

animal3.breath();?}}??調(diào)用呼吸方法

網(wǎng)站名稱:java代碼搞笑注釋 java代碼注釋有哪些
網(wǎng)頁網(wǎng)址:http://www.muchs.cn/article44/doeogee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、建站公司、、關(guān)鍵詞優(yōu)化、域名注冊軟件開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化