Problem displayin a picture in a Canvas Component

Hello.
I've a little problem of picture displaying, with this code:
import java.awt.*;
import java.awt.Image;
import java.awt.Graphics;
public class Terrain extends java.applet.Applet
     GridLayout terrain = new GridLayout(15,26);
     Image sol;
     Canvas c01_01;
     public void init()
          sol = getImage(getCodeBase(),"terrain.bmp");
          c01_01 = new Canvas();
          setLayout(terrain);
          add(c01_01);
     void paint(Canvas toto)
          toto.drawImage(sol, 0, 0, this);
a classical "Cannot resolve symbol" error is returned, about the method drawImage. I don't understand why, cause the examples i read also use "this" as ImageObserver.
If someone has an idea about that, it will be helpful.
Thanks by advance!
Ciao!

You can trytoto.getGraphics ().drawImage (sol, 0, 0, toto);but it still won't work like you expected.
Kind regards,
  Levi

Similar Messages

  • Problem with Canvas component.

    Hello all,
    I am building a sort of flowcharting software using Swing. The software is standalone. The "flowcharting" component is a sort of canvas, However it does not extend the Canvas class from AWT, but rather extends a JComponent. The paint() method simpy says g.fillRect(color) and this produces the backdrop. Ok, to the point, every once in a while, some components or text will not render at all on this canvas. If if I were to close and load the flowchart, the same component will not render, and usually it is text with user defined fonts that will not render. I would say they render correctly on 80% of the machines on which it has been installed. It may be a font problem, but other text with the same exact font will render. Assuming that the components are instructed to render(I am fairly convinced of this) are there any possible reasons that these components will not render. All components render on my machine, and some will not render on other machines. Has anyone ever dealt with anything like this? Perhaps my canvas should actually subclass Canvas from AWT? Any feedback is much appreciated.
    Thanks.

    Thanks,
    Actually, this canvas overrides the JComponent class and is not an AWT Canvas component. A couple of things I did notice however....
    Maybe overriding JPanel would be more suitable.
    Currently the paint() method is being overridden as opposed to the paintComponent() method. I think overriding paintComponent would be the right thing to do.
    Thanks for help anyways.

  • Canvas Component Problem

    Hi
    I am using canvas component  and in order to refresh my page every time I am using show attribute in the root instead of creation Complete.
    Thats working fine with all screens but in one Screen I am using canvas as the root and inside it I am using 4 canvas containers each of  which has many combos.In this case its restoring the previous values.Its not refreshing.
    Now I need to refresh the page And all the combo must display the prompt as Select a value.Though I have given  the prompt attribute its not working.
    Can Anyone Help Pls

    Hi Divya,
    Do you have the canvas component placed inside a ViewStack or else did you place the component within the main Application without including in the ViewStack container.
    What about your other screens ...? You said for other screens show is working then where did you put those components...?
    Try to post some sample code reproducing your problem.
    Thanks,
    Bhasker Chari

  • Popup menu appears behind canvas component

    Has anybody encountered this problem?
    I attach the popup menu to the canvas component, like this:
    public void mousePressed(MouseEvent e)
         if (e.getSource() == psuCanvas && e.getButton() == MouseEvent.BUTTON3)
              pmenu.show((Component)psuCanvas, e.getX(), e.getY());
              contextText.setText("Right Click!!!");
    The popup menu is only visible when I click the edge of the Canvas component, that is how I know that the popup is actually showing but behind the Canvas component!!!
    Please help

    You mean your 1 step of calling "JPopupMenu.setDefaultLightWeightPopupEnabled(false);"?
    That method is meant specifically for using popup menus when you are mixing AWT and Swing components. The reason is because of the problem you first posted about. It's a way to get around that problem. But really, it's more of a hack that is used when dealing with old AWT-based components which you can't (or won't), for whatever reason, "update" to Swing versions. (Say from a 3rd-party library).
    It is not recommended to mix AWT and Swing components, as already mentioned. The provided link above is an article that explains the issues with this. The fact that you can doesn't mean you should.
    If you are writing this Canvas subclass yourself, and it's going to be typically used in a Swing application, you will have problems later, most likely. For example, why don't you try puting your Canvas class in a JScrollPane so you can make it bigger then the window and scrollable? You'll have scrollbar visibility issues. Fine, you can use java.awt.ScrollPane, I guess. Then I can think of several things one might do with JLayeredPanes which would create problems as well. And there is no simple "setDefaultLightWeightEnabled()" option to fix those.
    So eventually, as your app, or library, matures, you start running into these problems cuz you are using AWT components where you should be using Swing components, and you start making more hack-like fixes for all these problems like using setDefaultLightWeightPopupEnabled() and explicit sizing instead of layout managers and limiting yourself to what you can do with your components.
    That's why.

  • I upload all of my photos from my iphone 5 onto my macbook air to get more space on my phone, and now whenver i try to upload it says there is no more storage or there was a problem transferring a picture. what can I do to get more space onto my iphoto?

    i upload all of my photos from my iphone 5 onto my macbook air to get more space on my phone, and now whenver i try to upload it says there is no more storage or there was a problem transferring a picture. what can I do to get more space onto my iphoto? I've tried putting the pictures on flashdrives, but iphoto would no tlet me transfer.

    I don't know how large the SSD (solid state hard drive) is, or how big your iPhone 5 is, but with some iPhones having 64GB and some Airs having as little as 64GB and some having as much as 512GB it's not hard to see how storing the contents of your iPhone 5 on your Macbook Air could run you out of space.
    Go to the Macbook Air and bring up a finder window and pull the Go menu down and go to the Computer. Right click on the Macintosh HD and select get info. See if there is any available space on the MacBook Air. If not you are out of SSD space (you're storing more on your Macbook Air than it has storage for). I'm not sure if iTunes can store its library on an external hard drive or quite how you would make that happen. But even if you managed that, when the hard drive was disconnected, you would lose access to your library. Using a smart media card might be possible (I don't know) but it would probably be irritatingly slow. If you have a small Air and a big iPhone you might just have to find a different computer to sync to. Just remember a 64GB iPhone is a big chunk of SSD for a Macbook Air. I did it with my previous and my current Air but even my previous one had 256GB and I really just fit.

  • I can not send my Note through email and it used to work. The same problem to send picture from iPhone message

    Can't send Notes through email and it used to work. The same problem of sending picture from iPhone message. Did the reset twice but still not working

    Try a reset:
    Hold the Sleep and Home button down for about 10 second until you see the Apple logo.

  • FaceTime freezes when same room has no problems. The picture is high resolution. There are no freezes when calling my daughter's iPad but the picture is lower resolution. Can I troubleshoot this?

    FaceTime freezes when I call my son's iPad. Calling his iPhone in the same room has no problems. The picture is high resolution. There are no freezes when calling my daughter's iPad but the picture is lower resolution. Can I troubleshoot this?

    Thanks Mario, but I tried everything there before posting my question. I may not have been clear in my question since I accidently recorded the whole question as the title and tried to edit. In brief: I have no trouble connecting with my daughter's iPad or my son's iPhone. However, his iPad is sending much higher resolution pictures and we disconnect after about a minute.  Oddly, he can hear and see me while my screen first freezes, then goes black and gives me a message of "reconnecting" until it quits trying and shows the buttons to end or redial. The picture quality difference is what is leading me to believe it is bandwidth related. However, I get anywhere from 5 to 10 MB download speeds; usually closer to 10. Last summer, I had 4 granddaughters on their iPads, a grandson on his gaming device and me on cell phone or pc, all using the bandwidth at once with no complaints. If there is a way to lower his outgoing resolution, I think that would help.

  • Calling a function every time a canvas component is viewed

    hi all,
    i have a function in a canvas component which i need to call
    every time i view that component. is there a way to generate an
    event each time a i view that component.. 'show' works only when
    the component turns from invisble to visible..
    thanx in advance

    the code is
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns:custom=".*"
    backgroundColor="#ccccccc" width="100%" height="100%"
    creationComplete="findCreatePermission(); addListeners();"
    show="findCreatePermission();"
    >
    <mx:Script>
    <![CDATA[
    private function findCreatePermission():void
    if(myPermission & 2)
    createPermission = true;
    else
    createPermission = false;
    ]]>
    </mx:Script>
    <mx:ViewStack id="mainStack" width="100%" height="100%"
    >
    <mx:Canvas id="mainCanvas"
    show="createPatient.visible=false;patientList.visible=true;sample2();">
    <mx:VBox width="100%" height="100%">
    <custom:patientInfo id="patientList" label="Room search"
    backgroundColor="#ECECD9" width="100%" height="100%"
    visible="true" />
    <mx:HBox horizontalAlign="center" width="100%" >
    <mx:Button id="create" label="Create New Patient"
    height="30" styleName="buttonBlue"
    enabled="{createPermission}"
    click="{mainStack.selectedChild=createPatient;}" />
    </mx:HBox>
    </mx:VBox>
    </mx:Canvas>
    <custom:create_patient id="createPatient" label="Create
    Patient" width="100%" backgroundColor="#ECECD9" visible="false"
    returnStack="{mainStack}" returnCanvas="{mainCanvas}"
    show="patientList.visible=false;createPatient.visible=true;"/>
    </mx:ViewStack>
    </mx:Canvas>
    i need to call findcreatePermission() every tme this
    component is viewed

  • Hi Guys, I have a problem with Importing Pictures onto my Mac mini with Lion installed by using a Card Reader, What is the problem here so I can get Pictures onto my Computer. ,

    Hi Guys,
    I have a problem with Importing Pictures onto my Mac mini with Lion installed by using a Card Reader,
    What is the problem here so I can get Pictures onto my Computer. ,

    Hi Noob Søren
    There are a few things that are confusing in your question.
    As far as I know, you dont have to install Time Machine on this OS as it is already installed for you. You only need to connect a hard drive to your computer via firewire or usb, click on the Time Machine icon, Open Time Machine Preference in the drop down menu and select a disk: your connected hard drive.
    You can of course reformat this connected device, partition it into a few volumes to organise data if you so wish.
    I find it strange that your mac's hard drive is divided into two volumes... perhaps this was created through bootcamp?
    You can access the configuration of your hd through Applications/Utilities/Disk Utilities.
    Clicking on one of the icons on the right hand panel will bring the details of the contents of your hardDrive and volumes. From there you can decide to erase a partition, reformat etc....
    If your hd contains more than one volume, and one of them is empty, you could decide to remove it. Back up all your important data before doing so.
    Hope this helps
    WN

  • Problem to removing pictures

    Hi!
    I have problem to removr picture´s from my album. I have turn off all streaming from icloud, but the picture are still in my ipad.
    Could someone please help me?
    poma01

    The links below have instructions for deleting photos.
    iOS and iPod: Syncing photos using iTunes
    http://support.apple.com/kb/HT4236
    iPad Tip: How to Delete Photos from Your iPad in the Photos App
    http://ipadacademy.com/2011/08/ipad-tip-how-to-delete-photos-from-your-ipad-in-t he-photos-app
    Another Way to Quickly Delete Photos from Your iPad (Mac Only)
    http://ipadacademy.com/2011/09/another-way-to-quickly-delete-photos-from-your-ip ad-mac-only
    How to Delete Photos from iPad
    http://www.wondershare.com/apple-idevice/how-to-delete-photos-from-ipad.html
    How to: Batch Delete Photos on the iPad
    http://www.lifeisaprayer.com/blog/2010/how-batch-delete-photos-ipad
    (With iOS 5.1, use 2 fingers)
    How to Delete Photos from iCloud’s Photo Stream
    http://www.cultofmac.com/124235/how-to-delete-photos-from-iclouds-photo-stream/
     Cheers, Tom

  • Problem with saving picture in Vision Builder

    hello
    I'm using Vision builder and i'm trying to save picture with Image Logging. And i made ftp server that picture could be save. In folder path I write location where I want that picture save. But problem is, that picture does not saves in that location where I want.
    Could anybody help me?
    Please
    Matjaz
    p.s.: I attach a picture that You will see how I made my settings
    Attachments:
    napaka.jpg ‏4307 KB

    rezi wrote:
    why is writen 257 "/" is current directory ??
    It means that root is current directory.
    For setting VBAI as current directory it should be something like
    CWD VBAI
    250 OK. Current directory is /VBAI
    PWD
    257 "/VBAI" is your current directory.
    Try to remove VBAI from Folder path and leave this setting just empty. Then your images should be written into root directory. Also you have selected option "Log images when inspection status FAIL". May be your status PASS? In this case images will be not logged. Try to change this option to "Log Image".

  • Problem with displaying picture.

    I use PS-CC and LR5.on a HP i7 computer and windows 7.Camera D-800, pictures in raw.
    I usually import pictures in nef  in LR5,. After  some corrections, I export my pictures to DNG format. I sometimes do a little bit of work in camera raw then go into Photoshop.
    My problem: When in photoshop, I get a grainy version of my photo which wasn't the situation in LR5 or Camera raw, Hard to work with. The grains will disappear when I enlarge the picture but then I have to enlarge it so much that I only see or can work with only part of my picture. The problem does not appear in CS6.
    Hope somebody can help me.
    Thanks
    Jacques Legault

    I should clarify this.. When I import photos into LR5, I always use copy as
    DNG. I know that NEF and DNG are the same for photoshop and I always shoot
    in raw.
    One thing I do not know is how to do a screen shot. I will get back tro you
    on that. When I say grain, or noise if you like, I mean that, if i relate
    to films, my picture in LR5  would be at ISO 100 and my screen shot in
    photoshop would look like it was boosted to 1200 or worse.
    See you soon I hope with a screen shot.
    2014-06-14 13:43 GMT-04:00 twenty_one <[email protected]>:
        Problem with displaying picture.  created by twenty_one
    <https://forums.adobe.com/people/twenty_one> in *Photoshop General
    Discussion* - View the full discussion
    <https://forums.adobe.com/message/6458682#6458682>

  • I have a problem, all the pictures turns grey when i open a document, i have a Mac computer if that can be any help.. Please can somebody tell me what i am doing wrong. It have not been like this before i have started now??

    I have a problem, all the pictures turns grey when i open a PDF document in acrobat xl pro, iy have not been like this before it started a few days ago. Before it did help if i closed the program but that does not work anymore??

    Now it works!!!! THANK YOU VERY MUSH!!! You made my holiday!! Now i can work! ; )) Happy new year to you!!!

  • Problem opening multiple pictures in Photoshop

    Problem opening multiple pictures in Photoshop.  OldBob1957 has given me some suggestions on how to overcome this problem.  I tried to Edit.Purge>All, Reset Preferences, Delete the Adobe Photoshop x Prefs.psp folders and Ctrl+Alt+Shift on Photoshop startup.  Did not work, what next?  Delete all the PSP folders.?  There are 45 more in my computer.  Any help will be appreciated.

    Hi Noel:
    I reset the max memory to the high side as suggested but the results when I opened the pictures and changed them was the same.  I could open four but nto the fifth one.
    Lyndon
    PS:  In the event you haven't seen the start of the problem, I thought I would include it here:
      I am working on a picture file, jpegs, changing the size, the level, etc. I open several pictures usually
    3 or 4 and when I try to open the next I receive a pop up error message that says: "Could not
    complete your request because of a program error.” This has just started to happen recently,
    probably since I upgraded to CS6. Previously I could work on a file and have 100 or so pictures
    open and still be able to open additional pictures. I have downloaded and in installed all available
    updates and the message I receive when I check for updates is: “Your applications are up-to-date
    as checked less than a minute ago.” I tried to Edit>Purge>All, Reset Preferences, Deleted the
    Adobe Photoshop Ver. 6 Prefs.psp folder and pressed Ctrl+Alt+Shift on Photoshop startup and
    deleted Adobe Photoshop Settings file. Did not work, what next? Delete all the PSP folders? There
    are 45 more in my computer. Any help will be appreciated.
    LR

  • Having a problem saving the graphics on a canvas.

    I'm having a problem saving graphics on a canvas. It draws on the canvas but when another window comes up the graphics disappear. I put in a method to take the graphics on the canvas and repaint it with the graphics. But this comes up blank. So I don't know why this is happening. It is probably the paint method but I don't know why. If anyone has any ideas could you please respond because I have had this problem for ages now and it's driving me mad and I have to get this finished or I'm going to be a lot of trouble. I'll show you the code for the class I am concerned with. It is long but most of it can be disregarded. The only parts which are relevent are the paint method and where the drawline e.t.c are called which is in the mouse release
    package com.project.CSSE4;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.ImageFilter;
    import java.awt.image.CropImageFilter;
    import java.awt.image.FilteredImageSource;
    import java.io.*;
    import java.util.*;
    import java.net.*;
    import javax.swing.*;
    import java.sql.*;
    public class CanvasOnly extends JPanel
           implements MouseListener, MouseMotionListener
       public static final int line = 1;
       public static final int freehand = 2;
       public static final int text = 3;
       public static final int mode_paint = 0;
       public static final int mode_xor = 1;
       public Color drawColor;
       public int drawThickness = 1;
       public int drawType = 0;
       public boolean fill = false;
       private boolean dragging = false;
       public int oldx = 0;
       public int oldy = 0;
       private int rectangleWidth;
       private int rectangleHeight;
       private tempLine draftLine;
       private tempText draftText;
       public Canvas pad;
       public static final Font defaultFont =
         new Font("Helvetica", Font.BOLD, 14);
       protected boolean floatingText = false;
       boolean showingPicture;
       protected Image offScreen;
       public JTextArea coor;
       public JButton writeIn;
       Connection connection;
       String codeLine;
       int x = 0;
       int y = 0;
       public CanvasOnly()
           try
                Class.forName("com.mysql.jdbc.Driver").newInstance();
           }catch( Exception e)
                 System.err.println("Unable to find and load driver");
                 System.exit(1);
            pad = new Canvas();
            pad.setBackground(Color.white);
            pad.setVisible(true);
            pad.setSize(400, 400);
           coor = new JTextArea(15, 15);
           writeIn = new JButton("load TExt");
           writeIn.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent event1)
                     try
                   Statement statement = connection.createStatement();
                   ResultSet rs = statement.executeQuery("SELECT * FROM submit WHERE file_name = 'cmd.java'");
                   rs.next();
                   String one1 = rs.getString("student_id");
                   //System.out.println("one1 :" + one1);
                   String two1 = rs.getString("file_name");
                   //System.out.println("two1 : " + two1);
                    InputStream textStream = rs.getAsciiStream("file");
                    BufferedReader textReader = new BufferedReader(
                                     new InputStreamReader(textStream));
                    codeLine = textReader.readLine();
                    x = 0;
                    y = -12;
                    while(codeLine != null)
                        y = y + 12;
                        //fileText.append( line + "\n");
                        //canvasPad.drawTheString(line, x, y);
                        drawText(Color.black, x, y, codeLine, mode_paint);
                        codeLine = textReader.readLine();
                     textReader.close();
                    pad.setSize(400, y);
                    Timestamp three1 = rs.getTimestamp("ts");
                    //System.out.println(three1);
                    textReader.close();
                    rs.close();
              }catch (SQLException e)
                System.err.println(e);
              catch(IOException ioX)
                System.err.println(ioX);
            //setSize(300,300);
            drawColor = Color.black;
            pad.addMouseListener(this);
         pad.addMouseMotionListener(this);
         offScreen = null;
       public Image getContents()
         // Returns the contents of the canvas as an Image.  Only returns
         // the portion which is actually showing on the screen
         // If the thing showing on the canvas is a picture, just send back
         // the picture
         if (showingPicture)
             return (offScreen);
         ImageFilter filter =
             new CropImageFilter(0, 0, getWidth(), getHeight());
         Image newImage =
             createImage(new FilteredImageSource(offScreen.getSource(),
                                  filter));
         return(newImage);
        public void setImage(Image theImage)
         // Fit it to the canvas
         offScreen = theImage;
         repaint();
         showingPicture = true;
        synchronized public void paint(Graphics g)
         int width = 0;
         int height = 0;
         //The images are stored on an off screen buffer.
            //offScreen is the image declared at top
         if (offScreen != null)
                  //intislise the widt and heigth depending on if showingpicture is true
              if (!showingPicture)
                       width = offScreen.getWidth(this);
                       height = offScreen.getHeight(this);
                   //width = getWidth(this);
                   //height = getHeight(this);  //offScreen
              else
                   //width = pad.getSize().width;
                   //height = getSize().height;
                   width = pad.getWidth();
                   //width = getSize().width;
                   height = pad.getHeight();
                   //height = getSize().height;
                    //Draws as much of the specified image as has already
                    //been scaled to fit inside the specified rectangle
                    //The "this" is An asynchronous update interface for receiving
                    //notifications about Image information as the Image is constructed
    //This is causing problems
              g.drawImage(offScreen, 0, 0, width, height, pad);
              g.dispose();
         //clear the canvas with this method
        synchronized public void clear()
         // The maximum size of the usable drawing canvas, for now, will be
         // 1024x768
         offScreen = createImage(1024, 768);
         //Creates an off-screen drawable image to be used for double buffering
         pad.setBackground(Color.white);
         //Set the showingPicture to false for paint method
         showingPicture = false;
         repaint();
         synchronized public void drawLine(Color color, int startx, int starty,
                              int endx, int endy, int thickness,
                              int mode)
         int dx, dy;
         Graphics g1 = pad.getGraphics();
         Graphics g2;
         //if image is not intialised to null
         //the getGraphics is used for freehand drawing
         //Image.getGraphics() is often used for double buffering by rendering
            //into an offscreen buffer.
         if (offScreen != null)
             g2 = offScreen.getGraphics();
         else
             g2 = g1;
            //mode is put into the method and XOR is final and equal to 1
         if (mode == this.mode_xor)
                  //calls the setXOR mode for g1 and g2
                  //Sets the paint mode of this graphics context to alternate
                    //between this graphics context's current color and the
                    //new specified color.
              g1.setXORMode(Color.white);//This will
              g2.setXORMode(Color.white);
         else
                  //Sets this graphics context's current color to the
                    //specified color
              g1.setColor(color);
              g2.setColor(color);
         if (endx > startx)
             dx = (endx - startx);
         else
             dx = (startx - endx);
         if (endy > starty)
             dy = (endy - starty);
         else
             dy = (starty - endy);
         if (dx >= dy)
              starty -= (thickness / 2);
              endy -= (thickness / 2);
         else
              startx -= (thickness / 2);
              endx -= (thickness / 2);
         for (int count = 0; count < thickness; count ++)
              g1.drawLine(startx, starty, endx, endy);
              g2.drawLine(startx, starty, endx, endy);
              if (dx >= dy)
                  { starty++; endy++; }
              else
                  { startx++; endx++; }
            //Disposes of this graphics context and releases any system
            //resources that it is using.
         g1.dispose();
         g2.dispose();
         //This method is not causing trouble
         synchronized public void drawText(Color color, int x, int y,
                String text, int mode)
         Graphics g1 = pad.getGraphics();
         Graphics g2;
         if (offScreen != null)
             g2 = offScreen.getGraphics();
         else
             g2 = g1;
         if (mode == this.mode_xor)
              g1.setXORMode(Color.white);
              g2.setXORMode(Color.white);
         else
              g1.setColor(color);
              g2.setColor(color);
         g1.setFont(new Font("Times Roman", Font.PLAIN, 10));
         g2.setFont(new Font("Times Roman", Font.PLAIN, 10));
         g1.drawString(text, x, y);
         g2.drawString(text, x, y);
         g1.dispose();
         g2.dispose();
          //connect to database
      public void connectToDB()
        try
           connection = DriverManager.getConnection(
           "jdbc:mysql://localhost/submissions?user=root&password=football");
                     //may have to load in a username and password
                                                     //code "?user=spider&password=spider"
        }catch(SQLException connectException)
           System.out.println("Unable to connect to db");
           System.exit(1);
      //use this method to instatiate connectToDB method
      public void init()
           connectToDB();
        protected void floatText(String text)
         draftText = new tempText(this.drawColor,
                            this.oldx,
                            this.oldy,
                                        text);
         this.floatingText = true;
        //nothing happens when the mouse is clicked
        public void mouseClicked(MouseEvent e)
        //When the mouse cursor enters the canvas make it the two
        //straigth lines type
        public void mouseEntered(MouseEvent e)
         pad.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
        //When mouse exits canvas set to default type
        public void mouseExited(MouseEvent E)
         pad.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        //used for creating the shapes and positioning thetext
        public void mousePressed(MouseEvent e)
             // Save the coordinates of the mouse being pressed
         oldx = e.getX();
         oldy = e.getY();
         // If we are doing lines, rectangles, or ovals, we will show
         // draft lines to suggest the final shape of the object
         //Draw type is a publc int which can be changed
         if (drawType == this.line)
            draftLine = new tempLine(drawColor, oldx, oldy, oldx,
                                 oldy, drawThickness);
            // Set the draw mode to XOR and draw it.
            drawLine(draftLine.color, draftLine.startx,
            draftLine.starty, draftLine.endx,
            draftLine.endy, drawThickness, this.mode_xor);
        //mouse listener for when the mouse button is released
        public void mouseReleased(MouseEvent e)
             if (drawType == this.line)
              // Erase the draft line
              drawLine(draftLine.color, draftLine.startx, draftLine.starty,
                    draftLine.endx, draftLine.endy, drawThickness,
                    this.mode_xor);
              // Add the real line to the canvas
              //When the imput changes to "mode_paint" it is drawen
              //on the canvas
              drawLine(drawColor, oldx, oldy, e.getX(), e.getY(),
                    drawThickness, this.mode_paint);
              dragging = false;
         else if (drawType == this.text)
              if (floatingText)
                   // The user wants to place the text (s)he created.
                   // Erase the old draft text
                   drawText(drawColor, draftText.x, draftText.y,
                                            draftText.text, this.mode_xor);
                       String str = Integer.toString(e.getX());
                       String str1  = Integer.toString(e.getY());
                       coor.append(str + " " + str1 + "\n");
                   // Set the new coordinates
                   draftText.x = e.getX();
                   draftText.y = e.getY();
                   // Draw the permanent text
                   drawText(drawColor, draftText.x, draftText.y,
                         draftText.text, this.mode_paint);
                   floatingText = false;
         public void mouseDragged(MouseEvent e)
            if (drawType == this.freehand)
              drawLine(drawColor, oldx, oldy, e.getX(), e.getY(),
                    drawThickness, this.mode_paint);
              oldx = e.getX();
              oldy = e.getY();
         else
             dragging = true;
         if (drawType == this.line)
            // Erase the old draft line
            drawLine(draftLine.color, draftLine.startx, draftLine.starty,
              draftLine.endx, draftLine.endy, drawThickness,
              this.mode_xor);
            // Draw the new draft line
            draftLine.endx = e.getX();
            draftLine.endy = e.getY();
            drawLine(draftLine.color, draftLine.startx, draftLine.starty,
              draftLine.endx, draftLine.endy, drawThickness,
              this.mode_xor);
         public void mouseMoved(MouseEvent e)
             if (floatingText)
              // When the user has entered some text to place on the
              // canvas, it remains sticky with the cursor until another
              // click is entered to place it.
              // Erase the old draft text
              drawText(drawColor, draftText.x, draftText.y,
                                draftText.text, this.mode_xor);
              // Set the new coordinates
              draftText.x = e.getX();
              draftText.y = e.getY();
              // Draw the new floating text
              drawText(drawColor, draftText.x, draftText.y,
                        draftText.text, this.mode_xor);
         //declare  a class for the line shown before the is as wanted
        class tempLine
         public Color color;
         public int startx;
         public int starty;
         public int endx;
         public int endy;
         public int thickness;
         public tempLine(Color mycolor, int mystartx, int mystarty,
                      int myendx, int myendy, int mythickness)
             color = mycolor;
             startx = mystartx;
             starty = mystarty;
             endx = myendx;
             endy = myendy;
             thickness = mythickness;
        class tempText
         public Color color;
         public int x;
         public int y;
         public String text;
         public tempText(Color mycolor, int myx, int myy, String mytext)
             color = mycolor;
             x = myx;
             y = myy;
             text = mytext;
    }

    http://www.java2s.com/ExampleCode/2D-Graphics/DemonstratingUseoftheImageIOLibrary.htm

Maybe you are looking for

  • HTML links from Full Check Accessibility report do not open the corresponding PDF links

    I regularly generate full Check accessibility reports for the PDF user guides I create in MSWord. However, when I click the links in the HTML file/report generated, they are supposed to link/highlight the corresponding errors in the PDf file. Instead

  • Oracle 10.1.3.

    Hi, I recently installed oracle app server 10.1.3 and following the instructions Reconfiguring Application Server Instances I tried to make it so that my 10.1.3 app server can use SSO with my 10.1.2 infrastructure. I deployed an application on 10.1.3

  • FULL_SCREEN_INTERACTIVE

    Hi, I am trying to use fullscreen mode with an keydown event in extendet desktop environment. But using the interactive mode won't turn my application into fullscreen and FULL_SCREEN doesn't allow keydown listener.      stage.displayState = StageDisp

  • Report Builder 3.0.5.8.0 using a servlet

    hi I am trying calling the Reports server using a servlet. i need to find if i get a confirmation from the reports server that the report is generated. In which case I would be able to throw the same to the browser. Naresh

  • How to Create simple WCF/REST (JOSN,get and post) and deploy to Sharepoint 2013 Server.

    HI All,    I wan to create a simple WCF/REST service and deployed to SharePoint server , i have created some sample svc file and put in to _vti_bin folder using SharePoint solution using vs 2013 but its not accessible from IIS its always asking the W