Draw line and shapes

I have a small problem...cos i have like one class that extends JFrame but i have one JPanel on which i would like to draw some shapes...but i dont know how...cos i tried to rewrite paint method but it does not work...if someone would please post me a simple example...on how to do that...thnx

This is slightly barebones, but it should do. It also has some less relevant code. Here's my JFrame (or the interesting parts):
public class MainWindow
     extends JFrame
     private PaintLayout layout;//My custom Layout, not required
     private Container c;
     public MainWindow()
          //Bind the layout and Container c for future use
     layout = new PaintLayout();
     c = getContentPane();
     c.setLayout(layout);
//These are useful if you want to know what space is getting chopped out
     it = c.getInsets().top;
     ib = c.getInsets().bottom;
          il = c.getInsets().left;
          ir = c.getInsets().right;
     GameBoard board = new GameBoard();
layout.addLayoutComponent(board, 0+il, 0+it, 720, 480);//Custom add function for my custom Layout
c.add(board);//Very useful and important
Followed by the code of interest in my JPanel:
public class GameBoard
     extends JPanel
     implements MouseListener, MouseMotionListener
     public GameBoard()
          this.addMouseListener(this);
          this.addMouseMotionListener(this);
     public void paint(Graphics g)
g.setColor(new Color(0, 127, 0));
g.fillRect(0,0,this.getWidth(),this.getHeight());
     public void mouseClicked(MouseEvent arg0)
          int x = arg0.getX(), y = arg0.getY();
          System.out.print("X: "+x+" Y: "+y+"; X: "+x/10/12+"'"+(x/10)%12+"\" Y: "+y/10/12+"'"+(y/10)%12+"\";\n");
Have fun with that.

