From ef93249b915c67ac5a103864ccd2cfaca79f06bd Mon Sep 17 00:00:00 2001 From: bingor_yhj Date: Thu, 29 Sep 2022 16:35:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ETankFrame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/msb/TankDemo.java | 16 +--------------- src/com/msb/TankFrame.java | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 src/com/msb/TankFrame.java diff --git a/src/com/msb/TankDemo.java b/src/com/msb/TankDemo.java index 27eeb6f..ab9dadd 100644 --- a/src/com/msb/TankDemo.java +++ b/src/com/msb/TankDemo.java @@ -1,9 +1,5 @@ package com.msb; -import java.awt.*; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - /** * @Author bingor * @Date 2022-09-29 11:02 @@ -13,17 +9,7 @@ import java.awt.event.WindowEvent; public class TankDemo { public static void main(String[] args) { - Frame frame = new Frame(); - frame.setTitle("Tank war"); - frame.setSize(200, 100); - frame.setResizable(true); - frame.setVisible(true); - frame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); + TankFrame tankFrame = new TankFrame(); } } diff --git a/src/com/msb/TankFrame.java b/src/com/msb/TankFrame.java new file mode 100644 index 0000000..3d49731 --- /dev/null +++ b/src/com/msb/TankFrame.java @@ -0,0 +1,37 @@ +package com.msb; + +import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +/** + * @Author bingor + * @Date 2022-09-29 16:24 + * @Description: com.msb + * @Version: 1.0 + */ +public class TankFrame extends Frame { + + private int x = 200; + private int y = 200; + + public TankFrame() { + setTitle("Tank war"); + setSize(800, 600); + setResizable(true); + setVisible(true); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + super.windowClosing(e); + System.exit(0); + } + }); + } + + @Override + public void paint(Graphics g) { + super.paint(g); + g.fillRect(x, y, 50, 50); + } +}