Jul 26, 2008

Button To Display An Image

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

free web hosting

Button To Display An Image

kvarnerexpress
I have an assignment that is due tomorrow that I am struggling with. I want to be able to click the next button in this applet, and then repaint all the graphics. Board contains an array with all of the chess pieces on a board, and when the button is clicked I want to be able to get the next move, but for now I just wanted to call a function to move one piece just so I know it's working. Here is my applet code, I could post all the other files, but I am almost positive they all work correctly, and I am just having trouble with the applet.

Code:

CODE
import java.awt.*;

public class Test extends java.applet.Applet
{
   Button nextButton;
   Image board, bp, wp, bn, wn, br, wr, bb, wb, bk, wk, bq, wq;
   Board currentBoard = new Board();

   public void init() {
    board = getImage(getCodeBase(), "../images/board.jpg");
 bp = getImage(getCodeBase(), "../images/bp.gif");
 wp = getImage(getCodeBase(), "../images/wp.gif");
 bn = getImage(getCodeBase(), "../images/bn.gif");
 wn = getImage(getCodeBase(), "../images/wn.gif");
 br = getImage(getCodeBase(), "../images/br.gif");
 wr = getImage(getCodeBase(), "../images/wr.gif");
 bb = getImage(getCodeBase(), "../images/bb.gif");
 wb = getImage(getCodeBase(), "../images/wb.gif");
 bk = getImage(getCodeBase(), "../images/bk.gif");
 wk = getImage(getCodeBase(), "../images/wk.gif");
 bq = getImage(getCodeBase(), "../images/bq.gif");
 wq = getImage(getCodeBase(), "../images/wq.gif");
    nextButton = new Button("Next");
       add(nextButton);
   }

   public boolean action(Event evt, Object arg) {
       if (evt.target instanceof Button) {
           getMove((Button) evt.target);
           return true;
       } else {
           return false;
       }
   }

   void getMove(Button b) {
       changeBoard();
       repaint();
   }
   
