Draw Panel


/*
* Class DrawPanel.java
* Author: Tausiq
* B.Sc in CTE (Studying)
* United International University
*/

import java.awt.Graphics;
import javax.swing.JPanel;

public class DrawPanel extends JPanel {

public void paintComponent ( Graphics g ) {

super.paintComponent(g);

int width = getWidth ();
int height = getHeight ();
int temp_width = 0;
int temp_height = height;

while ( temp_width < width ) { g.drawLine(0, 0, temp_width, temp_height); temp_width += 15; temp_height -= 15; } temp_width = 0; temp_height = 0; while ( temp_width < width ) { g.drawLine(0, height, temp_width, temp_height); temp_width += 15; temp_height += 15; } temp_width = 0; temp_height = 0; while ( temp_width < width ) { g.drawLine(width, 0, temp_width, temp_height); temp_width += 15; temp_height += 15; } temp_width = 0; temp_height = height; while ( temp_width < width ) { g.drawLine(width, height, temp_width, temp_height); temp_width += 15; temp_height -= 15; } } } [/sourcecode] [sourcecode language='java'] /* * Class DrawPanelTest.java (executable) * Author: Tausiq * B.Sc in CTE (Studying) * United International University */ import javax.swing.JFrame; public class DrawPanelTest { public static void main(String[] args) { DrawPanel panel = new DrawPanel (); JFrame a = new JFrame (); a.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); a.add(panel); a.setSize(250, 250); a.setVisible(true); } } [/sourcecode]

2 thoughts on “Draw Panel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s