java代码搞笑注释 java代码注释有哪些
JAVA代码,帮忙加点注释,分不多了
看到这种我完全能解决,却不知道解决什么的问题,我真的是头痛非常
创新互联公司主营磁县网站建设的网络公司,主营网站建设方案,重庆App定制开发,磁县h5成都微信小程序搭建,磁县网站营销推广欢迎磁县等地区企业咨询
以我的理解?你是要我写一个ServerThread类么?来处理连接到client的socket对象?但是怎么处理你又没讲?是向client回复一个消息啊?还是执行一段内部命令?拜托说清楚点吧?
我就按我的理解简单写下吧
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) {
//每一个客户端的请求过来都创建一个socket对象
socket = server.accept();
//创建一个固定大小的线程池,比传统new Thread()要更有效率,如不能理解
//可以用new Thread(new ServerThread(socket))代替
pool.execute(new ServerThread(socket));
}
}
}
public class ServerThread implements Runnable
{
/*
* 该类继承Runnable接口,run方法中做的事情是,接收客户商的消息并打印
* 向客户端发送一个消息
*/
private Socket socket;
public ServerThread(Socket socket) {
this.socket = socket;
}
@Override
public void run() {
try
{
//向客户端发送一个消息
socket.getOutputStream().write("hello,this is server".getBytes());
InputStream input = socket.getInputStream();
byte[] b = new byte[1024];
int len=0;
//打印客户端发来的消息
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];//游戏按钮数组JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮JLabel fractionLable=new JLabel("0"); //分数标签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; //游戏按钮的位置坐标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; //这里一定要将按钮点击信息归为初始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() { //相同的情况下能不能消去。仔细分析,不一条条注释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坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边for (i=y-1;i=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮if (grid[x][i]!=0) {k=0;break;}else{ k=1; } //K=1说明通过了第一次验证}if (k==1) {linePassOne();}}if (yj){ //如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边for (i=y+1;i=j ;i++ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮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){ //第一按钮同行空按钮在左边for (i=y0-1;i=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮if (grid[x0][i]!=0) {k=0;break;}else { k=2; } //K=2说明通过了第二次验证}}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..."); }} 具体的实现是Breathing...
代码二:public class Fish extends Animal { 定义鱼类 继承动物类
public void breath() { 定义呼吸方法
System.out.println("Bubbling..."); }} 具体的实现是 Bubbling...
代码三:public class LungFish extends Fish{ 定义肺鱼类继承鱼类
public void breath() { 定义呼吸方法
System.out.println("Breathing..."); }} 具体的实现是Breathing...
代码四:public class Test { public static void main(String[] args) {
Animal animal1 = new Animal(); 实例化一个动物类
animal1.breath(); 调用呼吸方法
Animal animal2 = new Fish(); 实例化一个鱼类
animal2.breath(); 调用呼吸方法
Animal animal3 = new LungFish(); 实例化一个肺鱼类
animal3.breath(); }} 调用呼吸方法
本文标题:java代码搞笑注释 java代码注释有哪些
文章起源:http://scjbc.cn/article/doeogee.html