【汇智学堂】JAVA多线程实现的小游戏-弹球-3

修改Ui

/**
 * 定义界面
 * 显示球板
 * 球板动画
 * 球板对键盘的响应
 */
package com.huizhi;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class Ui extends JFrame {

    static int PositionA=50,RecWidth=50,RecHeight=20,Width=900;

    public Ui(){
            setTitle("弹球游戏");
            setBackground(Color.WHITE);
            setSize(900, 600);
            setLocation(300, 50);
            setResizable(false);
            setVisible(true);
            setDefaultCloseOperation(EXIT_ON_CLOSE);

            this.addKeyListener(new KeyAdapter() {
                @Override
                public void keyPressed(KeyEvent e) {
                    //super.keyPressed(e);
                    JOptionPane.showMessageDialog(null,"1","22",JOptionPane.INFORMATION_MESSAGE);
                }
            });
    public void paint(Graphics g) {
        g.clearRect(0,0,900,600);//0,0:是相对于容器的坐标
        g.setColor(Color.red);
        g.fillRect(PositionA - 50, 450, RecWidth, RecHeight);
      }
    }
发布了268 篇原创文章 · 获赞 47 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_39593940/article/details/103612832
今日推荐