자바 체스 와 중국 장기 판 그리 기

JAVA API 에서 그래 픽 류 를 그 리 는 paint()방법 은 중국 장기 와 체스 의 바둑판 을 쉽게 그 릴 수 있다.코드 참조:
 1.중국 장기 바둑판 코드

import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
public class ChineseChese extends Frame{
 public ChineseChese(){
 setSize(630,630);
 this.setVisible(true);
 addWindowListener(new WindowAdapter(){
 public void windowClosing(WindowEvent e){
 System.exit(0);
 }
 });
 }
 public void paint(Graphics g){
 
 
 Font f=new Font("    ",Font.BOLD,30);
 g.setFont(f);
 int length=60;
 g.drawRect(60, 50,500, 560); //  
 g.drawRect(70, 60, 480, 540);
 /*    */
 for(int i=0;i<9;i++){
 g.drawLine(70, length, 550, length);
 length+=60;
 /*    */
 g.drawString("  ", 130, 350);
 g.drawString("  ",400 , 350);
 }
 length=130;
 /*      */
 for(int i=0;i<7;i++){
 g.drawLine( length,60, length,300);
 length+=60;
 }
 /*      */
 length=130;
 
 for(int i=0;i<7;i++){
 g.drawLine( length,360, length,600);
 length+=60;
 }
 /*         */
 g.drawLine(250, 60, 370, 180);
 g.drawLine(370, 60, 250, 180);
 /*         */
 
 g.drawLine(250, 480, 370, 600);
 g.drawLine(250, 600, 370, 480);
 
 }
 public static void main(String args[]){
 new ChineseChese();
 
 }
}
2.체스 코드 

import java.applet.Applet;
import java.awt.Graphics;
 
public class ChessBoard extends Applet{
 public void init(){
 setSize(400,400);
 this.setVisible(true);
 
 }
 public void paint(Graphics g){
 g.drawRect(20, 10, 320, 320);
 g.drawLine(60, 10, 60, 330); //     ;
 g.drawLine(100,10,100,330); //     ;
 g.drawLine(140, 10, 140, 330); //     ;
 g.drawLine(180, 10, 180, 330); 
 g.drawLine(220,10,220,330);
 g.drawLine(260, 10, 260, 330);
 g.drawLine(300,10,300,330);
 // g.drawLine(340,10,340,330);
 /*    */
 g.drawLine(20,50,340,50); //     ;
 g.drawLine(20,90,340,90);
 g.drawLine(20,130,340,130);
 g.drawLine(20,170,340,170);
 g.drawLine(20,210,340,210);
 g.drawLine(20,250,340,250);
 g.drawLine(20,290,340,290);
 
 /*    */
 g.fillRect(20, 10,40, 40);
 g.fillRect(100, 10,40, 40);
 g.fillRect(180, 10,40, 40);
 g.fillRect(260, 10,40, 40);
 
 g.fillRect(60, 50,40, 40);
 g.fillRect(140, 50,40, 40);
 g.fillRect(220, 50,40, 40);
 g.fillRect(300, 50,40, 40);
 
 g.fillRect(20, 90,40, 40);
 g.fillRect(100, 90,40, 40);
 g.fillRect(180, 90,40, 40);
 g.fillRect(260, 90,40, 40);
 
 g.fillRect(60, 130,40, 40);
 g.fillRect(140, 130,40, 40);
 g.fillRect(220, 130,40, 40);
 g.fillRect(300, 130,40, 40);
 
 g.fillRect(20, 170,40, 40);
 g.fillRect(100, 170,40, 40);
 g.fillRect(180, 170,40, 40);
 g.fillRect(260, 170,40, 40);
 
 g.fillRect(60, 210,40, 40);
 g.fillRect(140, 210,40, 40);
 g.fillRect(220, 210,40, 40);
 g.fillRect(300, 210,40, 40);
 
 g.fillRect(20, 250,40, 40);
 g.fillRect(100, 250,40, 40);
 g.fillRect(180, 250,40, 40);
 g.fillRect(260, 250,40, 40);
 
 g.fillRect(60, 290,40, 40);
 g.fillRect(140, 290,40, 40);
 g.fillRect(220, 290,40, 40);
 g.fillRect(300, 290,40, 40);
 }
중국 장기 바둑판 효과 도

체스 효과 도

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기