Search Results

Search found 1 results on 1 pages for 'user363035'.

Page 1/1 | 1 

  • Java problem cant find image file

    - by user363035
    I am a student working on a homework project. I spent DAYS trying to get the following code to display an image on my new windows 7 laptop. I compiled it and ran it on my old xp pc and it worked! I really want to use my laptop. Any suggestions on how to get it to display the image? import java.awt.*; import java.applet.*; import java.awt.event.*; import java.awt.image.*; public class MoveIt extends Applet implements ActionListener { // set variables and componets private Image cup; Panel keypad = new Panel(); public int top = 15; public int left = 15; private Button keysArray[]; public void init() { cup = getImage(getDocumentBase(), "cup.gif"); Canvas myCanvas = new Canvas(); keysArray = new Button[5]; setLayout(new BorderLayout(5,5)); setBackground(Color.blue); // set up keypad layout keypad.setLayout(new BorderLayout(0,0)); keysArray[0] = new Button("Up"); keysArray[1] = new Button("Left"); keysArray[2] = new Button("Center"); keysArray[3] = new Button("Right"); keysArray[4] = new Button("Down"); // add buttons to the keypad panel keypad.add(keysArray[0], BorderLayout.NORTH); keysArray[0].addActionListener(this); keypad.add(keysArray[1], BorderLayout.EAST); keysArray[1].addActionListener(this); keypad.add(keysArray[2], BorderLayout.CENTER); keysArray[2].addActionListener(this); keypad.add(keysArray[3], BorderLayout.WEST); keysArray[3].addActionListener(this); keypad.add(keysArray[4], BorderLayout.SOUTH); keysArray[4].addActionListener(this); // add canvas and keypad to the BorderLayout add(myCanvas, BorderLayout.NORTH); add(keypad, BorderLayout.SOUTH); } public void paint(Graphics g) { g.drawImage( cup, left, top, this ); } public void actionPerformed(ActionEvent e) { // test for menu item clicks String arg = e.getActionCommand(); if (arg == "Up") top -=15; else if (arg == "Down") top +=15; else if (arg == "Left") left -=15; else if (arg == "Right") left +=15; else { top = 60; left =125; } repaint(); } }

    Read the article

1