Draw a grid(different)

Hi,
I am trying to draw a circular grid, i.e. like a dartboard, where each ring is split into a number of parts.
So far I have managed to do that by drawing an image of the board. This creates other problems like reading mouse clicks,scaling, and placing components in correct coordinates.
I can provide more info. Thank you

This kinda solves my problem
for(int i = 0; i < 8; i++)
               g2d.draw(new Ellipse2D.Double(i*45, i*45,
                    getWidth()-(2*i*45),
                    getHeight()-(2*i*45)));
for(int i = 0; i < 24; i++)
               double temp = Math.toRadians(i*15);               
               Line2D line = new Line2D.Double(getWidth()/2,getHeight()/2, getWidth()/2,0);
               g2d.draw(line);               
               at.rotate(Math.toRadians(15),(getWidth()/2), (getHeight()/2));
               g2d.setTransform(at);
}This draws the grid. Now if I want to place something or read a click my best bet is:
x = a + r cos(t)
y = b + r cos(t)
So a code of this sort:
Point point = new Point((int)(center.x+(getWidth()/2)*Math.cos(temp)),
                         (int)(center.y+(getHeight()/2)*Math.sin(temp)));Will produce results slightly different from the actual drawing.
Thanks again for the help

Similar Messages

  • Draw images in different Panels

    Hi,
    I have a JFrame with three JPanels.
    How can I draw three different Buffered images to those three JPanels?
    Code is appreciated.

    devboris wrote:
    Hi,
    I have a JFrame with three JPanels.
    How can I draw three different Buffered images to those three JPanels?Do you know how to draw one BufferedImage in one JPanel? If not, start there.
    Code is appreciated.An [SSCCE |http://sscce.org] is appreciated.

  • Excel drawing shape shown differently in 2 computers

    anyone encounter drawing shape missing in  excel? open the excel in 2 different computer but shown differently. tried to start excel in safe mode but still the same.
    the correct one:
    https://www.dropbox.com/s/7g3e8d5oydgabiz/correct%20.png?dl=0
    the wrong one:
    https://www.dropbox.com/s/efupyzsh15m7tzf/wrong.png?dl=0

    Hi,
    In regarding of the issue, please provide us more information to assist you better.
    Which Office version are you using with the two pcs?
    Do the two pcs have the same operation system and software environment?
    Based on my test with my local environment (Window 8.1 & Excel 20013; Windows 7 & Excel 2007/2010), I recreate some sample drawing like you provided, but I could not reproduce your issue.
    General speaking, if you are using the different Office version with the 2 pcs, the Excel file might display differences, because there also might be some compatibility issues.
    I recommend we try the following steps to narrow down the issue:
    First, open the file with third pc that installed the same Excel version with correct pc if possible.
    If the file display correctly, we'd better focus on the wrong pc (Second pc).
    Then, we may try the following methods and check they are helpful.
    Update the Office/Windows patches.
    Repair Office.
    Update the display card drive
    Next, if this issue still exists or could not open it with third pc, I recommend you upload the sample file through OneDrive, I want to download and test it.
    Regards,
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Drawing String In Different Colors

    Hi!
    I need to do the following. Using DrawString method, I need to make a special character, each time it appears in string, invisible(but not to remove it from string). So I decided to draw it in a background color(If you know some other way to hide it, please share it with me). But other letters should be in foreground colors. How can I define only that letter in different(background) color?
    If you understood my problem, please help me to solve it.

    This program will do it :
    import java.awt.event.*;  
    import java.awt.*;
    public class DrawS extends Frame
    public DrawS()
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);
         setBounds(50,50,450,400);
         setBackground(Color.lightGray);
         setForeground(Color.red);
        setVisible(true);
    public void paint(Graphics g)
         super.paint(g);
         String s = "this is a string";
         char   c = 'i';
         g.drawString(s,50,50);
         FontMetrics fm = getFontMetrics(g.getFont());
         int x = 50;
         for (int j=0; j < s.length(); j++)
              if (s.charAt(j) == c) g.setColor(getBackground());
                   else              g.setColor(getForeground());
              g.drawString(s.substring(j,j+1),x,100);
              x = x + fm.charWidth(s.charAt(j));
    public static void main(String[] args )
         new DrawS();
    Noah

  • How to draw image in different dpi?

    I wonder is there any approach can be used to draw a image in different dpi, such as 144dpi, in a JPanel?
    'cause my image processed from other tools is not good, if I can draw image in a high dpi, then the image will looks much better, though the image becomes smaller.
    Note: no SCALE!

    I have a image which is 152dpi, then, how does the Widows draws this image? It looks much better than scale the 72dpi image to the same size.
    Really puzzled-_-                                                                                                                                                                                                                                                                                                                               

  • Fastest way to draw a grid

    What is the best or quickest way to draw the walls on PacMan
    Making the game pacman and wondering is there a fast way to draw the board...
    instead of loads of lines saying
    g.drawLine(......);

    Uh, I was asking if there was another way...
    fillrect/drawrect are the only other ways to do it
    lol... and I've tried Graphics2D.How about drawOval or drawPolygon (doubt that)?
    >
    I was wondering if there was maybe another class/set
    of functions... etc?You could drop down to some native library like DirectX or OpenGL or some such, but I don't know of any other way to paint the screen with Java. (but then, I'm certainly not a "screen painting" sorta guy, so take that for what it's worth)

  • Draw Text2D in different points

    hello,
    how do i draw a Text2D in points that are not (0,0,0)?
    thanks,
    ifat

    append a transform above it in the heirarchy?
    your question is abit vague though, i might be mis-understanding
    rob,

  • Cell border manipulation

    hi,
    i want to change the width of a jTable's columnborder. do i have to write a own border class or can i manipulate the default border in some way?
    thanx for help,
    mischa

    I seem to remember someone talking about extending the BasicTableUI class to draw the grid differently, but it doesn't seem like that would be as straightforward. You might look into it and see.

  • Java applet to draw grid

    Hi, I have an exam Tuesday and an assignment Ive done before is to draw a chessboard pattern, but a past question has been to draw a grid pattern with red horizontal lines and blue vertical ones.
    It must display an input dialog asking the user how many lines to draw along each side and the pattern should size itself to fit exactly with the applet area.
    It says to use setColor(Color c) and fillRect(x1,y1,x2,y2): draws lines between (x1, y1) and (x2,y2)
    Here's my code for the chessboard:
    import java.awt.*;
    import java.applet.*;
    public class Q2_chessboard extends Applet {
         public void paint(Graphics g)
              int row, column, x, y;
              //for every row on the board
              for (row = 0;  row < 8;  row++ )
                   //for every column on the board
                   for (column = 0;  column < 8;  column++)
                        //Coordinates
                        x = column * 20;
                        y = row * 20;
                        //square is red if row and col are either both even or both odd.
                        if ( (row % 2) == (column % 2) )
                             g.setColor(Color.red);
                        else
                             g.setColor(Color.black);
                        g.fillRect(x, y, 20, 20);
    }But Ive tried for ages and cant turn this code into the code needed for the past question.
    I know I have to use:
              //Gets size of Applet
              int appletHeight = getSize().height;
              int appletWidth = getSize().width;But cant wrap my head around it where to use it.
    I had replaced the numerical values of row and column with
              input = JOptionPane.showInputDialog("Enter number lines to draw on each side:");
              lines = Integer.parseInt(input);but it came asked twice and I couldnt expand the applet without it asking for input again.

    Came up with this:
    import java.awt.*;
    import java.applet.*;
    import javax.swing.JOptionPane;
    public class VertLines extends Applet {
         public void paint(Graphics g)
              String input;
              int lines;
              input = JOptionPane.showInputDialog("Enter number of lines to draw on each side:");
              lines = Integer.parseInt(input);
              int horizontal, vertical, x, y;
              //Gets size of Applet
              int appletWidth = getSize().width;
              int appletHeight = getSize().height;
              //for every horizontal on the board
              for (horizontal = 0;  horizontal < lines;  horizontal++ )
                   //Coordinates
                   y = horizontal*(appletWidth/10);
                   g.setColor(Color.red);
                   g.drawLine(0, y, appletWidth, y);
              for (vertical = 0;  vertical < lines;  vertical++ )
                   //Coordinates
                   x = vertical*(appletHeight/10);
                   g.setColor(Color.blue);
                   g.drawLine(x, 0, x, appletHeight);
    }Doesnt really do 'exactly' what I want but its the closest ive gotten and ive had to use two different loops and drawLine instead of drawRect.
    The input dialog still comes up twice too.

  • Draw Grid in Illustrator

    hi guys,
    1 - Do you know which is the best way to draw a grid like that in Illustrator?
    http://www.pixentral.com/show.php?picture=1ub1FOws8ZpNjfaWuKSTIOpkSeMN7V
    Sometimes i did drew something like it and when i apply the outline view, the node points are not in the same line. I guess i might have to make an isometric grid...
    2 - The idea is to use this grid later on as a pattern to fill shapes like rectangles or circles. Which is the best way to do it?
    thanks for any ideas,
    Sebastiao

    Jet, that is a marvelous drawing!
    So if i understand right you draw the red or the yellow lines and then how you convert it to a pattern? Is that symbol palette?
    Thanks for the good info and regards!
    Sebastiao

  • Drawing a warped grid in perspective???

    Now...... i know how to use the perspective tool and i understand that i can draw a grid onto this but the grid always seems to be out of whack when i do and the line spacing isn't at all perfect.  What i want to be able to do is draw a grid with equal spacing and have the ability to warp this so it looks all bent up going off into the distance.
    I can see this is going to be something that i have to draw in manually but i'm kind of hoping that i can have the bulk of the job done for me. 
    However, if i do have to draw it manually, how would i go about spacing the lines equally along a wafty curved line???

    Actually, upon playing about with this, i seem to have got exactly wat i was after    Thanks a lot

  • How to draw grid?

    I want to draw a grid in an application. how do i do that?
    I want to use a efficient & effective way of doing it.
    I was thinking along the lines of drawing a 2D rectangle and draw horizontal/vertical lines in position to make up the grid. (this probably would be a hard coded way)
    would above work then?
    Any ideas?

    I was thinking along the lines of drawing a 2D rectangle and draw horizontal/vertical lines in position to make up the grid. (this probably would be a hard coded way)
    would above work then?Yes, this will work. Give it a try.
    You should also store a variable like gridX and gridY that you can change. These variables specify the amount of desired grid lines in the x and y direction. Then at draw time, based on the width and height of the component you caculate the interspacing betwen lines required to meet your desired # of lines and draw accordingly.

  • How to interactive-draw on a grid?

    Hello!
    Imagine you had set up a grid based on little 1x1px boxes.
    Wouldn’t it be cool to take your Wacom-Pen and simply color the boxes the way you’d love to?
    You could simply set up a solid brush matching your needs …no matter if it’s 1x1 px thin. …or 1000x1000 px heavy.
    You could create sharp edged drawings in beautiful colors.
    Well, that’s pretty the kind of set-up I’m looking for.
    But instead of that solid look, I get shades or halftones even if my brush is set to 1px.
    Anyone an idea how to create a sharp-edged brush-set-up?
    Any hints would be much appreciated
    G

    how about making a grid of actual 1px X 1px squares...
    Yes, and one could use the Rectanglular Grid tool to create the grid and not mess with snaps or the document grid at all. And using that method, there would be no reason to draw the grid to a measure of 1 "pixel" (1 point) at all. At that size, you would have to zoom in to see what you're doing and zoom out to see what the finished results will look like at "actual size."  So instead, you could draw the grid of squares to any arbitrary scale, flood fill them, and then scale the results to the desired vector-squares-per-inch size.
    But (beside the pointlessness of the whole exercise, which I hope is becoming evident) that does not satisfy G's desire to use a pressure-sensitive Wacom stylus to interactively adjust the fatness of his swipes.
    Functionally, what G desires is exactly what any ordinary bitmap program (assuming pressure-sensitivity support) does and has been doing for decades, when painting at low res or high zoom with antialiasing turned off (or some other means which disallows it, such as painting in limited index color mode).
    What G is failing to realize is that drawing a mosaic of vector squares is essentially the same thing as coloring aliased pixels. A pixel is essentially a call for a colored square. You can scale and rotate that raster pixel every bit as much as you can scale and rotate a vector square. In other words, by wanting his vector drawing to consist of nothing other than squares, he is essentially desiring to circumvent the resolution-independent rasterization of vector drawing.
    So G may argue, "But James, by drawing with vector paths, I can have adjustability of the array of squares! If only I had the new kind of pressure-sensitive brush I want, I could reshape the spine path which auto-generates the array of squares!"
    And I would answer: Yes. But that's exactly what you would have if you simply turned off antialiasing and used any of the existing Brushes (and/or any of the other drawing tools, like the Blob tool), and otherwise used those tools normally. Getting a "scaleable" version of the artwork with the desired number of "squares" is a simple matter of zooming (thereby controlling the number of rows/columns of squares) and taking a screen capture (because, as demonstrated, scaling an aliased raster image is for most practical purposes functionally equivalent to scaling an array of vector squares).
    If you want to see how many "squares" are created as you draw, you could even use a screen magnification utility, like the Magnifier built into Windows. But in practice, that's rather antithetical to the notion of pressure-sensitivity; you don't really want to "count pixels" as you go with an interactively pressure-sensitive "painting" tool.
    So again; the whole idea is so much like just wanting to make Illustrator act exactly like what any aliased painting method does in even the cheapest raster program, that it raises the question, "Why reinvent the wheel?" Just use a paint program--or turn off antialiasing and take a screen shot, and you've got the "new feature" that you want, without hoping and waiting for Adobe to ever add such a (frankly quite dubious) feature.
    In a nutshell, the primary intent and purpose of the resolution independence of vector drawing is to avoid the aliasing inherent in raster imaging--exactly what G now wants to preserve. So simply use raster imaging, and you'll have your aliased artwork, and it will be scaleable.
    There's no need to re-invent the square wheel. The square wheel is easy. The whole purpose of vector drawing is to avoid square wheels. If you want square wheels, you don't need vector squares.
    JET

  • Turning a Grid Drawing Panel Into a JavaBean

    Hello,
    I've written a class for drawing a grid in which a user can draw shapes. I want to implement it into my GUI that I've built using the Netbeans GUI builder and it seems the most straightforward way (or so I thought!) was to create it as a JavaBean. I've read the JavaBean tutorial but it seems a little unclear apart from for the creation of the simple bean. I've also had a look at the conventions on wikipedia and modified my class several times to try and get it to be accepted as a JavaBean but with no luck. Are there any other sources of info I could use?
    Thanks,
    Nick

    (Thanks for helping me!) Woops! I forgot about this thread.
    Well anyway, this is one way. There might be a better way.
    Good luck!
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class GridPanelTest{
    public static void main(String[] args){
         new GridPanelTest();
    public GridPanelTest(){
         panel = new GridPanel();
         frame = new JFrame();
         frame.setContentPane(panel);
         frame.setSize(500, 500);
         frame.setLocationRelativeTo(null);
         frame.setVisible(true);
    public class GridPanel extends JPanel{
    public GridPanel(){
         this.setBackground(Color.WHITE);
    public void paintComponent(Graphics g){
         super.paintComponent(g);
         Graphics2D gfx = (Graphics2D)g;
         gfx.setRenderingHint(     RenderingHints.KEY_ANTIALIASING,
                                       RenderingHints.VALUE_ANTIALIAS_ON);
         gfx.setStroke(thick);
         gfx.setPaint(Color.RED);
         for(int i = 0; i < numRows; i++){
         int pos = (int)(((double)this.getHeight() / (double)numRows) * (double)i);
         gfx.drawLine(0, pos, this.getWidth(), pos);
         for(int j = 0; j < numColumns; j++){
         int pos = (int)(((double)this.getWidth() / (double)numColumns) * (double)j);
         gfx.drawLine(pos, 0, pos, this.getHeight());
         int numRows = 4;
         int numColumns = 3;
         BasicStroke thick = new BasicStroke(2);
         JFrame frame;
         GridPanel panel;
    }

  • Different versions of animated image in single swf file

    I am making a game which has several objects (beds, crates, tables) that can be placed on a grid.
    The objects are created in flash and exported as individual .swf files. Each object can be rotated. To do this I create 4 frames in each .swf and draw a different version of the image in each frame. This allows me to 'rotate' an object in actionscript by simply going to the next frame of the swf movieClip.
    This simplifies things a lot for me, as it follows logically that an object will have one image file (swf) for all orientations. However, I've hit a problem in that I would like the object to have an animation. Does anyone know if there is a way to do this? or perhaps another technique I could use.

    I think It's best to explain with an example. Let's say I have a television that I draw in four different frames with different rotations. The first frame has the television facing in a south west direction. The 2nd frame has a south east facing television and so on. This is what I have at the moment. What I'm wanting to do next is add an animation to the television, e.g. display something moving on the screen.

Maybe you are looking for

  • JVM Error 517 cause?

    Hey, quick question. Yesterday after turning my phone on i got that JVM Error 517 message, after looking on here i found a solution to fix it (you brainy people!), turned out it had no software so its all fixed now, my question is what causes it? I w

  • Weird naming inconsistency with imported library

    I have managed my mp3's on the PC with iTunes for years and migrated them to my MBP. I never had iTunes manage the files as I also have other PC tools to play the files, so folder and naming stucture were important. Can anyone explain what 'rule' is

  • System crashes while capturing in CS5

    Recently installed Samsung Kies software for supporting my Galaxy cell phone. Same day Win7 started crashing while capturing video in Premiere Pro CS5. It crashes after random number of minutes capturing. There's no problem with any other aplication,

  • Try to download some files from cd but when I run the file the icon says

    Hi. I need help. I am trying to install a software from a cd but when I run the cd to my mac pro, the icon that I have to click to install the software has the extension .exe and when I click on this it asks me to choose application. The icon is diff

  • [SOLVED] Banshee won't start up entirely (high CPU, no window)

    Whenever I start Banshee, it starts a process and runs up the CPU use but a window never shows up. When I start Banshee from the command line, all I get is this output. [Info 17:31:49.010] Running Banshee 2.0.1: [ArchLinux (linux-gnu, x86_64) @ 2011-