import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.*; /** * This is a way to see the 2D Color Array you made in Step 2 of the ASCII Art Lab * @author Chris Thiel, OFMCap * @version 25 Mar 2023 */ public class Step2Tester extends JPanel { private String fileName; private Font titleFont, regularFont; private Color[][] px; private Step2 objectToTest; public Step2Tester(String fileName) { this.fileName = fileName; objectToTest = new Step2(fileName); px = objectToTest.getPx(); titleFont = new Font("Roman", Font.BOLD, 32); regularFont = new Font("Helvetica", Font.PLAIN, 24); } public int getWidth() { return px.length;// width is max x i.e, the max col } public int getHeight() { return px[0].length; // height is the max y, i.ie max row } public void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(Color.WHITE); g.fillRect(0, 0, getWidth(),getHeight()); //g.drawImage(source, 0, 0, null); for (int y=0; y < getHeight(); y++) for(int x=0; x < getWidth(); x++) { g.setColor( px[x][y] ); g.fillRect( x, y, 1, 1); } g.setColor(Color.BLACK);// Use WHITE if the image is dark g.setFont(titleFont); g.drawString(fileName, 20, 40); g.setFont(regularFont); g.drawString ( getWidth() + " by " + getHeight() + "- Drawn from 2DColor Array", 20, 70); } public static void main(String[] args) { Step2Tester pic= new Step2Tester("MyPicture.jpg"); // change this to the picture you picked JFrame window = new JFrame("Step 2 Tester"); window.setSize(pic.getWidth(), pic.getHeight()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.getContentPane().add(pic); window.setVisible(true); } }