Coding Horror, be scared

DoubleBufferingBouncing

My teacher won't teach me how to put an image as the background and make the ball stop at the end of the wall and I need to know how. She gave us code to fix but my project won't run anymore... please help asap!

untitled.php
package Pac1; import java.applet.Applet; import java.applet.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.logging.Level; import java.util.logging.Logger; public class Help extends Applet implements Runnable { int x_pos = 10; // x - Position int y_pos = 100; // y - Position int radius = 20; // Radius int x = 10; int y = 10; int countX = 10; int countY = 10; private Image dbImage; private Graphics dbg; Image backImage; Thread th; AudioClip beep; Button button1; Button button2; Button button3; Button button4; Button button5; Button button6; public void init() { setSize(1400,1000); setBackground (Color.blue); beep = getAudioClip (getCodeBase(), "beep.wav"); backImage = getImage(getCodeBase(), "Zack and Travis 2013.jpg"); button1 = new Button("Fullscreen"); add(button1); button1.addActionListener((ActionListener) this); button2 = new Button("Smallscreen"); add(button2); button2.addActionListener((ActionListener) this); button3 = new Button("Salmon"); add(button3); button3.addActionListener((ActionListener) this); button4 = new Button("LimeGreen"); add(button4); button4.addActionListener((ActionListener) this); button5 = new Button("Stop"); add(button5); button5.addActionListener((ActionListener) this); button6 = new Button("Go"); add(button6); button6.addActionListener((ActionListener) this); } private void incrementX() { x += 10; } private void decrementX() { x -= 10; } private void incrementY() { y += 10; } private void decrementY() { y -= 10; } public void start () { th = new Thread (this); th.start (); } public void stop() { } public void destroy() { } public void run () { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while (true) { if(countX < (getSize().width/10)-1) { incrementX(); countX++; } if(countX >= (getSize().width/10)-1) { decrementX(); countX++; } if(countX >= (getSize().width/5)-2) { countX=0; } if(countY < (getSize().height/10)-1) { incrementY(); countY++; } if(countY >= (getSize().height/10)-1) { decrementY(); countY++; } if(countY >= (getSize().height/5)-2) { countY=0; } x_pos ++; repaint(); if(x_pos > 280 && x_pos < 305) { beep.play(); } repaint(); try { Thread.sleep (20); } catch (InterruptedException ex) { // do nothing } Thread.currentThread().setPriority (Thread.MAX_PRIORITY); } } public void actionPerformed(ActionEvent e) { if (e.getSource() == button1) { System.out.println("Button 1 was pressed"); setSize(1900, 1000); } if (e.getSource() == button2) { System.out.println("Button 2 was pressed"); setSize(1400, 1000); } if (e.getSource() == button3) { System.out.println("Button 3 was pressed"); Color Salmon=new Color(255, 78, 96); setBackground(Salmon); } if (e.getSource() == button4) { System.out.println("Button 4 was pressed"); Color LimeGreen=new Color(13, 225, 115); setBackground(LimeGreen); } if (e.getSource() == button5) { System.out.println("Button 5 was pressed"); Thread exampleThread = new Thread(){ public void run(){ try { Thread.sleep(2000); } catch (InterruptedException ex) { } } }; exampleThread.start(); try { exampleThread.join(); } catch (InterruptedException ex) { Logger.getLogger(Ball.class.getName()).log(Level.SEVERE, null, ex); } } if (e.getSource() == button6) { System.out.println("Button 6 was pressed"); } } public void update (Graphics g) { if (dbImage == null) { dbImage = createImage (this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics (); } dbg.setColor (getBackground ()); dbg.fillRect (1900, 1000, this.getSize().width, this.getSize().height); dbg.setColor (getForeground()); paint (dbg); g.drawImage (dbImage, 1900, 1000, this); } public void paint (Graphics g) { g.drawImage(backImage,1900,1000,this); g.setColor (Color.red); g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius); } }

Reactions 0 reactions

No reactions yet, be the first: comment or tweak the code

Comment on this code:

Please Login or Register to leave a comment.