Results 1 to 3 of 3
  1. #1
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default Can you run this code and tell me what would cause missing graphic data like this?

    If you are familier with a guitar chord diagram then you will see what I am talking about.
    Sorta Like This.... click here


    Java Code:
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    
    public class ChordGrid extends JFrame {
    
    	PrintPreviewTest printPreviewTest = new PrintPreviewTest();
        ChordGrid() {
        	super("Gridy Grid Grid");
        	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        	this.add(printPreviewTest);
        	this.setSize(545, 720);
        	setVisible(true);
        }
    
        public static void main(String[] args) {
        	new ChordGrid();
        }
    }
    
    class PrintPreviewTest extends JPanel {
    
    	BufferedImage diagram;
    	private final int DPI = 72, UNIT = 12, PAPER_X = 612, PAPER_Y = 792;
    	private int strings = 6, frets = 4;
    	private BufferedImage[][] chordImageGrid = new BufferedImage[3][3];
    	boolean[][] dChord, aChord, eChord;
    
    	public void setTheSize() {
    		setPreferredSize(new Dimension((int)(10.5 * DPI), 13 * DPI));
    	}
    
    	PrintPreviewTest() {
    
    		dChord = new boolean[6][5];
    		aChord = new boolean[6][5];
    		eChord = new boolean[6][5];
    
    		dChord[2][0] = true;
    		dChord[3][2] = true;
    		dChord[4][3] = true;
    		dChord[5][2] = true;
    
    		aChord[1][0] = true;
    		aChord[2][2] = true;
    		aChord[3][2] = true;
    		aChord[4][2] = true;
    
    		eChord[0][0] = true;
    		eChord[1][2] = true;
    		eChord[2][2] = true;
    		eChord[3][1] = true;
    		eChord[4][0] = true;
    		eChord[5][0] = true;
    
    		setChordImage(eChord, 0, 0);
    		setChordImage(aChord, 1, 0);
    		setChordImage(dChord, 2, 0);
    		setChordImage(eChord, 0, 1);
    		setChordImage(aChord, 1, 1);
    		setChordImage(dChord, 2, 1);
    		setChordImage(aChord, 0, 2);
    		setChordImage(dChord, 1, 2);
    		setChordImage(eChord, 2, 2);
    	}
    
    
    
    	private void setChordImage(boolean[][] chordData, int gx, int gy) {
    		diagram = new BufferedImage(UNIT*13, UNIT*18, BufferedImage.TYPE_INT_ARGB);
    		Graphics2D g2d = diagram.createGraphics();
    
    		g2d.setPaint(Color.BLACK);
    
    		for(int col = 0; col < strings; col++) {
    			for(int row = 0; row <= frets; row++) {
    				//Draw Strings
    				g2d.drawLine((int)(UNIT*1.5 + UNIT*col*2), UNIT*2, (int)(UNIT*1.5 + col*2*UNIT), (int)(UNIT*2 + frets*UNIT*3.5));
    				//Draw Frets
    			 	g2d.drawLine(UNIT, (int)(UNIT*2 + UNIT*row*3.5), UNIT*12, (int)(UNIT*2 + UNIT*row*3.5));
    
    
    			 	//Draw Fretted Notes
    
    			 	// ****** Even With This Commented Out it still draws the grid WRONG
     			 	if (chordData[col][row]) {
     			 		g2d.fillRect((int)(UNIT*.8+UNIT*2*col), (int)(UNIT*3.3*row), (int)(UNIT*1.5), (int)(UNIT*1.5));
    				}
    				// ****** Even With This Commented Out it still draws the grid WRONG
    			}
    		}
    
    		chordImageGrid[gx][gy] = diagram;
    	}
    
    
    	public void paintComponent(Graphics g) {
    
    		super.paintComponent(g);
    		this.setBackground(Color.darkGray);
    
    		Graphics2D g2 = (Graphics2D) g;
    		g2.translate(5, 5);
    		g2.scale(.85, .85);
    
    		g.setColor(Color.WHITE);
    		g.fillRect(0, 0, 612, 792);
    
    		//Create 3x3 Grid
    		g.setColor(new Color(230, 230, 230));
    		int gridRow = 3, gridCol = 3;
    		for(int row = 0; row < gridRow; row++) {
    			for(int col = 0; col < gridCol; col++) {
    				g.drawRect(DPI + (col * (13*UNIT)), DPI + (row * (18 * UNIT)), 13 * UNIT, 18 * UNIT);
    
    			}
    		}
    
    		//Place Chord Dagram
    		g.setColor(Color.BLACK);
    		for(int row = 0; row < gridRow; row++) {
    			for(int col = 0; col < gridCol; col++) {
    				g2.drawImage(chordImageGrid[col][row], null, DPI + (col * (UNIT*13)), DPI + (row * (UNIT * 18)));
    
    			}
    		}
    	}
    }

  2. #2
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default

    It looks like its due to you using the scale() method. Commenting it out, all the lines draw fine. So the lines you are drawing are getting scrunched out by the scaling.

  3. #3
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

Similar Threads

  1. Replies: 4
    Last Post: 01-30-2011, 12:18 AM
  2. Using Tokenizer to parse file data--CODE
    By Cylab in forum Java Software
    Replies: 0
    Last Post: 07-26-2010, 12:48 PM
  3. Graphic library
    By xeannart in forum Advanced Java
    Replies: 6
    Last Post: 07-14-2008, 03:36 AM
  4. data structure code
    By vgvt in forum New To Java
    Replies: 1
    Last Post: 01-17-2008, 03:49 PM
  5. Basic Graphic
    By jkswebsite in forum Java 2D
    Replies: 6
    Last Post: 11-26-2007, 03:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •