Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics; // so that we have a graphics object
- import javax.swing.JPanel; // so that we have something to draw on
- public class DrawPanel extends JPanel // subclass of JPanel, provided in swing above
- {
- public void paintComponent(Graphics g) // every JPanel thing needs its own paintComponent
- {
- super.paintComponent( g ); // call JPanel's paintComponent stuff to draw the panel
- int width = getWidth(); // getWidth is part of JPanel.paintComponent
- int height = getHeight(); // ditto - these get width & height of panel
- g.drawLine( 0 / 2, 0 / 2 , width, height ); // draw a line from upper left to lower right
- g.drawLine( 0 / 2, height, width, 0 / 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement