Results 1 to 4 of 4
  1. #1
    jdurwe is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Displaying an array on a Jpanel

    I am developing a game called "Angry Tank", 2 tanks on a landscape trying to destroy eachother as fast as possible. I am adding a GUI but i have no idea how to display my landscape (stored in an array made out of elements, 26 (rows) *100(columns)). A friend of mine advised me to override the paintComponent method and draw your my elements ("x" = landscap eelement," " = ai, "A" = tankA element, "B" = tankB element , "°" = shotelement).

    I am not familiar with those paintComponent method and its very hard to find good information on the web for my situation.
    I would be very pleased if somebody could come some basic stuff that i can use in my application.

    Thanks in advance!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: Displaying an array on a Jpanel

    Landscape sense do you want to draw the background of the game? Is your background interact with the game (like obstacles and all)?

  3. #3
    jdurwe is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Re: Displaying an array on a Jpanel

    every element of the array has a draw method wich returns a char ( public char teken() { return 'x';} ) all elements implements the element interface so normally i can do like this:

    landscapearray[2][30].teken

    i only want to show what element (char) is on each coordinate on my panel using the "teken" method.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: Displaying an array on a Jpanel

    Quote Originally Posted by jdurwe View Post
    I am not familiar with those paintComponent method and its very hard to find good information on the web
    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. JPanel not displaying after adding JMenu logic
    By AMCNovember in forum New To Java
    Replies: 1
    Last Post: 12-18-2011, 05:44 AM
  2. Displaying text in a JPanel
    By DrKilljoy in forum New To Java
    Replies: 7
    Last Post: 04-15-2011, 07:28 PM
  3. Help Displaying an Array
    By Spyderpig in forum New To Java
    Replies: 1
    Last Post: 03-15-2011, 01:08 PM
  4. displaying JSplitPane in JPanel
    By sandysm in forum AWT / Swing
    Replies: 4
    Last Post: 07-26-2010, 09:13 AM
  5. Jpanel and displaying graphics
    By jdsflash in forum New To Java
    Replies: 6
    Last Post: 11-21-2009, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •