Android课程设计的建议石头剪刀布游戏
发布网友
发布时间:2022-04-25 09:28
我来回答
共1个回答
热心网友
时间:2023-12-02 11:01
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Test extends JApplet{
private static final long serialVersionUID = 1L;
JButton btnStone = new JButton("石头");
JButton btnForfex = new JButton("剪刀");
JButton btnCloth = new JButton("布");
JLabel jl = new JLabel();
JPanel jpl = new JPanel();
public void init(){
jpl.add(jl,BorderLayout.NORTH);
jpl.add(btnStone,BorderLayout.SOUTH);
jpl.add(btnForfex,BorderLayout.SOUTH);
jpl.add(btnCloth,BorderLayout.SOUTH);
this.getContentPane().add(jpl);
btnForfex.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
doSFC();
if(doSFC()==1){
jl.setText("石头");
JOptionPane.showMessageDialog(null, "平手");
}
if(doSFC()==2){
jl.setText("剪刀");
JOptionPane.showMessageDialog(null, "你赢了");
}
if(doSFC()==3){
jl.setText("布");
JOptionPane.showMessageDialog(null, "你输了");
}
}
});
btnStone.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
doSFC();
if(doSFC()==1){
jl.setText("石头");
JOptionPane.showMessageDialog(null, "你赢了");
}
if(doSFC()==2){
jl.setText("剪刀");
JOptionPane.showMessageDialog(null, "你输了");
}
if(doSFC()==3){
jl.setText("布");
JOptionPane.showMessageDialog(null, "平手");
}
}
});
btnCloth.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
doSFC();
if(doSFC()==1){
jl.setText("石头");
JOptionPane.showMessageDialog(null, "你输了");
}
if(doSFC()==2){
jl.setText("剪刀");
JOptionPane.showMessageDialog(null, "平手");
}
if(doSFC()==3){
jl.setText("布");
JOptionPane.showMessageDialog(null, "你赢了");
}
}
});
}
public int doSFC(){//随机生成1、2、3
int n = 0 ;
//
return n;
}
}