How paint method in TiledLayer work ?

It's my 1st time in forum. Does anyone has source code of Sprite, TiledLayer class or know how exactly the paint method work? I had used it in some game but not satisfied with it. I want to code my own class but i wonder it has some native or low-level code.
Sorry for my poor E !!!

perhaps you want to use a more hardware oriented approach. I can highly recommend you the Slick API. It is built on top of the LWJGL API set, which is a Java binding for OpenGL, OpenAL and provides device support such as joysticks/joypads. Slick turns the 3D part into an easy to use 2D rendering framework.
[http://slick.cokeandcode.com/|http://slick.cokeandcode.com/]
Basic example program:
[http://slick.cokeandcode.com/wiki/doku.php?id=01_-_a_basic_slick_game|http://slick.cokeandcode.com/wiki/doku.php?id=01_-_a_basic_slick_game]

Similar Messages

  • Help with 2D Graphics - How do I send Variable data to paint method?

    I am working on a program that figures mortgage payments and an amortization schedule when a user inputs the principle, APR, and term length in years. After it figures all of those, I want to be able to display a chart that shows the principle and interest amounts for each year. My problem is, how do I get my loan information into my paint method so that I can draw a chart using that data? Any help would be greatly appreciated. The graph class in the code below is called after pressing a "Display Graph" button from my GUI.
    I'm pasting my code below. This does not include my main method or my GUI method. I can post those if necessary. Here is my code so far:
    import java.util.*;
    import java.lang.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.io.*;
    import java.lang.Math;
    public class Graph extends JFrame
         public Graph(double dCurrentBalance, double dMonthlyPmt, double dRate, int iTime)
              final double balance = dCurrentBalance;
              JFrame graphFrame;
              int iCounter = 0;
              int iPmtNumber = 0;
              double dCurrentInt = 0.0;
              double dCurrentPrinciple = 0.0;
              double dMPR = 0.0;
              int yCoordInt = 0;               //integer for Y coordinate for Interest
              int yCoordPrinciple = 0;     //integer for Y coordinate for Principle
              iTime *= 12;               //determine number of months for this loan
              iCounter = iTime;          //set loop counter to number of months for this loan
              dMPR = dRate/12;          //determine monthly periodic rate
              graphFrame = new JFrame ("mCalc Graph");
              graphFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              graphFrame.setSize(800,600);
              graphFrame.setResizable(false);
              // center graphFrame on the screen
         Dimension ScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
         Dimension FrameSize = graphFrame.getSize();
         if (FrameSize.height > ScreenSize.height)
         FrameSize.height = ScreenSize.height;
         if (FrameSize.width > ScreenSize.width)
         FrameSize.width = ScreenSize.width;
         graphFrame.setLocation((ScreenSize.width - FrameSize.width) / 2,
                   (ScreenSize.height - FrameSize.height) / 2);
              //Displays graphFrame
              Graphic graphicPane = new Graphic();
              graphFrame.add(graphicPane);
              graphFrame.setVisible(true);
              //This loops until all payments have been figured
              for (; iCounter > 0; )
         iPmtNumber++;
         dCurrentInt = dCurrentBalance * dMPR;
         dCurrentPrinciple = dMonthlyPmt - dCurrentInt;
         dCurrentBalance = dCurrentBalance - dCurrentPrinciple;
                   if (iPmtNumber%12 == 0)
    //           System.out.println("dCurrentBalance = " + dCurrentBalance);
    //                    System.out.println("Payment # = " + iPmtNumber);
    //                    System.out.println("dCurrentInt = " + dCurrentInt);
    //                    System.out.println("dCurrentPrinciple = " + dCurrentPrinciple);
         iCounter = iCounter-1;
              } //end for loop
         } //end Graph constructor
    /* This class needs to be personalized to include my own variable names,
    *     etc. I also need to find a way to bring in data from the Graph class.
         class Graphic extends JPanel
              public void paintComponent(Graphics comp)
                             int i; // Declare the variables used to generate the chart
    float xLoc = 50; // Location of the X Axis along Y
    float yLoc = 50; // Location of the Y Axis along X
    Line2D.Float LnA; //
    super.paintComponent(comp);
                   // Establish a tie between this subroutine and the Graphic
    Graphics2D comp2D = (Graphics2D) comp;
    // Cast the Graphics named comp to a Graphics2D as comp2D
    comp2D.setColor(Color.white);
    // Set the background color
    comp2D.fillRect(0,0,800,600);
    // Draw the X and Y axis
    comp2D.setColor(Color.black); // Set the pen color to black
    Line2D.Float YAxis = new Line2D.Float(50,50,50,getSize().height - 50); // Define the Y-Axis
    Line2D.Float XAxis = new Line2D.Float(50F,getSize().height - 50F, getSize().width -50F, getSize().height -50F); //Define the X-Axis
    comp2D.draw(YAxis); // Draw the Y-Axis
    comp2D.draw(XAxis); // Draw the X-Axis
    Font font = new Font("Dialog", Font.BOLD, 12); // Set the font for the Axis labels
    comp2D.setFont(font);
    float increment = 15;
    // Draw the line
    xLoc += increment;
    comp2D.setColor(Color.red);
    /* Need to find a way to bring in my own data to use for the
    * yLoc variables.
    for (i=1; i<=45; i++)
    { // Begin making the graph
    if (i < 30)
         yLoc += increment;
    } else {
         yLoc -= increment;
    // Scale the location to the graph height
    LnA = new Line2D.Float( xLoc, getSize().height - 50F , xLoc, yLoc); // Create the line
    comp2D.draw(LnA); // Draw the line
    xLoc += increment;
                             }//end for
                   }//end paintComponent
              } //end class Graphic
    } //end class Graph
    Any help would be GREATLY appreciated! Thanks.
    Message was edited by:
    russedl
    My email address iss [email protected] if you wish to reply privately. I can send my entire program code if that will help. Thanks!

    Hi Deca,
    You can use the CmdExecuteSync method of the DIAdem.TOCommand interface to set the value of a text channel. For example passing the string "CHT(1,1) := 'test'" as a parameter to the CmdExecuteSync method will set the 1st row of the 1st channel to "test". Please refer to the DIAdem help for more documentation on the CHT function.
    I hope this helps! Please post back if I wasn't clear enough in explaining how to do this or if you have any problems getting it to work.
    Regards,
    Sarah Miracle
    National Instruments

  • I cannot figure out how to make the text larger on an incoming email.  The finger method doesn't work and I cannot find any toolbar with which to do it.  I could find nothing in settings also.  Plese help and thank you.

    I cannot figure out how to make the text larger in a received email.  The finger method doesn't work and I can find no tool bar as I can for composing emails.  I can find nothing in settings.  Please help and thank you in advance.

    Hi there,
    Download a piece of software called TinkerTool - that might just solve your problem. I have used it myself to change the system fonts on my iMac. It is software and not an app.
    Good wishes,
    John.

  • I plug my iPhone 3gs into my laptop and it no longer syncs with my iTunes.  Ive tried all the trouble shooting methods and nothing works.  My iPhone doesnt appear on iTunes or under "my computer." Does anyone know how to fix this?

    I plug my iphone 3gs into my laptop and it no longer syncs with my iTunes.  I've tried all the trouble shooting methods and nothing works.  My iPhone doesn't appear on iTunes or under "My Computer." Does anyone know how to fix this?

    If AMDS is running, you are using a USB port directly on the computer and not a hub, you have disconnected other USB devices except keyboard and mouse, you have completely uninstalled and reinstalled iTunes as described in http://support.apple.com/kb/HT1925, You have tried cleaning the connector on the bottom of the phone, you have tried a different cable, you have installed the latest USB drivers for your computer, you have disabled your antivirus and firewall, you are running as an Administrator account and you have tried creating a new user on your computer and connected when logged in as that user then you have exhausted my knowledge. The only other thing to try is a different computer. If it isn't recognized on a different computer you have a hardware problem. Good luck!

  • Please explain how the method CHECK_CHANGED_DATA works?

    Hi experts,
       Can any of you experts please explain how the method <b>CHECK_CHANGED_DATA</b>
    of <b>CL_GUI_ALV_GRID</b> class works ?
    Thanks in advance
    regards,
    Ashwin

    DATA: l_valid TYPE c.
    Data grid1 type ref to cl_gui_alv_grid.
    CALL METHOD grid1->check_changed_data IMPORTING e_valid = l_valid.
    This method checks if any data is changed on the grid if there any editable fields .
    And updates the changed values
    Message was edited by:
            Chandrasekhar Jagarlamudi

  • How to use an object's paint method

    I have created a class imagePanel which extends a jPanel to display an image. When I create a new imagePanel object I pass it an image argument which is used to paint my image on the jPanel, so far so good. I don't wish to have to continuously create new ImamePanels to display new images so I thought I could make a set_Image method that would set a new image in an exising imagePanel object. This is where I run into problems how to use the existing object paint method to replace the image. I tried this without success:
    public Image setMyImage (Image myImage)
    imageX = myImage; // imageX is the image that is painted by the imagePanel object's paint method
    paint(g);
    Something must be wrong on how I access the paint method. Thanks for any help.
    Jack

    Yahoooo, got it. This was the code I needed and thanks for your help:
    public void setImage (Image myImage)
    imageX = myImage;
    repaint(300);
    }

  • How do I print in B&W now that I have lion? The whole "open in preview" method is not working. Thanks

    Subject says it all.....The whole "open in preview" method is not working. Any ideas or solutions would be appreciated. Thanks

    What kind of printer do you have? Have you looked at their PDEs to see if there are any settings for color/b&w?
    How is the "open in Preview" not working? Please provide some details.

  • SetBounds method is not working - settings change after Applet paint()

    Hello,
    I'm creating an applet with a scrollbar on it. I'm using Scrollbar.setBounds to set its position and dimension. These values are correct at the end of the init() method, but when the paint() method starts executing, these values have changed!
    Here's my code :
    import java.awt.Graphics;
    import java.awt.Scrollbar;
    public class testSetBounds extends java.applet.Applet {
      Scrollbar sb;
      public void init(){
        sb = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 270);
        sb.setBounds(10, 200,300,10) ;
        this.add(sb);
        System.out.println("sb.getWidth() " + sb.getWidth() );
        System.out.println("sb.getBounds().x " + sb.getBounds().x  ) ;
      public void paint(Graphics g){
        System.out.println("paint...") ;
        System.out.println("sb.getWidth (at start of paint()) " + sb.getWidth() );
        System.out.println("sb.getBounds().x " + sb.getBounds().x  ) ;
        System.out.println("sb.getMaximum() " + sb.getMaximum()) ;
    <html>
    <body>
    <applet code="testSetBounds" codebase="classes" width="300" height="350">
    </applet>
    </body>
    </html>
    The output I get on the Java Console is:
    sb.getWidth() 300
    sb.getBounds().x 10
    paint...
    sb.getWidth (at start of paint()) 50
    sb.getBounds().x 125
    Can anyone tell me what's going on?
    How to make my scrollbar remain in the position and with the dimensions I specified?
    Thank you very much.

    The layout manager is setting the bounds. If fo some obscure reason you want to do all the layout yourself then -
    Hello,
    I'm creating an applet with a scrollbar on it. I'm
    using Scrollbar.setBounds to set its position and
    dimension. These values are correct at the end of the
    init() method, but when the paint() method starts
    executing, these values have changed!
    Here's my code :
    import java.awt.Graphics;
    import java.awt.Scrollbar;
    public class testSetBounds extends java.applet.Applet
    Scrollbar sb;
    public void init(){
    sb = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0,
    , 0, 270);
    sb.setBounds(10, 200,300,10) ;this.setLayout(null);
    this.add(sb);
    System.out.println("sb.getWidth() " +
    " + sb.getWidth() );
    System.out.println("sb.getBounds().x " +
    " + sb.getBounds().x ) ;
    public void paint(Graphics g){
    System.out.println("paint...") ;
    System.out.println("sb.getWidth (at start of
    t of paint()) " + sb.getWidth() );
    System.out.println("sb.getBounds().x " +
    " + sb.getBounds().x ) ;
    System.out.println("sb.getMaximum() " +
    " + sb.getMaximum()) ;
    <html>
    <body>
    <applet code="testSetBounds" codebase="classes"
    width="300" height="350">
    </applet>
    </body>
    </html>
    The output I get on the Java Console is:
    sb.getWidth() 300
    sb.getBounds().x 10
    paint...
    sb.getWidth (at start of paint()) 50
    sb.getBounds().x 125
    Can anyone tell me what's going on?
    How to make my scrollbar remain in the position and
    with the dimensions I specified?
    Thank you very much.

  • How to use paint method to draw in many componets.

    Hi!
    I have code like this:
    public class MainPanel extends JPanel{
       JPanel p1;
       JPanel p2;
       public MainPanel(){
           super(new BorderLayout());
           p1 = new JPanel();
           p2 = new JPanel();
           add(p1 , BorderLayout.Center);
           add(p2 , BorderLayout. West);
           setVisible(true);
    @Override
        protected void paintComponent(Graphics g) {
           g.setColor(Color.red);
           g.fillrect(10,10,10,10);
    }This code is onle an example. Supose, this code will paint black rectangle on "main panel" to which p1 and p2 are added. What should i do to be able to paint this rectangle on p1 or p2 without creating separate classes in which i will override paintComponents() method for p1 and p2. I would like to avoid creating separete classes for each panels. Is there any way to do that using one paint Components method. Thanks in advance for all respone.

    (where's Darryl when you need him?)Erm, Pete, since when did I become an expert lol?
    Lost my hard disk, its been hiccuping for a couple of weeks now. I'm running on an old 20 GB PATA with a 5GB c drive. No IDE, no offline Javadoc. I'll get a HDD in the morning, but I hope I can spin up the old disk at least once and recover the last week's "work" ... just fun stuff actually.
    Why does this code draw rectangles just for split second?repaint() (and consequently paint(), paintComponent() and other painting methods) may be called by the system any time it is detected that the component needs to be repainted. Since you do not have a override for paintComponent, it will perform its default painting and paint the entire component, wiping out your rectangle.
    For persistent drawing on a JPanel or JComponent I know only one way: override paintComponent. If you need to avoid this, you could go with morgalr's suggestion to use JLabel.
    For this you would draw the triangle/rectangle/whatever to a BufferedImage, then call label.setIcon with a new ImageIcon constructed from the BufferedImage.
    Also, avoid obtaining a Graphics reference via getGraphics. During the lifetime of a visible component, various different Graphics references may be passed into the paintComponent method, so the reference you obtain may not be current. getGraphics can also return null.
    luck, db

  • HT201272 My pay method has stopped working, so that now I can't purchase anything from my iPad anymore,even when there's money in my account. How do I resume using my pay method to purchase.

    My pay method has stopped working so that I can no longer purchase and/or download any apps or products onto my iPad. It is saying "there was a problem with a previous purchase. Use another pay method. What does this mean, and what do I do?
    Further, in my attempts to correct the situation, I reset my iPad, resulting in my losing all the apps that I downloaded, and all the products I had bought and downloaded. How do I recover all of them (magazines,  books, apps, etc).
    Please, help.
    Victor Kalala

    Look, I understand I still need a card attached to the account. The problem is, it won't accept my card because I only have 87 cents in my bank account right now.
    If I had known there would be so much trouble with the iTunes card, I would have just put the cash in my bank account in the morning instead of buying an iTunes card (I didn't expect the banks to be open on Thanksgiving of course).
    Apple will only accept cards that have a balance. The balance is so small in my account that it won't accept it as a valid card.
    I'm going to have to contact Apple anyway to reset the security questions. That's obvious. Your answers were not exactly helpful. You didn't tell me anything I don't already know, but thanks for trying to be helpful.

  • Confused by how Paint Brushes Work

    I draw a rectangle in object mode, and using the Brush Mode
    options:
    a) paints fill paints behind the shape. What is considered
    the fill in this example?
    b) paints inside, seems to paint inside the shape, however,
    if I start painting outside the shape and into the shape, the
    stroke appears only outside of the shape and not inside.
    When drawing the shape in non-object mode:
    a) Paints fill paints both on top and outside of the shape
    b) paints inside, seems to paint inside the shape, however,
    if I start painting outside the shape and into the shape, the
    stroke appears only outside of the shape and not inside.
    Can anyone clarify how this is supposed to work?
    Thanks!!!

    I draw a rectangle in object mode, and using the Brush Mode
    options:
    a) paints fill paints behind the shape. What is considered
    the fill in this example?
    b) paints inside, seems to paint inside the shape, however,
    if I start painting outside the shape and into the shape, the
    stroke appears only outside of the shape and not inside.
    When drawing the shape in non-object mode:
    a) Paints fill paints both on top and outside of the shape
    b) paints inside, seems to paint inside the shape, however,
    if I start painting outside the shape and into the shape, the
    stroke appears only outside of the shape and not inside.
    Can anyone clarify how this is supposed to work?
    Thanks!!!

  • How to add more than one paint method

    hi everyone
    I am doing a project in which i have already created a paint method but i find that there is necessity to create one more
    paint method within the same file in which i have a paint method pls tell me how to how to add a paint method how to call the repaint method
    please its very urgent

    By even suggesting that I can gather you have a horrible design of what ever you are doing--DON'T! And go back and refactor your application so you do not need or even want such a thing to happen.
    1 - paint is for use in AWT. If you are using AWT, then very well, you are at least using the right method to override. If you are using SWING, then you are totally messed up before you even arrived at this ill conceived plan of 2 paint methods.
    2 - your paint (AWT)/paintComponent (SWING) is a system called method driven by events you haven't any control over. You need to treat it as such.
    3 - your painting method should be very tight. I will bet your's is a horrid mess: overstuffed with attempted control and logic processes.
    4 - Even if you are using active rendering, your approach to 2 painting methods is horrible at best.
    If you need help in designing your process better, then post what you have and ask for help. IMO what you are doing can only lead to ugliness.

  • [svn] 3051: actually, for some reason this cast is changing how this method works so

    Revision: 3051
    Author: [email protected]
    Date: 2008-08-29 19:19:32 -0700 (Fri, 29 Aug 2008)
    Log Message:
    actually, for some reason this cast is changing how this method works so
    I'm backing it out!
    Modified Paths:
    blazeds/trunk/modules/core/src/java/flex/messaging/io/BeanProxy.java

    As I said in your original post, iTunes U is not available to any institution, government or otherwise, in South Korea. If or when Apple will extend iTunes U to your country is something none of us here can say, and Apple will not until such time as they're ready to make an announcement. What Apple's criteria and requirements are for being able to open iTunes U in a given country is unknown; there is no "procedure" that any of us here can state or direct you to that you could initiate. It's totally up to Apple, and if they are working on this, I'm sure they know who in the SK government they would need to work with.
    Sorry, but you will just have to wait and hope that something develops in the future.
    Regards.

  • How seek method works actually??

    Hi,
    i am not able to understand how seek method works in java.
    plz make me clear on this method..
    seek(pos)
    The position in the file where the next read or write operation will occur.
    But it operates entirely different in the following code. only when i put the value as 5 , it prints the value of 7890. if i pass anything other than that, it would return some values which were not written.
    import java.io.*;
    public class TestIPApp {
    public static void main(String args[]) throws IOException {
    RandomAccessFile file = new RandomAccessFile("c:\\test.txt", "rw");
    file.writeBoolean(true);
    file.writeInt(123456);
    file.writeInt(7890);
    file.writeLong(1000000);
    file.writeInt(777);
    file.writeFloat(.0001f);
    file.seek(9);
    System.out.println(file.readInt());
    file.close();
    }when i open the test.txt file, it contains some junk values. how could i see this txt file in readable format?
    plz help me

    Pannar wrote:
    only when i put the value as 5 , it prints the value of 7890.Makes sense to me. You write a boolean, then an int. Boolean values are written [in one byte|http://java.sun.com/javase/6/docs/api/java/io/RandomAccessFile.html#writeBoolean(boolean)], int values are written [in four bytes|http://java.sun.com/javase/6/docs/api/java/io/RandomAccessFile.html#writeInt(int)]. Positioning the file pointer to the fifth byte gets ready to read the next int value.
    In your code, however, you move the pointer to the ninth byte, which is the start of what you wrote as a long value. So, this code...System.out.println(file.readInt());...should be this:System.out.println(file.readLong());
    Pannar wrote:how could i see this txt file in readable format? Write text rather than data.
    ~

  • I dont know what to do!!! I pulled out my headphones and then saw that my sound was not working correctly. I was horrified to find a piece of the headphone never came out. I have heard how much it costs to repair and the other methods are not working.

    Please help, i am so scared that i will never get my laptop back the way it was.

    "the other methods aren't working"
    Well, what other methods have you tried that didn't work?  Frankly, your post reads as a hoax, but I have some extra time on my hands, and an idea.  Make an appointment with the Apple Genius at your local Apple store.  You could also bring your MBP to an AASP.  Regardless, either one should be able to remove the bottom cover, and use a plastic thingy (dang, what is that tool called?) to push out the offending bit.

Maybe you are looking for