Programming Graphics Format

So, how do we incorporate graphics into our java code?

At this point in Unit 9, the following format will get you started drawing.
You will fill in the red areas with your programming code.
The other items should remain constant, for now.

import java.awt.*;   
import javax.swing.*;

public class
graphicsName extends JPanel
{
     public void paintComponent(Graphics g)
     {
           super.paintComponent(g);
          
g.setColor(Color.green);
           int [ ] x = {75, 150, 120};
           int [ ] y = {75, 140, 50};
           g.fillPolygon(x, y, 3);

     }

     public static void main (String[ ] args)
     {
          
graphicsName d = new graphicsName();
           JFrame f = new JFrame();
           f.add(d);
           f.setSize (
300,300);
           f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           f.setLocationRelativeTo(null);          
           f.setVisible(true);
     }

}

d

divider
Return to Unit Menu |  JavaBitsNotebook.com | MathBits.com | Terms of Use  | JavaMathBits.com

Notice: These materials are free for your on-line use at this site, but are not free for the taking.
Please do not copy these materials or re-post them to the Internet, as it is copyright infringement.
If you wish hard-copies of these materials, refer to our subscription area, JavaMathBits.com.
Help us keep these resources free. Thank you.