Creating objects/shapes and printing to a swing??

Hey, if anyone has a few example files that draws a rectangle, oval, square, and a circle then they can be animated by being moved around the screen. I have a swing that has a file, with the option to create these shapes. If anyone can help please, thanks. I am also trying to call the draw method from the rectangle class that i have created. here is what i have in my main file where the swing is created.
private void rectangleMenuItemActionPerformed (java.awt.event.ActionEvent evt) {
//I don't know how i would call this, so when the
//rectangle menu item is clicked it draws a rectangle to
//the screen. If anyone could help i would really
//appreciate it i also still need examples of the shapes,
//thanks again!!!!!
mdawg

Hi,
You can use draw methods on Graphics Class. like
(guessing myPanel is your canvas)
private void rectangleMenuItemActionPerformed (java.awt.event.ActionEvent evt) {
Graphics g = myPanel.getGraphics();
g.drawRect(x, y, width, height);
But the problem with this approach is if myPanel is repainted(when resized etc.) it will clear the panel.
The best way is to extend JPanel and overrice paint method. Example:
public void paint(Graphics g)
if(rectangle)
g.drawRect(...);
else if(circle)
g.drawCircle(..);
set those flags(rectangle, circle,...) on your menu actions.
Hope this helps

Similar Messages

  • CREATE OBJECT obj and EXCEPTIONS problem

    Hi experts,
    I have a problem with my program.
    CREATE OBJECT obj
      EXPORTING
        ls_record_local = ls_record
      EXCEPTIONS
        error = 1.
    When there is no exception everything is fine, but when the sy-subrc = 1, there is no possibility to trigger any other method like
    CALL METHOD obj->get_data.
    System says that obj is initial and it goes to dump.
    Any idea how to prevent this dump How can I have the reference to my object after exception has been throwed ?

    CREATE OBJECT command creates an instance of the class. If there is a problem in instantiating the class an EXCEPTION is raised & the class doesn't get instantiated.
    In this case you can't use the instance attributes / methods of the class.
    Try something like this:
    CREATE OBJECT obj
      EXPORTING
        ls_record_local = ls_record
      EXCEPTIONS
        error = 1.
    IF sy-subrc NE 0.
      MESSAGE 'Error Instantiating the class' TYPE 'E'.
    ENDIF.
    CALL METHOD obj->method.
    Hope i'm clear.
    BR,
    Suhas
    Edited by: Suhas Saha on Oct 21, 2010 3:40 PM

  • Creating Object Sender and Receiver

    Good morning,
    I am creating my first scenario B1iSN trying to integrate SQL Server DB B1 and I have a couple of questions:
    And design a BizPackage and BizStep, but I can not understand why option adds the Sender and Receiver Object.
    I appreciate any help.
    Andrew

    Hi Andrew,
    Sender and Receiver Object is to define which objects you are going to include in the package. Without this, you will not be able to integrate two systems.
    Have you checked through this: B1iSN: Tips, tricks and important topics ?
    Thanks,
    Gordon

  • Export PDF creates 0kb file and Print Error.

    By "Print Error", I mean a simple pop-up window with the pages logo and the sentence "Print. Error while printing" even though I haven't asked for anything to be printed. The resulting pdf file is zero k in size and useless.
    I had this problem in iW '06 and thought that '08 might fix it. No dice though.
    Deleating prefs did not fix the issue. ['06 or '08]
    Anyone? Thanks.
    CSK
    Burbank, CA

    I suspect that you've turned off a couple fonts with Font Book (or perhaps removed them from the Fonts folder). Pages expects certain fonts to exist - even if we don't use them or even want them.

  • AIR 1.5, create and print PDF?

    Hi,
    I need to develop an application that is able to print. To file to print is build up during application usage (you can walk trough the application in a linear way). At the end of the app you need to be able to print the printable file.
    Im using AIR 1.5 as the runtime (Flex 3 as development IDE). Can I dynamically create PDF files and print them from AIR?
    Your answer could be as simple as a yes/no but any tips or references to articles are greatly appreciated.
    Thanks a lot for your help!
    Regards,
    Marcel

    It runs fine before, so I don't know if this a bug or a
    change in the way soemthing, such as ".innerHTML" is
    handled.

  • Shapes and measurements. Help please!

    I created a shape and the measurement keeps changing on it's own. It set it for 12.60" and it keeps changing to 12.5972 in. Why does this happen?

    Does the object have a stroke? And is "Use preview bounds" checked?
    and/or
    is "Align to pixel grid" checked?

  • "OIP-04796 Unable to create object instance"

    I am using OO4O, version 3 for Oracle 8.1.7 on Windows with Visual Basic version 6.
    I am getting the intermittent errors "OIP-04796 Unable to create object instance" and also "Method createDynaset of _IOraDatabase failed" - I think both are related to one another and from the documentation for OO4O, "OIP-04796" relates to the client side object cache of the OraDatabase class. Reasoning that the client side object cache was too small I attempted to increase the relevant properties of the OraDatabase object using the following: -
    MyOraDatabaseObj.CacheOptimalSize = 400
    However, at run-time, this property of the OraDatabase object does not get set accordingly in the VB IDE and after several attempts I can't seem to set it. I have also tried setting the CacheMaximumSize property but to no avail.
    Can anybody indicate to me where I am going wrong and either with the setting of the above properties or with the error message in general if I am not on the right track with the cache properties. I don't suspect that it is my code because the problem "seems" to be intermittent.
    Any and all help would be greatly appreciated. If more info is required then just ask as this is pressing problem.
    TYIA
    Mark Grimshaw

    I am pretty sure the patches are available here. If you didn't explicitly install one then you have whatever the base release was.
    If they are not available here (I almost never look here first for a patch) they are certainly available in the MetaLink file library for OO4O.

  • Holding Shift when creating Vector Shape - No snap to pixels!

    Hi there,
    Adobe Photoshop Version: 13.0.1 (13.0.1 20120808.r.519 2012/08/08:21:00:00) x64
    Operating System: Windows 7 64-bit
    Version: 6.1 Service Pack 1
    I'm experiencing the following problem:
    When creating vector shapes and holding shift the shape do not snap to pixel. Snap to pixels is turned on.
    It is pretty strange.
    Please check the video below:
    http://screencast.com/t/1iys3tDJHpJt
    Initially when do not hold shift shapes is pixel perfect. As you can see in the image first 2 shapes are made free hand.
    SK

    Instead of holding the shift key try pressing the + key to change the path operations to Add to Shape Area and the - key to subtract from shape area.
    That is strange behaviour compared to cs5 where having snap to pixels checked for the rectangle tool does align the edges when holding down shift
    where as cs6 13.01 doesn't align the edges when holding shift either with the snap vector preferences of align edges checked.
    It only seems to align the pixels when snap vectors in the preferences is checked and using add to shape area is actually selected in the drop down.
    That's what the plus key does.
    I guess i was under the impression that align edges was supposed to be the same as the snap to pixels was in cs5.
    Message was edited by: R_Kelly

  • Create a PDF file from swing component and print

    Hi,
    Suppose i have a JFrame where in i add a JScrollpane which has a JPanel with some painting on it, suppose i want to create a pdf file of the total JPanel, and not of what i see on screen like taking a screen shot, or print the total JPanel, and not only the screen that is displayed
    how can i do it
    I am attaching the code below, how can i create a pdf for MyPanel and print it
    //start code
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TestDisplaySize extends JFrame
         JScrollPane scrollPane ;
         public TestDisplaySize()
              super("layered pane");
              this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              MyPanel panel = new MyPanel();
              scrollPane = new JScrollPane(panel);
              Container contentPane = this.getContentPane();
              contentPane.add(scrollPane, BorderLayout.CENTER);
              setSize(new Dimension(800,600));
              this.setVisible(true);
              JViewport viewPort = scrollPane.getViewport();
         class MyPanel extends JPanel
              public MyPanel()
         setPreferredSize(new Dimension(2000,600) );     
         this.setBackground(Color.white);
         this.setOpaque(true);
         public void paintComponent(Graphics g)
    super.paintComponent(g);
    setBackground(Color.white);
    Rectangle r = scrollPane.getViewport().getViewRect();
    g.setClip((Shape)r);
    g.setColor(Color.blue);
    int x = 0;
    for(int i = 0; i < 60; i++)
         x +=60;
         g.drawLine(x, 0, x, 600);
         g.drawString(String.valueOf(i), x, 50);
         public static void main(String args[])
         new TestDisplaySize();
    //end code

    create a class wich implements printable, redefine the print method of this class with the this you want to print
    and at the end of the constructor...
    PrinterJob printJob = PrinterJob.getPrinterJob();
    PageFormat myFormat = new PageFormat();
    myFormat.setOrientation(PageFormat.LANDSCAPE);
    myFormat.setPaper(ps.getMyPaper());
    printJob.setPrintable(this, myFormat);
    if (printJob.printDialog()) {
    try {
    printJob.print();
    } catch (Exception pe) {
    System.out.println(pe);

  • Adding New View Objects/Link on "Preview and Print" - Order Acknowledgement

    Hi,
    Can we add New View Objects/View Links for the existing "Preview and Print" Order Acknowledgement.
    I want to add for the 2 new functionalities i.e., for Charges (from OE_PRICE_ADJUSTMENTS_V ) and the Line Level Notes, which is currently not supported by Oracle.
    Can anyone help me on acheving this functionality?
    Looking forward for your response.
    Thanks in advance,
    Regards,
    Muru

    You can do that. You should first create the new business objects(AM, VO, VL) in jdeveloper, create your new regions in jdeveloper, associate the AM to the top level region(stackLayout) you create. Use personalization and add a stack layout in the Preview and Print page, set the extends property to point to the new region which you had created. Donot forget to deploy all the files in middle tier before doing the personalization.
    The AM which you had added to the stackLayout will automatically be nested with the root AM of the page during runtime.

  • Creating Objects with the Shape Tools | Learn Illustrator CS6 | Adobe TV

    In this video you'll see how to use Illustrator's shape tools to create primitive shapes that you can use as the basis for objects. You'll also learn how to use the Shape Builder tool to combine shapes.
    http://adobe.ly/JXWnRj

    What tool did you use to drag between the skull and jaw to join them?  You didn't share how you did that.

  • Is there a way to create a year at a glance with detail and print?

    Is there a way to create a year at a glance with detail and print?

    To do what Dave indicated you need to do, it depends on what version of Acrobat you have:
    Acrobat 8: Advanced > Enable Usage Rights in Adobe Reader
    Acrobat 9: Advanced > Extend Features in Adobe Reader
    Acrobat 10: File > Save As > Reader Extended PDF > Enable Additional Features
    Acrobat 11: File > Save as Other > Reader Extended PDF > Enable More Tools (includes form fill-in & save)
    I wonder what it will be next time?

  • How to add zooming and printing in e-magazine created by indesign?

    Could you please give ma an advise me how to add zooming and printing in e-magazine created by indesign? Many thanks

    Ooohh... you mean, like the one mentioned in http://indesignsecrets.com/adding-zoom-and-print-to-indesign-swf-files.php?
    But they want to get paid for their hard work, the bastards!

  • In pages, when a create a document, potions of it, say several pages will be clumped together and it effects me editing their order.  It is like they are forever joined- How do I edit my document and print just one page or move just one page?

    In pages, when a create a document, potions of it, say several pages will be clumped together and it effects me editing their order.  It is like they are forever joined- How do I edit my document and print just one page or move just one page?

    May you open your eyes before creating a new thread ?
    Your question was already asked and answered today.
    https://discussions.apple.com/thread/3177074?tstart=0
    Yvan KOENIG (VALLAURIS, France) jeudi 14 juillet 2011 14:40:40
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8
    Please :
    Search for questions similar to your own
    before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a

    We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a printer."C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /T "\\<Application Server>\Report\<TEST.PDF>" "<Printer Name>". Current Situation: The above command line parameter when executed is working as expected in a User's Workspace. When executed in a command line on the Application Server is working as expected. But, the same is not working while executing it from Deployed environment.Software being used: 1. Adobe 11.0 enterprise version. 2. Webshpere Application Server 8.5.5.2. Please let us know if there is a way to enable trace logs in Adobe Reader to further diagnose this issue.

    This is the Acrobat.com forum.  Your question will have a much better chance being addressed in the Acrobat SDK forum.

Maybe you are looking for

  • The tricky logminer in 8.0.5

    I'd the need of mine some old information for this weird ethic committee. and after a while, i found myself writing a small guide that will help the poor souls chained to old oracle server releases. I hope it helps. As many of you know there was not

  • Java plug in 1.4.1_04 the install package could not be opened

    Hi . I am trying to install java plug in 1.4.1 on a Windows XP client SP1 and I receive the following error. Windows Installer The installation package could not be opened. Verify that the package exists and that you can access it, or contact the app

  • Master Page button hidden prob

    How can i make a button in a masterpage invisble?? The code should run from a Script Object. Hierarchy is :: testForm MasterPage Page1 resetButton MainPage Variables MyScripts MyScripts is a script object.. And i want to make the resetButton in Maste

  • Photosop CS4 graphics card question

    Hello, I am looking into buying a new IMAC and was wondering about whether or not the graphics card that comes with it supports the new CS4 features. Does anyone know if the- ATI Radeon HD 2600 PRO w/256MB card -that comes with the IMAC supports all

  • TextEdit crashes when opening RTFD files

    This just started happening recently. Can open RTF files, but when I try and open an RTFD, the application crashes. Any help would be appreciated!