SHARE
TWEET

Untitled

a guest Sep 8th, 2017 169 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.Graphics; // so that we have a graphics object
  2. import javax.swing.JPanel; // so that we have something to draw on
  3.  
  4. public class DrawPanel extends JPanel // subclass of JPanel, provided in swing above
  5. {
  6.     public void paintComponent(Graphics g) // every JPanel thing needs its own paintComponent
  7.     {
  8.         super.paintComponent( g );  // call JPanel's paintComponent stuff to draw the panel
  9.         int width = getWidth();  // getWidth is part of JPanel.paintComponent
  10.         int height = getHeight(); // ditto - these get width & height of panel
  11.        
  12.         g.drawLine( 0 / 2, 0 / 2 , width, height ); // draw a line from upper left to lower right
  13.         g.drawLine( 0 / 2, height, width, 0 / 2);
  14.     }
  15. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top