From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing2902.java | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing2902.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing2902.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2902.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2902.java new file mode 100644 index 0000000..be57239 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2902.java @@ -0,0 +1,69 @@ +/* Listing2902.java */ + +import java.awt.*; +import java.awt.event.*; + +class ComponentRepaintAdapter +extends ComponentAdapter +{ + public void componentMoved(ComponentEvent event) + { + event.getComponent().repaint(); + } + + public void componentResized(ComponentEvent event) + { + event.getComponent().repaint(); + } +} + +class BirdsEyeFrame +extends Frame +{ + public BirdsEyeFrame() + { + super("BirdsEyeFrame"); + addWindowListener(new WindowClosingAdapter(true)); + addComponentListener(new ComponentRepaintAdapter()); + setBackground(Color.lightGray); + } + + public void paint(Graphics g) + { + Dimension screensize = getToolkit().getScreenSize(); + Dimension framesize = getSize(); + double qx = framesize.width / (double)screensize.width; + double qy = framesize.height / (double)screensize.height; + g.setColor(Color.white); + g.fillRect( + (int)(qx * getLocation().x), + (int)(qy * getLocation().y), + (int)(qx * framesize.width), + (int)(qy * framesize.height) + ); + g.setColor(Color.darkGray); + g.fillRect( + (int)(qx * getLocation().x), + (int)(qy * getLocation().y), + (int)(qx * framesize.width), + (int)(qy * getInsets().top) + ); + g.drawRect( + (int)(qx * getLocation().x), + (int)(qy * getLocation().y), + (int)(qx * framesize.width), + (int)(qy * framesize.height) + ); + } +} + +public class Listing2902 +{ + public static void main(String[] args) + { + BirdsEyeFrame wnd = new BirdsEyeFrame(); + wnd.setSize(300,200); + wnd.setLocation(200,100); + wnd.setVisible(true); + } +} \ No newline at end of file -- cgit v1.2.3