比赛记分板

比赛记分板

之前写的,记得好像有个bug在这里插入图片描述

import java.awt.Color;
import java.awt.Font;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main {
    public static void main(String[] args) {
        
        JFrame frame = new JFrame("排球比赛计分系统"); // 实例化窗体对象
        frame.setLayout(null); // 使用绝对定位
        Font f = new Font("",Font.BOLD, 50);
        
        JLabel guo = new JLabel("中国队得分"); // 建立标签对象
        guo.setFont(f);
        guo.setForeground(Color.red);
        
        JLabel ben = new JLabel("日本队得分"); // 建立标签对象
        ben.setFont(f);
        ben.setForeground(Color.black);
        
          
        // 日本得分框
        JLabel ri = new JLabel("0");
        ri.setForeground(Color.black);
        ri.setBounds(450, 150, 300, 100);
        ri.setFont(new Font("dialog", 100, 100));
        frame.add(ri);
        
        // 中国得分框
          JLabel z = new JLabel("0");
         z.setForeground(Color.red);
         z.setBounds(100,150, 300, 100);
        z.setFont(new Font("dialog", 100, 100));
        frame.add(z);
        
        //按钮计分
        Font q = new Font("", Font.PLAIN, 40);
        JButton china = new JButton("中国队得分"); 
        china.setForeground(Color.red);
        china.setFont(q);
        china.addActionListener
        (
          new ActionListener() {
            int count=1;            
            public void actionPerformed(ActionEvent e) {                
                            
                z.setText(String.valueOf(count));
                
                if(count>=10) {
                    z.setText("获胜");    
                }
                count++;
            }
        }
        );
        // 建立按钮对象
        JButton japan = new JButton("日本队得分"); 
        japan.setFont(q);
        japan.setForeground(Color.black);        
        japan.addActionListener(new ActionListener() {
            int a=1;
            public void actionPerformed(ActionEvent e) {
                    
                    ri.setText(String.valueOf(a));
                    if(a>=25) {
                        ri.setText("获胜");    
                    }
                    a++;    
            }
        });
        // 设置窗体大小
        frame.setSize(800, 430);                       
        frame.setLocation(700, 400); 
       
        guo.setBounds(10, 0, 500, 100);              
        ben.setBounds(450, 0, 500, 100); 
        
        china.setBounds(0, 300, 400, 100);             
        japan.setBounds(400, 300, 400, 100);           
        
        frame.add(china); 
        frame.add(japan);
        
        frame.add(guo); 
        frame.add(ben); 
        
        frame.setVisible(true); // 设置窗体可见
    }
}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大大大大龙虾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值