How do I draw an image through a rectangle?

I have worked with c# in the past, and i remember being able to draw an image but drawing it within the bounds of the rectangle. I would do this so collision detection was easy. Any suggestions?
btw since im so very new to the language, i am even having trouble with g.drawImage stuff :(
any help would be amazing -_-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

hollow wrote:
hmm ya i was messing around with that already, i guess im just retarded. i will keep looking thanks! ><No, you are not retarded. You are just incredibly impatient. Take a step back and ease yourself into the language. Take the time to read some articles while you're at it. I would also take a look at JavaFX2, it is a more modern approach to client application development and is less clunky than Java2D with a very active community. It might be that you are more comfortable with it.

Similar Messages

  • Help!How can i draw an image that do not need to be displayed?

    I want to draw an image and save it as an jpeg file.
    first I have to draw all the elements in an image object.I write a class inherit from Class Component,I want to use the method CreateImage,but I get null everytime.And i cannot use the method getGraphics of this object.Thus i can not draw the image.
    when i use an applet,it runs ok.I use panel and frame,and it fails.
    How can i draw an image without using applet,because my programme will be used on the server.
    Thank you.

    you could try this to create the hidden image
    try
              GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
              GraphicsDevice gs = ge.getDefaultScreenDevice();
              GraphicsConfiguration gc = gs.getDefaultConfiguration();
              offImage = gc.createCompatibleImage(100, 100);
              offG = offImage.getGraphics();
          catch(Exception e)
              System.out.println(e.getMessage());
          }

  • How do I draw an image on a JPanel?

    To be honest I have no idea even where to start. I tried hacking through the tutorials but it just didn't help me (normally they do, I don't what's up).
    Anyway, so what I'm trying to do is build a game. The Graphics2D is great for simple shapes but drawing characters is getting kind of ridiculous (tedious + difficult + looks bad). So, I need to figure out how to display an image on a JPanel.
    To that end I have several questions.
    1 - What image type do I use? Like jpeg, bmp, gif, etc.
    2 - How do I make parts of it transparent?
    3 - How do I make it appear on the screen, given some coordinates on the JPanel?

    To draw an image directly to a JPanel given certain coordinates, you have to create a custom JPanel and override its paintComponent() method. Like this:
    class PaintPanel extends JPanel{
    public void paintComponent(Graphics g){
    super.paintComponent(g);
    //painting code goes here}
    }Java can load in and draw GIF and JPEG images. If you decide to use GIF files, any good image editor like Adobe Photoshop should be able to make them transparent for you before the fact. If you want to set transparency within your java program you will have to create a BufferedImage and make certain colors within it transparent, but I would like to know how to do that as much as you do.

  • How can I draw an image in the browser using mouse

    I have to draw an image in the browser and have to store a file in the server and I don't know how can I do it. Is there anybody who konw it.

    Components other than applets cannot be downloaded into client machines
    unleess There is a Java Web Start kind of Mechanism present on client and the server also supports
    this .Hence your application is between Applet ---Xdownloadable ApplicationXX ---- traditinal Application

  • How can I send an image through a WebService

    Hi,
    I'm trying to send an image through a WebService to a mobile phone, but I can't get it working.
    Anyone knows how I can send an image on the server side, and receive it on the client side?
    Thanks for your help.

    Hope this will help
    String encodingStyleURI = org.apache.soap.Constants.NS_URI_SOAP_ENC;
    SOAPMappingRegistry smr = new SOAPMappingRegistry();
    BeanSerializer beanSer = new BeanSerializer();
    try {
    // Build the call.
    Call call = new Call();
    call.setSOAPMappingRegistry(smr);
    call.setTargetObjectURI("urn:filereceiver");
    call.setMethodName("loopFile");
    call.setEncodingStyleURI(encodingStyleURI);
    Vector params = new Vector();
    DataSource ds = new ByteArrayDataSource(new File(fname),
                                  null);
    DataHandler dh = new DataHandler(ds);
    params.addElement(new Parameter("addedfile",
                             javax.activation.DataHandler.class, dh, null));
    params.addElement( new Parameter( "filename", String.class,fname, null ) );
    call.setParams(params);
    // Invoke the call.
    Response resp;
    try {
         System.out.println(url);
    resp = call.invoke(url, "");
    } catch (SOAPException e) {
              FLAG          ="NO";
              System.err.println("Caught SOAPException (" +
                        e.getFaultCode() + "): " +
                        e.getMessage());
              e.printStackTrace();
    return FLAG;
    // Check the response.
    if (!resp.generatedFault()) {
    Parameter ret = resp.getReturnValue();
    if (ret == null){
    System.out.println("No response.");
              FLAG="NO";
    else {
              // System.out.println("Response: " + resp);
    // printObject(ret.getValue());
    } else {
    Fault fault = resp.getFault();
              FLAG          ="NO";
    System.err.println("Generated fault: ");
    System.err.println(" Fault Code = " + fault.getFaultCode());
    System.err.println(" Fault String = " + fault.getFaultString());

  • How can I draw an image when the mouse is clicked

    I am trying to draw X's and O's for a tic-tac-toe board and I cannot conceptualize how to get the X or O to appear if the mouse is pressed on an individual [row][col].
    Im using the MouseListener with a mouseAdapter as an inner class of paintComponent. Using the mousePressed method I want to draw the X or O when one square detects a mousepress
    How can I get the image on the partiuclar square. Im stumped presently. Any help is appreciated
    Thanks.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TicTacToe extends JPanel
        Rectangle[] cells;
        int[] hits;
        final int
            GRID =  3,
            PAD  = 25;
        public TicTacToe()
            // jvm initializes all elements to zero by default
            hits = new int[GRID * GRID];
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            int w = getWidth();
            int h = getHeight();
            int xInc = (w - 2*PAD)/GRID;
            int yInc = (h - 2*PAD)/GRID;
            if(cells == null)
                initCells(xInc, yInc);
            // vertical lines
            int x1 = PAD + xInc, y1 = PAD, x2 = w-PAD, y2 = h-PAD;
            for(int j = 0; j < GRID-1; j++)
                g2.drawLine(x1, y1, x1, y2);
                x1 += xInc;
            // horizontal lines
            x1 = PAD; y1 = PAD + yInc;
            for(int j = 0; j < GRID-1; j++)
                g2.drawLine(x1, y1, x2, y1);
                y1 += yInc;
            // draw hits
            g2.setPaint(Color.red);
            for(int j = 0, side = 30; j < hits.length; j++)
                if(hits[j] == 1)
                    int row = j / GRID;
                    int col = j % GRID;
                    int x = PAD + xInc/2 + col * xInc - side/2;
                    int y = PAD + yInc/2 + row * yInc - side/2;
                    g2.fillRect(x, y, side, side);
            //g2.setPaint(Color.blue);
            //for(int j = 0; j < cells.length; j++)
            //    g2.draw(cells[j]);
        public void addHit(int cellIndex)
            hits[cellIndex] = 1;
            repaint();
        private void initCells(int width, int height)
            cells = new Rectangle[GRID * GRID];
            for(int row = 0; row < GRID; row++)
                for(int col = 0; col < GRID; col++)
                    int index = col + row * GRID;
                    int x = PAD + col * width;
                    int y = PAD + row * height;
                    cells[index] = new Rectangle(x, y, width, height);
        public static void main(String[] args)
            TicTacToe ticTacToe = new TicTacToe();
            Selector selector = new Selector(ticTacToe);
            ticTacToe.addMouseListener(selector);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(ticTacToe);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class Selector extends MouseAdapter
        TicTacToe ticTacToe;
        public Selector(TicTacToe ttt)
            ticTacToe = ttt;
        public void mousePressed(MouseEvent e)
            Point p = e.getPoint();
            Rectangle[] r = ticTacToe.cells;
            for(int j = 0; j < r.length; j++)
                if(r[j].contains(p))
                    ticTacToe.addHit(j);
                    break;
    }

  • How to load the Employee Images through Script

    Dear All,
    How to load Employee Images into HRMS module through script, Pls provide scripts any body having..
    Thank in advance,
    Hanimi
    Edited by: Hanimi on Jun 7, 2011 10:12 AM

    Hi Hussain,
    Following ctl file is working fine for loading images, But problem is at a time it is loading only 64 rows, pls let me know what i have change in my ctl file for loading all data at a time..
    load data
    infile '/usr/tmp/Images_Data.dat'
    INTO TABLE PER_IMAGES
    append
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS(
    parent_id,
    table_name constant "PER_PEOPLE_F",
    ext_fname FILLER CHAR(80),
    "IMAGE" LOBFILE(ext_fname) TERMINATED BY EOF,i
    mage_id "PER_IMAGES_S.nextval"
    Thanks,
    Hanimi..

  • How can I spread an image through multiple shapes?

    I have a large image im wanting to use to do a sort of peek-a-boo through multiple small triangle shapes i've created. Is there a way to do this?

    Select all your shapes, and choose: objects > paths > make compound path. Then you can place your photo into the compound path and it will span all the shapes.

  • How do i load an image through XML?

    Hi.
    My code is below. What I am trying is to dinamically load images from xml. I attach the holder from the library, and when i try to target it and addChild to him i get an error:
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();
    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
    xmlLoader.load(new URLRequest("links.xml"));
    var xmlLength:int;
    var iconPos:Number = 0;
    function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    var xmlLength = xmlData.link.length();
    for (var i=0; i<xmlLength; i++) {
    var d:MovieClip = new icon();
    content_mc.addChild(d);
    d.name = "d"+i;
    var target:DisplayObject = content_mc.getChildByName("d"+i);
    var ldr:Loader = new Loader();
    ldr.load(new URLRequest(xmlData.link[i].icon));
    target.addChild(ldr);
    How can i make this happen and load the image into it's holder?
    Thank you.

    Code from adobe's sample packages cut&&paste&&edit:
    AS4 code:
    import flash.events.IOErrorEvent;
    var fotoElenco:Array;
    var fotoXML:XML;
    var fotoURLRequest:URLRequest=new URLRequest();
    var fotoURLLoader:URLLoader=new URLLoader();
    var fotoLoader:Loader=new Loader();
    var fotoPosition:Number=0;
    var errorMessage:TextField=new TextField();
    caricaFoto();
    function caricaFoto():void
        addChild(errorMessage);
        fotoURLRequest.url="gallery.xml";
        fotoURLLoader.load(fotoURLRequest);
        fotoURLLoader.addEventListener(Event.COMPLETE, showFoto);
        fotoURLLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorEventXML);
    function ioErrorEventXML(event:IOErrorEvent):void
        manageErrorMessage(true, 0);
    function manageErrorMessage(val:Boolean, num:Number):void
        if(val && num==0){
            errorMessage.x=stage.stageWidth/2;
            errorMessage.y=stage.stageHeight/2;
            errorMessage.text="Errore caricamento file XML";
        if(val && num==1){
            errorMessage.x=stage.stageWidth/2;
            errorMessage.y=stage.stageHeight/2;
            errorMessage.text="Errore caricamento file IMMAGINE";
    function showFoto(event:Event):void
        fwd_mc.buttonMode=true;
        back_mc.buttonMode=true;
        back_mc.addEventListener(MouseEvent.CLICK, manageFoto);
        fwd_mc.addEventListener(MouseEvent.CLICK, manageFoto);
        fotoElenco=new Array();
        fotoXML=XML(fotoURLLoader.data);
        for each(var prop:XML in fotoXML.foto)
            fotoElenco.push({url:prop.@url, didascalia:prop.@didascalia});
        viewFoto(fotoPosition);
        gallery_mc.addChild(fotoLoader);
        manageButton();
    function manageButton():void
        if(fotoPosition<1){
            back_mc.visible=false;
        }else{
            back_mc.visible=true;
        if(fotoPosition>=fotoElenco.length-1){
            fwd_mc.visible=false;
        }else{
            fwd_mc.visible=true;
    function manageFoto(event:MouseEvent):void
        switch(event.currentTarget)
            case fwd_mc:
                if(fotoPosition<fotoElenco.length-1)
                    fotoPosition++;
            break;
            case back_mc:
                if(fotoPosition>0)
                    fotoPosition--;
            break;
        viewFoto(fotoPosition);
    function viewFoto(num:Number):void
        fotoLoader.load(new URLRequest(fotoElenco[num].url));
        fotoLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorEventIMG);
        didascalia_txt.text=fotoElenco[num].didascalia;
        manageButton();
    function ioErrorEventIMG(event:IOErrorEvent):void
        manageErrorMessage(true, 1);
    XML code:
    <?xml version="1.0" encoding="UTF-8"?>
    <gallery>
        <foto url="img/immagine1.jpg" didascalia="Didascalia 1 foto"/>
        <foto url="img/immagine2.jpg" didascalia="Didascalia 2 foto"/>
        <foto url="img/immagine1.jpg" didascalia="Didascalia 1 foto"/>
        <foto url="img/immagine2.jpg" didascalia="Didascalia 2 foto"/>
    </gallery>

  • How do you draw an image into a certain field in applet layout?

    i need to to take a image drawn from a function and place it in the "center" field of a borderlayout applet...

    Check out the link shown below for a complete example on how to do this:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=226875
    V.V.

  • How to send an 'jpeg' image through XI?

    Can I send an image in the form of 'giff' or 'jpeg' type through XI?
         If so, please provide any blogs or documents regarding this.
    Thanks in advance,
    Dhana.

    Hi
    From the document : http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/2016a0b1-1780-2b10-97bd-be3ac62214c7&overridelayout=true
    Large File Handling
    In transaction code SXMB_ADM, Integration Engine Configuration, you can maintain parameter EO_MSG_SIZE_LIMIT of category TUNING to process large messages in series. This applies to any kind of messages however especially files usually exceed the best performing message size, and hence this is mentioned here. Once set, all messages exceeding the specified value are processed in series in a separate message queue. Recommendation
    Maintain the parameter in order to avoid that parallel processing of multiple large messages exceeds main memory resources. Furthermore, since large messages are processed in a separate queue the processing of smaller messages won't be affected or even blocked.
    For large text files containing multiple records, you can split the same into multiple messages in the file/ftp adapter. This applies when File Content Conversion mode is chosen. In the communication channel, you have to maintain parameter Recordsets per Message.
    For more details, please refer to SAP Help Portal http://help.sap.com, navigate to SAP NetWeaver 7.0 u2192 SAP NetWeaver 7.0 Library u2192 SAP NetWeaver Library u2192 SAP NetWeaver by Key Capability u2192 Process Integration by Key Capability u2192 SAP NetWeaver Exchange Infrastructure u2192 Runtime u2192 Connectivity u2192 Adapters u2192 File/FTP Adapter u2192 Configuring the Sender File/FTP Adapter u2192 Converting File Content in a Sender Adapter
    Pooja.

  • How can I draw a image in transparent mode

    I write a applet which derived from JApplet. I want to draw a icon on It's content panel transparently, but it seems that ImageIcon can't handle *.ico.
    What should I do?

    It's solved.
    .gif can do this thing.

  • How to use recursion with images

    Ok, for this program I'm trying to recursively repeat an image 3 times with varying widths and heights, and I don't know how to do that with images. With rectangles and other shape objects it's easy because all I had to do was override the draw method, but with images I'm not sure what to override to allow me to repeat the drawing of it with a different height and width. Any help would be greatly appreciated.

    Would I be able to work that in with recursion? Currently I have a JPanel with the paintComponent method being overridden, and I've tried setting up the paintComponent method to call itself to repaint the image, but I've realized everytime I resize the application's window paintComponent gets called again making the images go out of site. Is there a way to override the drawImage method to allow me to change the width and height of the image without causing the panel to repaint itself?

  • Draw circles,images in flex

    How can we draw circles,images in flex? (ex as in
    ms-paint)

    http://livedocs.adobe.com/flex/3/html/help.html?content=Drawing_Vector_Graphics_1.html

  • How to use Draw documnet wizar to a  user form?

    Hi all,
             I  have created one form with matrix.I want to get a  copy of sales quotation's data in my form. How to get through coding.
    (How to use Draw document wizard through coding)
             My form using UDO.Just like In my form i have created one button .If i click that button the list of sales quotations for the particular cutomer has to be displayed.
              From that i have to select one quotation,that data has to be filled   in my form.
             Please help me.How to do that?
            What is the menu ID for Draw document wizard.If i get that how can i link it with the my form having datas using UDO.
             Please help me to solve this problem
    Regards
    V.Rangarajan

    Hi,
    If you want to search for a specific menu ID you only have to activate the "System Information" with the B1 menu View -> System Information. After that when you use the Menus in the top of B1 application (all menus included the same ones as in the Modules form) you will be able to ee the MenuIDs in the bottom of B1 application.
    If you want to open a document form with information inside it I will say to better create a grid with the list of documents you want to show everytime (please have a look to UI API Grid item in help file, there is also a sample in the SDK UI samples) and make one of the columns a LinkButton, when the user will click in the link button the document form will open automatically. You have also many posts talking about how to create a link button in a grid, please use the search capabitility of this forum.
    Hope it helps
    Trinidad.

Maybe you are looking for

  • Htmlb:get the values from bean n display it in textView

    Hi, I am doing one PDK application using jspdyn page. In jsp page I am using htmlb to display the table. In that I am using one text view element. There I need to get the values from bean class.And display it in a table. Can anyone help me how can us

  • 'Fixing' default Zoom level when document is opened

    I wanted to add this to an existing Thread, but could find no option to do so. To fix the default Zoom level, e.g. to 100%, when opening a PDF with Reader X - click 'Edit' in Menu bar>Preferences (bottom of drop-down menu list)>Page Display (in 'Cate

  • No purchase requisitions generated

    Hi, How come no PRs are generated after the MRP run for my raw materials? My demand comes from PIR for the FG, which has a strategy group of 40. In MD04 after MRP run, IndReq are created. However, in the lower level material, no dep reqs are created.

  • Disappearing custom shapes

    i've posted about this before, but never received a single answer. hopefully meanwhile someone's figured out what's going on so, i followed, step by step, the ken stone tutorial on making custom shapes - highly recommended set of tutorials on this an

  • Unable to set completion due date on a task in wli 10.3

    In the task plan that I have created I have set the property "Completion Due Date" to 7 days in the properties tab for the step, yet when I view that task that gets created from this in the Worklist User Portal the Completion Due date is still not se