当前位置:
文档之家› 围棋(改进版)源代码-Java Applet小程序
围棋(改进版)源代码-Java Applet小程序
text_4.setEnabled(true);
startbutton.setEnabled(false);
text_1.setEnabled(false);
text_2.setEnabled(false);
chessColor=1;
add(startbutton);
{
Component com=(Component)e.getSource();
if(com==text_3)
{
text_3.setText("");
}
else if(com==text_4)
{
text_4.setText("");
}
}
public void focusLost(FocusEvent e)
}
else if(blackname.equals("black'name"))
{
JOptionPane.showMessageDialog(this,"please input the black player's name,and click input button","reminder",JOptionPane.WARNING_MESSAGE);
{
int x = -1, y = -1, chessColor = 1;
String blackname="",whitename="";
Button startbutton=new Button("restart");
Button inputButton=new Button("input");
TextField text_1=new TextField("black please"),
}
else if(blackname.equals("black'name"))
{
JOptionPane.showMessageDialog(this,"please input the black player's name","reminder",JOptionPane.WARNING_MESSAGE);
{
}
public void mousePressed(MouseEvent e)
{
if(e.getModifiers()==InputEvent.BUTTON1_MASK)
{
x = (int)e.getX();
y = (int)e.getY();
int a=(x+10)/20,b=(y+10)/20;
{
ChessPad chesspad= new ChessPad();
Chess()
{
add(chesspad);
chesspad.setBounds(70,90,440,440);
Label label=new Label("click to point,doubled_click to remove,right click to back",Label.CENTER);
text_2.setEnabled(false);
text_2.setEditable(false);
setSize(440,440);
setLayout(null);
setBackground(Color.orange);
addMouseListener(this);
}
public void paint(Graphics g)
text_1.setText(blackname+" please");
text_2.setEnabled(true);
}
}
else if(e.getSource()==startbutton)
{
this.removeAll();
inputButton.setEnabled(true);
text_3.setEnabled(true);
{
for(int i=80;i<=400;i=i+20)
{
g.drawLine(40,i,400,i);
}
g.drawLine(40,420,400,420);
for(int j=40;j<=380;j=j+20)
{
g.drawLine(j,80,j,420);
}
g.drawLine(400,80,400,420);
text_2.setText("");
}
}
}
}
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
System.exit(0);
}
}
);
setLayout(null);
setVisible(true);
setSize(600,550);
}
public static void main(String args[])
{
Chess chess=new Chess();
}
}
class ChessPad extends Panel implements MouseListener, ActionListener,FocusListener
}
else if(whitename.equals("white'name"))
{
JOptionPane.showMessageDialog(this,"please input the white player's name,and click input button","reminder",JOptionPane.WARNING_MESSAGE);
{
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==inputButton)
{
blackname=text_3.getText().trim();
whitename=text_4.getText().trim();
if(blackname.length()==0||whitename.length()==0)
text_1.setText("");
}
else if(chessColor==-1)
{
this.add(chesspoint_white);
chesspoint_white.setBounds(a*20-10,b*20-10,20,20);
chessColor=chessColor*(-1);
text_1.setText(this.blackname+" please");
add(label);
label.setBounds(70,55,440,24);
label.setBackground(Color.orange);
addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
}
else
{
inputButton.setEnabled(false);
text_3.removeFocusListener(this);
text_3.setEnabled(false);
text_4.setEnabled(false);
startbutton.setEnabled(true);
text_1.setEnabled(true);
g.fillOval(97,137,6,6);
g.fillOval(337,137,6,6);
g.fillOval(97,377,6,6);
g.fillOval(337,377,6,6);
g.fillOval(217,257,6,6);
}
public void focusGained(FocusEvent e)
add(text_4);
text_4.setBounds(315,5,90,24);
text_4.addFocusListener(this);
text_4.setEditable(true);
add(startbutton);
startbutton.setBounds(35,36,60,26);
startbutton.setEnabled(false);
startbutton.addActionListener(this);
add(text_1);
text_1.setBounds(115,36,90,24);
text_1.setEnabled(false);
text_1.setEditable(false);
add(text_2);
text_2.setBounds(315,36,90,24);
}
else if(whitename.equals("white'name"))