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); + } +}