Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void paintComponent(Graphics g){
- //Override the default paintComponent method
- super.paintComponent(g);
- //Resize the form to get rid of decimal values to make the tick marks accurate since only integers are accepted
- //Draw the horizontal and vertical axis
- g.drawLine(0, getHeight()/2, getWidth(), getHeight()/2);
- g.drawLine(getWidth()/2, 0, getWidth()/2, getHeight());
- //Create a grid scaled to the current size of the window
- for (int i = 1; i < 20; i++){
- if (i==10) continue;
- //Draw the horizontal ticks
- g.setColor(Color.black);
- g.drawLine(getWidth()/20 * i, getHeight()/2 + 5, getWidth()/20 * i, getHeight()/2 - 5);
- //Draw the vertical ticks
- g.drawLine(getWidth()/2 - 5, getHeight()/20 * i, getWidth()/2 + 5, getHeight()/20 * i);
- }
- }
Add Comment
Please, Sign In to add comment