From a36ff772f5c180030f25883f7a63307a66bdb838 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 4 May 2023 11:54:29 -0400 Subject: add rounded rectangle test --- apcs/Driver.java | 2 +- apcs/RoundedRectangleTest.java | 61 ++++++++++++++++++++++++++++++++++++++++++ apcs/block.java | 6 ++++- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 apcs/RoundedRectangleTest.java (limited to 'apcs') diff --git a/apcs/Driver.java b/apcs/Driver.java index a3b4c6c..7b053e4 100644 --- a/apcs/Driver.java +++ b/apcs/Driver.java @@ -12,7 +12,7 @@ public class Driver public static void main(String[] args) { - new Gui(); + new RoundedRectangleTest(); } } diff --git a/apcs/RoundedRectangleTest.java b/apcs/RoundedRectangleTest.java new file mode 100644 index 0000000..e506ec4 --- /dev/null +++ b/apcs/RoundedRectangleTest.java @@ -0,0 +1,61 @@ +package apcs; + +import java.awt.*; +import java.awt.event.*; +import java.awt.geom.AffineTransform; + +import javax.swing.*; + +public class RoundedRectangleTest extends JFrame { + public RoundedRectangleTest() { + setTitle("RoundedRectangle Test"); + setSize(350, 275); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLocationRelativeTo(null); + setVisible(true); + } + public void paint(Graphics g) { + + Graphics2D g2d = (Graphics2D) g; + g2d.setPaint(Color.DARK_GRAY); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + /* + Color holdColor = g2d.getColor(); + g2d.setColor(Color.black); + AffineTransform holdTransform = g2d.getTransform(); + // want the shadow to be one line width pixel offset + float lineWidth = g2d.getStroke() instanceof BasicStroke ? ((BasicStroke) (g2d.getStroke())).getLineWidth() + : 1.0f; + //System.err.println("DrawingUtilities.drawShadowedShape(): lineWidth = "+lineWidth); + g2d.translate(lineWidth, lineWidth); + g2d.fillRoundRect(10, 50, 150, 150, 50, 50); // to draw a rounded rectangle. + g2d.setColor(holdColor); + g2d.setTransform(holdTransform); + */ + g2d.fillRoundRect(10, 50, 150, 150, 50, 50); // to draw a rounded rectangle. + + } + public static void main(String []args) { + new RoundedRectangleTest(); + } + + /*/from www . j av a2 s .c o m + * @param shape the shape to be drawn + * @param g2d the drawing context + */ + public static void drawShadowedShape(Shape shape, Graphics2D g2d) + { + Color holdColor = g2d.getColor(); + g2d.setColor(Color.black); + AffineTransform holdTransform = g2d.getTransform(); + // want the shadow to be one line width pixel offset + float lineWidth = g2d.getStroke() instanceof BasicStroke ? ((BasicStroke) (g2d.getStroke())).getLineWidth() + : 1.0f; + //System.err.println("DrawingUtilities.drawShadowedShape(): lineWidth = "+lineWidth); + g2d.translate(lineWidth, lineWidth); + g2d.draw(shape); + g2d.setColor(holdColor); + g2d.setTransform(holdTransform); + g2d.draw(shape); + } +} \ No newline at end of file diff --git a/apcs/block.java b/apcs/block.java index cf3d31f..ea7663f 100644 --- a/apcs/block.java +++ b/apcs/block.java @@ -23,11 +23,12 @@ public class block { EventQueue.invokeLater(new Runnable() { @Override public void run() { - try { + /*try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } + */ JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -35,6 +36,7 @@ public class block { frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); + } }); } @@ -52,6 +54,7 @@ public class block { return new Dimension(100, 100); } + @Override protected void paintComponent(Graphics g) { super.paintComponent(g); @@ -63,6 +66,7 @@ public class block { g2d.fill(rightEnd); g2d.dispose(); } + } -- cgit v1.2.3