Similar Messages

  • Line and shape controls

    Where can I can the line and shape tools that are missing from my list of controls. Using Google and Microsoft site, I see there are "Power Packs". I found and downloaded the PowerPack 3, and the next time I start VS 2013 I get a long list of
    files flashing by on my screen, too fast to read. But I still don't have any reference to line or shape controls that I can find. I am uncomfortable about what this process has added to and changed on my system. Should I just re-install VS and try again?

    Where can I can the line and shape tools that are missing from my list of controls. Using Google and Microsoft site, I see there are "Power Packs". I found and downloaded the PowerPack 3, and the next time I start VS 2013 I get a long
    list of files flashing by on my screen, too fast to read. But I still don't have any reference to line or shape controls that I can find. I am uncomfortable about what this process has added to and changed on my system. Should I just re-install VS and try
    again?
    Possibly you didn't add shape tools from Choose ToolBox Items after you installed Visual Studio 2013 initially as all toolbox items are not automatically in the toolbox since they do not all need to be used commonly. Although you don't mention which VS 2013
    you installed and I've seen issues where Express versions either do not appear to come with PowerPacks or did not appear to come with PowerPacks at some earlier point in time which may have been resolved. It's also possible earlier releases of other versions
    of VS 2013 did not come with them. Because for some point in time people questioned about some VS 2013 Express versions as well as the Pro and I believe Ultimate versions not having powerpacks available so I used to provide links for version 12.0 for them
    which were at Microsoft but you couldn't find that link by searching at Microsoft downloads for some reason. I just happened to find it in some thread once when assisting somebody with that issue.
    Although as
    Jack-Zhai mentions PowerPack versions should be provided to Visual Studio which are for the version of Visual Studio you are using. It's probably a good idea to remove powerpack 3 although trying to find powerpack 12.0 doesn't seem very easy without a great
    deal of searching. And I'm not certain for a version of Visual Studio how to find out which rev of PowerPacks should be used with it.
    La vida loca

  • Draw lines and columns button was disabled

    hi friends,
    in my smartform template draw lines and columns button was disabled which results select pattern button also disabled. now i am unable to change any lines, can any one help me how to enable this button to change.
    thanks and regards,
    venkat suman.

    Hi
    I come to the same problem and google lead me here.
    Not the problem of Display/Change mode or authorization.
    I fix this problem as below:
    1) create a new smartform and create a template
    2) click the "Settings" button
    3) in tab General, check the "Draw Lines and Columns", click OK
    4) exit without saving
    5) now I can use the "Draw Lines and Columns" button
    but here when I click the Settings button again, the "Draw Lines and Columns" is unchecked.
    Hope this can help
    May some mentor give an explanation.

  • Draw lines and columns button is disbaled inde template

    Hi all,
    Im developing a custom smartform with a template.
    Now in the template,Draw lines and columns button is disbaled .How do i enable it.Also all the "SELCT PATTER" buttons are also disabled.

    Go to settings->table painter->select the required ones.

  • Optimizer erases lines and shape boxes from PowerPoint pdf

    Hi,
    I am on a MacBook Pro running 10.5.8, using Powerpoint 12.2 for Mac, with Adobe Acrobat 9.
    I have saved a pdf of a PowerPoint file with many pictures for distribution.
    When I attempt to reduce file size or optimize the file, Optimizer erases all line art and outlines of box shapes. I have tried every setting under Images in Optimizer and run the optimizer on color, grayscale and monochrome in every combination and get the same result. I am only running the Image optimizer.
    Alternately, when I also check Transparency, it keeps the line art but changes all fonts in ever text box to gibberish.
    There appears to be no guidance anywhere on the web for this problem. Please help!
    Thanks!

    Try "Press Quality" Acrobat 5 compatable setting for "live" transparency.  You can also try PDF/X-4 2008 which maintains live transparency and, in CS4, maintain Acrobat 5 compatability.  PDF-X1 is a setting that "flattens" transparency which may limit your output options, depending on final output device.  Double check your raster settings and make sure it is set for 300ppi/2400dpi and not 72ppi/300dpi.  As suggested by Wade, your printer may not be a Postscript Level 3 output device with a RIP.  So, the driver may not be screening the artwork properly and the stitching shows up in output.  You may benefit from taking the file to a prepress shop and have them output a "contract" proof.  If the stitching shows up in the contract proof, then the PDF setup may be the problem or the original file itself.

  • Need to draw line after the 2nd line item(Smart Forms)

    Dear Friends,
    I need to draw horizontal line after the 2nd line item  and 3rd line item in smart forms.How can i achive this.
    Plz help.
    Edited by: farook shaik on May 19, 2009 8:19 AM

    This is what you need to do:
    1> In the tables->details section define two line types LT1 and LT2.
    2> Come back to tables section pressing the table painter button.
    3> Select a line type for which you want to have an underline(say LT2).
         a] If the anchor cursor does not come click the draw lines and columns button( the pencil icon nutton)
         b] select the line type ( it will become black after selection. Press and hold down ctrl to select
             multiple cells.
         c] after selection click the lower 'frame button' ( which is right at the top of box and shading).
    4> Now goto data section where you have given your internal table name and work area.
         a] in the sort criteria put your field POSNR and check the Event on Sort end chk box.
         b] you will see an extra node under the main area of the table.
         c] Create a table line with the line type LT2 in the node.
         d]Also in the Main area add another table line with LT1 as the line type.
    5> If POSNR remains unchnged LT1 will be triggered.
    6> if Posnr changes then LT2 will be triggered with the underline.
    This will suffice your requirement.

  • Draw line in Action Script project in Flash Builder (Gumbo).

    Hi
    I am working on drawing tool application and want to draw line and rectangle in Action Script project in Flash Builder (Gumbo). Please guide and help me with an example.
    Thanks
    Rangrajan.

    This should be helpful http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9 b90204-7dd9.html

  • Strange Vertical lines and pixelation issues with my Powerbook screen...Hel

    I have got a problem with mt LCD screen which now permanently displays lines of "dead" pixels, but they can't be dead because they chaneg all the time. If I move a window, I get lots more, which are created by the edge of the window, like a ghosting? Does that make sense?
    I have taken a screen grab, but not sure how to feature it in these forums. Anyone got any ideas or know about this problem?
    I have had a similar problem with this and other laptops, but it has always been a temporary thing before, when I had overloaded the system or something, and I got 'ghosting' from the trailing edge of a window, but this is permanently there?

    I have now attached a monitor to the PB, and it happens on the monitor too...maybe suggesting something wrong with the graphics card or logic board, rather than the screen itself. When I type this message, I get strange red 'ghosting' lines where the cursor moves across the page.It reminds me of the 'Etch-o-sketch' game, where you draw lines, and then wipe them off. I can move a window from left to right and get these ghosting lines. When I move the window back right to left, they erase the lines to the left of the window, but I get more to the trailing right edge of the window...i.e. on the right of the screen.
    Scrolling also removes these pixels, but creates new ones elsewhere.
    Any ideas?

  • I would like to find a program to draw lines, shapes and words for my iMac.

    If anyone can help me find a program or App for my iMac that lets me draw lines, shapes and letters.
         Thank You
         Sandy

    http://www.sketchup.com/
    Try this it is a free download and it is a great program. I almost feel guilty not paying anything:)

  • Drawing lines, rectangles and circles as objects onto a JPanel.

    Hi. I have to complete a task in school. The work is to create some simple 2D graphical editor. I'm new to java and I have some problems with this job, so I'm looking for help where it is possible...
    I created a JFrame and using it as a window. Into this JFrame I've added a toolbox (JToolBox) and "drawpad" - a JPanel. The toolbox wasn't any problem, but I aim to use the JPanel for drawing 2D objects. I tought about creating some container of objects, where I could put lines, rectangles or circles, each one with its properties (color, [x; y] coordinates on the scene, filling and drawing width) and then, draw this scene onto the JPanel.
    It should be something like windows Paintbrush. Can be simplier, but including the possibility to move and change properties of drawn objects.

    Well, there are two approaches to this that come to mind:
    1. Create an image. If this program is supposed to be like Windows Paint, the tools you are describing are only there for the sake of modifying a two dimensional image. In that case, I would recommend using a BufferedImage.
    The JPanel can contain a single JLabel. The JLabel is constructed in the following fashion:
    JLabel image_label = new JLabel(new ImageIcon(bufferedImage));...where bufferedImage is the image on which you will be storing the data. You can use bufferedImage.getGraphics() to get an object which will quite happily draw geometric shapes for you. Then, after each draw, you tell the panel to repaint itself.
    2. Store the shapes and create a component to draw them for you. You'd create a new JComponent class that would accept objects representing geometric shapes. You then override the paintComponent method on this new class to have it render itself according to the contents of the geometry objects. It would also probably be advisable to have all of these classes implement a common interface (which you would also create) so the rendering component could treat them identically.

  • I can't draw straight lines for fill-in-the-blank on my tests and worksheets. The "draw it yourself choice makes big fat lines and takes a lot of manipulation. Do I have to draw them myself with a pen and a ruler?

    I can't draw straight lines for fill-in-the-blank on tests and worksheets. The draw-it-yourself ooption gives me thick lines and is time-consuming. So, after all these years, do I have to go back to using a ruler and a pen?

    In Pages v5.0.1, the straight lines are already drawn for you in the Shape Tool. Before we go there, select Menu > View > Show Ruler.
    When you click on Shape in the Pages toolbar, the top left line is straight. Click it. It will drop into your document in a 45 degree angle. Grab the lower left selection grip and drag it up and to the right to position the horizontal line in the length of your choice. Use the Format: Style tab to manage the stroke weight. You can also choose Menu > Edit > Duplicate Selection (command+D) as a productivity tool.
    If you move from the Format: Style tab to the Arrange tab, you can compare the start and end points with where you want the line positioned on the ruler. Once you have it positioned, notice the Lock button, also on the Format: Arrange tab.

  • It's simple... I want the Illustrator pen tool to ALWAYS make corner annchor points and NEVER smooth.  Right now I have to convert every single one of them, or I have to do a work around every time I draw a line and make one of the handles disappear.  Is

    It's simple... I want the Illustrator pen tool to ALWAYS make corner annchor points and NEVER smooth.  Right now I have to convert every single one of them, or I have to do a work around every time I draw a line and make one of the handles disappear.  Is there some simple setting out there that will just "make it so?"@

    The video I am watching this guy is just dragging every line to make curves.  And every anchor point is a corner.  He is not switching back and forth between the pen and the anchor points tool, and he is not using the convert points tool.  He draws a curved line and starts another straight line only to curve it with a click and a drag.  It is super efficient, and I could save a world of time if I could figure out what he is doing.

  • I would like to cut and paste information from a word file onto a pdf file, as well as draw lines onto the pdf file.  How can I accomplish that task?  Is there software I can purchase?

    I would like to cut and paste information from a word file onto a pdf file, as well as draw lines onto the pdf file.  How can I accomplish that task?  Is there software I can purchase?

    Hi jgallu7382,
    The latter is easily accomplished using the Drawing Markup tools, which are available in both the free Adobe Reader, and in Acrobat. Copying/pasting text into the PDF is something that you could do using the editing tools that are available only in Acrobat. Note, however, that Acrobat isn't intended to be a text-editing application, so editing there won't be as robust as in an application designed specifically for that purpose. (It's also worth mentioning that you won't be able to alter a PDF if it has document permissions applied that would prevent you from doing so.)
    I hope that answers your questions.
    Best,
    Sara

  • Problem inserting graphics from line and draw to illustrator

    Hello everyone,
    I had just installed Draw and Line (mobile apps) to my iPad and they both work fine, except when I am trying to insert projects toillustrator... Mind you that there is no problem with photoshop or saving in creativecloud.
    I am getting an error that reads "The file "Project - Drawing.line" is an unknown file format and cannot be opened." I get the same messagewith drawwith the only difference that the.linebecomes.draw.
    I have found this thread:
    Illustrator CC 2014 can't open files sent from Draw.
    But does not help me at all as I suspect they are referring to iOS as my version is also 18.0 and I just updated everything and there is nothing new for illustrator. The only matter I could address would be to remove my old version of CS but I would prefer not to yet, as I see that sometimes there are bugs to newer versions and I do not want to be left without a working solution.
    I am running windows 7 64bit and any help would be really appreciated.
    Kindest regards,
    Michael

    Dear Larry,
    Thank you very much! That fixed both my problems. I would have never though about it.
    Note for others, by logging out and in again I got like 9 updates that previous were not there, although I have updated everything like 3 hours ago.
    Thanks once more Larry have a perfect evening!
    Kindest regards,
    Michael

  • Ai, 3D effect - after using to either extrude or revolve the settings are retained in my drawing tools - pen, pencil and shapes. Example I draw a 50 pt extruded object in wireframe, isometric view and my pen and all drawing tools will only draw using thos

    Ai, 3D effect - after using to either extrude or revolve the settings are retained in my drawing tools - pen, pencil and shapes. Example I draw a 50 pt extruded object in wireframe, isometric view and my pen and all drawing tools will only draw using those settings. I can not exit, help please!

    Appearance panel menu > New art has basic appearance.

Maybe you are looking for