十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这种题自己写吧,题里状态定义个变量,然后判断邻点这些都是方法,然后题里面if要怎么用都给你说清楚了 题了有如果的地方就是一个if语句然后跟着题里的如果把条件写完了 结果也出来了
创新互联于2013年成立,先为尉氏等服务建站,尉氏等地企业,进行企业商务咨询服务。为尉氏企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
第一个:用Integer类的parseInt方法:
如:int a=parseInt("1111111","2");那么a就是127了。(好像是parseInt("2","1111111");自己试试)
第二个:
static final int huLu=7.5;//中元美元汇率
int a=100*huLu
System.out.println("¥"+Integer.toString(a));
第三个:做一个围棋棋盘的图片,加入程序就是了。
就给你一个吧,只不过没有添加棋子,你自己搞吧。import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class ChessPad extends Panel implements MouseListener,ActionListener
{int x=-1,y=-1,棋子颜色=1;
Button button=new Button("重新开局");
TextField text_1=new TextField("请黑棋下子"),
text_2=new TextField();
ChessPad()
{setSize(440,440);
setLayout(null);setBackground(Color.pink);
addMouseListener(this);add(button);button.setBounds(10,5,60,26);
button.addActionListener(this);
add(text_1);text_1.setBounds(90,5,90,24);
add(text_2);text_2.setBounds(290,5,90,24);
text_1.setEditable(false);text_2.setEditable(false);
}
public void paint(Graphics g)
{for(int i=40;i=380;i+=20)
{g.drawLine(40,i,400,i);
}
g.drawLine(40,400,400,400);
for(int j=40;j=380;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 mousePressed(MouseEvent e)
{if(e.getModifiers()==InputEvent.BUTTON1_MASK)
{x=(int)e.getX();y=(int)e.getY();
ChessPoint_black chesspoint_black=new ChessPoint_black(this);
ChessPoint_white chesspoint_white=new ChessPoint_white(this);
int a=(x+10)/2,b=(y+10)/2;
if(x/202||y/202||x/2019||y/2019)
{}
else
{
if(棋子颜色==1)
{this.add(chesspoint_black);
chesspoint_black.setBounds(a*20-7,b*20-7,16,16);
棋子颜色=棋子颜色*(-1);
text_2.setText("请白棋下子");
text_1.setText("");
}
else if(棋子颜色==-1)
{this.add(chesspoint_white);
chesspoint_white.setBounds(a*20-7,b*20-7,16,16);
棋子颜色=棋子颜色*(-1);
text_1.setText("请黑棋下子");
text_2.setText("");
}
}
}
}
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)
{this.removeAll();棋子颜色=1;
add(button);button.setBounds(10,5,60,26);
add(text_1);text_1.setBounds(90,5,90,24);
text_2.setText("");text_1.setText("请黑棋下子");
add(text_2);text_2.setBounds(290,5,90,24);
}
}
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.棋子颜色=1;
chesspad.text_2.setText("");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);
}
}
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.棋子颜色=-1;
chesspad.text_2.setText("请白棋下子");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);
}
}
public class Chess extends Frame
{ChessPad chesspad=new ChessPad();
Chess()
{setVisible(true);
setLayout(null);
Label label=new Label("单击左键下子,双击吃子,右击棋子悔棋",Label.CENTER);
add(label);label.setBounds(70,55,440,26);
label.setBackground(Color.orange);
add(chesspad);chesspad.setBounds(70,90,440,440);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);
}
});
pack();setSize(600,550);
}
public static void main (String args[])
{Chess chess=new Chess();
}
}