package meng; import java.awt.Color; import java.awt.Font; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; public class abc extends JFrame implements ActionListener { JPanel panel; //panel面板 JButton toneButton; //石头按钮 JButton jianButton; //剪刀按钮 JButton buButton; //布按钮 JButton clearButton; //清除按钮 第1页 JLabel label; //显示分数标签 JTextArea textArea; //显示结果文本区 int win=0; //赢了 int fail=0; //输了 int ping=0; //平了 int grade=0; //分数计数 int i=1; //1表示剪刀,2标示石头, 3表示布 String[] set=new String[]{null,"剪刀","石头","布"}; //存放剪刀石头布String result=" "; //显示分数的字符串 public abc() //构造函数 { //实例化各个控件和设置各个控件的在面板里的位置 panel=new JPanel(); panel.setLayout(null); panel.setBackground(Color.yellow); textArea=new JTextArea(); textArea.setBounds(new Rectangle(0,50,400,100)); textArea.setEditable(false); textArea.setBackground(Color.yellow); textArea.setFont(new Font("宋体",Font.BOLD,30)); toneButton=new JButton("石头"); 第2页 toneButton.setBounds(new Rectangle(0,0,100,50)); jianButton=new JButton("剪刀"); jianButton.setBounds(new Rectangle(100,0,100,50)); buButton=new JButton("布"); buButton.setBounds(new Rectangle(200,0,100,50)); clearButton=new JButton("清空"); clearButton.setBounds(new Rectangle(300,0,100,50)); buButton.setBackground(Color.green); jianButton.setBackground(Color.green); toneButton.setBackground(Color.green); clearButton.setBackground(Color.green); label=new JLabel(result); label.setBounds(new Rectangle(0,150,300,60)); //实现按钮监听 toneButton.addActionListener(this); jianButton.addActionListener(this); buButton.addActionListener(this); 第3页 本文来源:https://www.wddqw.com/doc/34f4755ce518964bcf847c22.html