Results 1 to 3 of 3
- 03-03-2011, 06:05 PM #1
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
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))); } } } }
- 03-03-2011, 06:39 PM #2
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.
- 03-03-2011, 06:55 PM #3
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Similar Threads
-
Tokenizer with data validation for missing text
By dug in forum New To JavaReplies: 4Last Post: 01-29-2011, 11:18 PM -
Using Tokenizer to parse file data--CODE
By Cylab in forum Java SoftwareReplies: 0Last Post: 07-26-2010, 11:48 AM -
Graphic library
By xeannart in forum Advanced JavaReplies: 6Last Post: 07-14-2008, 02:36 AM -
data structure code
By vgvt in forum New To JavaReplies: 1Last Post: 01-17-2008, 02:49 PM -
Basic Graphic
By jkswebsite in forum Java 2DReplies: 6Last Post: 11-26-2007, 02:19 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks