4,512,577 th visitor since 2017.2.1 ( Today : 3144 )
Programming
No. 482
Name. swindler
Subject. Sudoku 풀이 #2
Main Cate. Java
Sub Cate.
Date. 2008-10-16 09:44
Hit. 2935 (210.182.190.136)
File.
이것은 스도쿠 데이터를 awt로 화면에 보여주는 프로그램.
내가 볼려고 만든거라 아주 허접하지만
그래도 잘 보인다 ^^


import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

public class DrawSudoku extends JFrame{

    private static int WindowWidth = 180;
    private static int WindowHeight = 180;
    
    private int [][] matrix;
    
    public DrawSudoku(int [][] matrix)
    {
        this.matrix = matrix;

    }
    
    public void draw()
    {
        
        addWindowListener(
                new WindowAdapter() {
         public void windowClosing( WindowEvent e ) {
         System.exit( 0 );
         }
         }
         );
        
        setSize( WindowWidth, WindowHeight+30 );
        setVisible(true);
    }
    
    
    public void paint( Graphics g ) {

        // Draw Background
        g.setColor( Color.white );
        g.drawRect( 0,0,WindowWidth,WindowHeight+30 );
        g.fillRect( 0,0,WindowWidth,WindowHeight+30 );

        // Draw Guide Line
        for(int i=0; i<9; i++) {
            
            if(i%3==0)
                g.setColor(Color.red);
            else
                g.setColor(Color.black);
            
            g.drawLine(0, (WindowHeight/9)*i+25, WindowWidth, (WindowHeight/9)*i+25);
            g.drawLine((WindowWidth/9)*i, 25, (WindowWidth/9)*i, WindowHeight+25);
            
            if(i%3==0) {
                g.drawLine(0, (WindowHeight/9)*i+25+1, WindowWidth, (WindowHeight/9)*i+25+1);
                g.drawLine((WindowWidth/9)*i+1, 25, (WindowWidth/9)*i+1, WindowHeight+25);
            }
        }

        if(matrix==null)
            return;

        // Draw Text
        int x, y;
        g.setColor(Color.blue);
        for(int i=0; i<9; i++) {
            
            for(int j=0; j<9; j++) {

                if(matrix[i][j]!=0) {
                    
                    x=(WindowWidth/9)*i+8;
                    y=(WindowHeight/9)*j+40;
                    g.drawString(""+matrix[i][j], x, y);
                }
            }
        }

    }
    
    public static void main(String [] args)
    {
        DrawSudoku d = new DrawSudoku(null);
    }
    
}


[바로가기 링크] : http://coolx.net/cboard/develop/482



Name
Password
Comment
Copyright © 1999-2017, swindler. All rights reserved. 367,611 visitor ( 1999.1.8-2004.5.26 ), 2,405,771 ( -2017.01.31)

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog