Choose a job you love, and you will never have to work a day in your life.
- Confucius
News
Site News
Latest Comments
Affiliates
Proxies
Contribute!
Tutorials
Newest Articles
Most Popular
Highest Rated
Latest Comments
Code Samples
Newest Code
Most Popular
Highest Rated
Latest Comments
Blogs
Admins Blog
Newest Blogs
Most Popular
Highest Rated
Latest Comments
Forums
Latest Posts
Latest Topics
Memberlist
[login]
|
[Register]
chessboard
by: javabhai
Description:
The code displays a standard chess board in a frame taking advantage of Graphics in JAVA. Needless to say, it should be stored in a file named "chessboard.java"
Code:
/* * chessboard.java * * Created on August 2, 2008, 12:37 PM */ import java.awt.*; import java.awt.geom.*; import javax.swing.*; /** * * @author Administrator */ public class chessboard { public static void main(String[] args) { DrawFrame frame = new DrawFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); } } /** A frame that contains a panel with drawings */ class DrawFrame extends JFrame { static int one_for_all=700; //decides the width and heigth ofthe frame Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); public int screenHeight = screenSize.height; public int screenWidth = screenSize.width; public DrawFrame() { setSize(FRAME_WIDTH, FRAME_HEIGHT); // center frame in screen setLocation(screenWidth / 4, screenHeight / 4); setResizable(true); setTitle("A Standard Chess Board"); setUndecorated(false);//try changing TRUE | FALSE /*The title bar, title, frame border, close(X) button everything will be removed What you will see will just be a plain frame,a plain area. */ // add panel to frame DrawPanel panel = new DrawPanel(); Container contentPane = getContentPane(); contentPane.add(panel); } public static final int FRAME_WIDTH = one_for_all; public static final int FRAME_HEIGHT = one_for_all; } /** A panel that displays rectangles and ellipses. */ class DrawPanel extends JPanel { public void paintComponent(Graphics g) { DrawFrame frame = new DrawFrame(); int XXX=25;//x coordinate of the point where drawing starts int YYY=25;//x coordinate of the point where drawing starts System.out.println(XXX); int co_x=XXX; int co_y=YYY; int no=8; // value of no should be at the most frameSize/10 int size=80; //size of each box boolean flag=false; setBackground(new Color(80,40,40)); super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; for(int j=0;j
No Comments for this page.
You Must be
signed in
or a
member
to comment.
Code Stats
845
Views
0
Total Comments
0
Rating of 5 (
Votes)
Code Options
·
Login to Rate This Code
·
Login to Post a Comment
·
Read more by this author
Related
·
Hello World Program
Your Code Here
Bankruptcy
-
Debt Consolidation
-
Credit Card Consolidation
-
Loans
"AllSyntax.com" Copyright © 2002-2007; All rights lefted, all lefts righted.
Privacy Policy
|
Internet Rank