   public void paint(Graphics screen) {
 // Draw Board
 screen.drawImage(board, 0, 50, 900, 930, this);
 String hi = "hi";
 for(int y = 1; y < 9; y++)
 {
 
  char tempX = 'a';
  for(int x = 1; x < 9; x++)
  {
   if(currentBoard.colorOn(tempX, y) != 'n')
   {
    if(currentBoard.colorOn(tempX, y) == 'b')
    {
     if (currentBoard.typeOn(tempX, y) == "Pawn")
     {
      screen.drawImage(bp, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "Rook")
     {
      screen.drawImage(br, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "Knight")
     {
      screen.drawImage(bn, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "Bishop")
     {
      screen.drawImage(bb, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "King")
     {
      screen.drawImage(bk, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "Queen")
     {
      screen.drawImage(bq, convertX(tempX), convertY(y), 100, 100, this);
     }
    }
    if(currentBoard.colorOn(tempX, y) == 'w')
    {
     if (currentBoard.typeOn(tempX, y) == "Pawn")
     {
      screen.drawImage(wp, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "Rook")
     {
      screen.drawImage(wr, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "Knight")
     {
      screen.drawImage(wn, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "Bishop")
     {
      screen.drawImage(wb, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "King")
     {
      screen.drawImage(wk, convertX(tempX), convertY(y), 100, 100, this);
     }
     if (currentBoard.typeOn(tempX, y) == "Queen")
     {
      screen.drawImage(wq, convertX(tempX), convertY(y), 100, 100, this);
     }
     
    }
   }
   tempX++;
  }
 }
}
public int convertX(char a) {
 return ((a-97)*(100)) + 90;
}

public int convertY(int a) {
 return ((a-1)*(100)) + 90;
}
public void changeBoard(){
 currentBoard.move('b',2,'b',3);
 currentBoard.move('b',7,'b',5);
}
}

Thanks,kvarnerexpress

 

 

 


Reply

wow
I suppose your assignment is passed by now, and I hope you found an answer to your question. I would be interested in the chess game if you could send me the projects files. I'm just starting to learn java myself,and this probally has not a thing to do with your question, but I was noticing that the applet source code only contains one import statment that doesnt seem right.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : button, display, image

  1. Image Rotater
    need help (2)
  2. Text Image Java Problem
    How to include text and image in some scrollable container? (1)
    Hello everyone, I am just writing some kind of text editor as practice for some school project and I
    have come to certain point where I can not solve certain problem. I wanted to make it available
    for people to insert images but I cannot figure how to combine images and text and which container
    should I use. I am working in Java and using swing. Also I would like to say that this content
    should be scrollable. So if anyone knows something about this and could be able to help me thanks in
    advance. Everyone opinion is accepted.....
  3. Button Animation With Rollover State That Stays When User Clicks A Button
    (0)
    QUOTE We are going to need animation and I don't like to use time-line animation so I use AS
    to code my animation. A very good reason to not use timeline animation is this: Say in my example
    (located here: http://www.creativenetdesign.com/menuWithScalingBox/) say I made the little red
    squares animate with a time-line animation and when the user rolls over the button I tell it to
    start. Say the red square is half way through its animation and I rollOff of it. The red square
    will automatically "jump" to the rollOut animation which will make it appear to chang....
  4. How To Make This Type Of Link?
    Image change on mouseover (1)
    I cant figure out how to solve this problem.... I want to make link to be like this: When the page
    is loaded to have a pictures on it, but one picture is a link. I want to make this picture to change
    when I get my mouse cursor over her... I mean: when my mouse cursor is not on a picture then on page
    is loaded a "pic1.gif" file, but when my mouse cursor is over it, picture changes to a "pic2.gif".
    Thanks for help!....
  5. Need A Java Script/ Help
    How to display download count on site? (6)
    /dry.gif" style="vertical-align:middle" emoid=" I am offering some download stuffs to the
    visitors of my site.. I have seen on some sites that they host download files on a box with 2
    columns, the left one showing the filename and the right column showing the number of times the file
    has been downloaded.. I want to know how to do these.. Is there any javascript available for this..
    if yes then please provide the link for the script.....
  6. Expanding Image Gallery
    Images Expanding on a mousover (6)
    I was looking through wired today, and i noticed :
    http://www.hotwired.com/webmonkey/06/08/index2a.html looks like a pretty nifty image gallery
    effect, though i noticed that it wont display properly in FireFox. Does anyone have any links or
    examples of other image gallery code, i find it pretty fascinating.....
  7. Countdown Code Help
    I need help setting an image as the background. (3)
    Ok, now for scripts like this i am not to well of working with..and i am in need of a bit of help, i
    would like to set a background image as the background not a color... CODE <script
    language="JavaScript1.2"> /* Dynamic countdown Script- © Dynamic Drive
    (www.dynamicdrive.com) For full source code, 100's more DHTML scripts, and TOS, visit
    http://www.dynamicdrive.com */ function setcountdown(theyear,themonth,theday){
    yr=theyear;mo=themonth;da=theday } //////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////
    //STEP 1&....
  8. Problem To Update Jlabel With A Different Image..
    (1)
    Hi All, I am inplementing a preview function on a image file browser. The application displays a
    list of image file names, which the user can select (one at a time). The preview image is loaded
    into a JLabel. When an image file name is selected, the application creates a thumbnail image on the
    hard drive call "preview.jpg". The JLabel should then update itself with the newly created thumbnail
    "preview.jpg". For some reason I cannot get the Image in the JLabel to update. I have confirmed
    that "preview.jpg" is being rewritten, each time a new image file is selected from ....
  9. How To Create Java Button Or Frame
    to be customized (12)
    hi to all!!!! just like to ask if it would be possible if i could make a custom
    button or frame in java. i got tired of using the build infeatures in java. i would like to create
    my own dessign of button or frame.. can it be possible!!! /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> thank!!!! /laugh.gif'
    border='0' style='vertical-align:middle' alt='laugh.gif' /> New Help In! is NOT a descriptive
    topic title. Next time you decide not to follow the posting rules, you will be issued a w....
  10. Image Clocks
    (2)
    Does anyone know how to make you r own image clock (like a skin) for your website. The time displays
    like your system. you might take a look a this to know what i mean. So-You.net click here to see
    what i mean ...image clocks ....
  11. Image Show With Thumbnail And Fade
    Does anyone know were I can get this code? (2)
    Hi I would like to know if anyone knows a javascript that makes an thumbnail 'slideshow'
    and when mouseover...it fades...and when you click...it enlarges!!! I saw it somewhere
    here on the net but i cant finf it anymore!!! Can anyone help me...or does anyone know
    a good javascript site???? THANKS ....
  12. Resize Image Before Uploading
    (0)
    Hi, My upload and resizing scripts are working perfectly. Problem is clients are uploading large
    files and the script times out or connection timeout. Problem is with the bandwith and the slow
    connection in South Africa. I have increased the script timeout but it simply takes too long to
    upload. Clients forget that most didgital cameras files are massive and if they simple resize
    before uploading it will save them a huge amount of time. The final file is only 280 X 210 pixels.
    Uploading a 5Mb file over a 56k connection takes a month of Sundays. I have detailed instr....
  13. Onclick Image ->> Add Text To Input(text)field?
    (3)
    when some images get clicked, a text should added to an input(textfield). Does someone know how this
    can be done? I suppose it can be done via javascript. thanks in advance! /cool.gif' border='0'
    style='vertical-align:middle' alt='cool.gif' /> If you need more information, just ask
    /tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /> ....
  14. Rollover Background-image Button Ie
    Rollover background-image button IE (0)
    I find This Code On Search I Think for webmasters is good To Find Easy this Kind of code so i Type
    it here I Hope U enjoy it /blink.gif' border='0' style='vertical-align:middle' alt='blink.gif' />
    Step 1: Insert the below into the section of your page. Change the image path within ".initial"
    to reference the image you want applied initially to the button. .initial{ font-weight:bold;
    background-image:url(first.jpg); } CODE <script type="text/javascript">
    <!-- //Specify optional button target: "_new" for new window, ....
  15. Image Scroller?
    (6)
    does anybody know where i can find a image scroller script? scrolling up and down?....

    1. Looking for button, display, image

Searching Video's for button, display, image
advertisement



Button To Display An Image



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE