//Tasha Wallage //Period 7 import java.awt.image.*; import java.awt.*; import javax.swing.*; import java.util.HashSet; import java.util.Iterator; public class Graph extends JPanel { private HashSet data; private Location last; private JFrame frame; private BufferedImage bfi; private Graphics g; private int length = 1000, width = 300; public Graph(JFrame frame) { this.frame = frame; frame.setSize(length,width); frame.setLocation(50,500); bfi = new BufferedImage(length, width, BufferedImage.TYPE_INT_RGB); g = bfi.getGraphics(); g.setColor(Color.black); g.drawRect(0, 0, length, width); data = new HashSet(); last = new Location(0,0); g.setColor(Color.red.brighter()); } public void add(int x, int y) { g.drawLine(last.getX(), width-last.getY(), x, width -y); last = new Location(x, y); repaint(); } public void reset() { g.drawRect(0,0,length,width); repaint(); } public void paintComponent(Graphics g) { g.drawImage(bfi, 0, 0, getWidth(), getHeight(), null); } public static void main(String[] args) { JFrame myFrame = new JFrame("Graph"); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myFrame.setContentPane(new Graph(myFrame)); myFrame.setVisible(true); } }