Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tiltmaze;
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- public class TiltMaze extends JPanel implements ActionListener
- {
- Timer time = new Timer(5, this);//Declares variable
- Image Pic;//Declares variable
- int PicW = 363;//Declares variable
- int PicH = 362;//Declares variable
- int Start = 0;//Declares variable
- int x = 15;//Declares variable
- int y = 115;//Declares variable
- int speed = 3;//Declares variable
- public TiltMaze ()
- {
- ImageIcon obj = new ImageIcon("src/tilt2.jpg"); //Gets image
- Pic = obj.getImage(); //Sets image to a variable
- }
- public void paint(Graphics g)
- {
- super.paint(g);
- g.drawImage(Pic, Start, 0, null);//Makes the image in /src painted
- g.setColor(Color.white);//Sets colour for next entries
- g.fillRect(15, 110, 30, 35);//Fills in a rectangle
- g.setColor(Color.green);//Sets colour for next entries
- g.fillOval(x, y, 25, 25);//Fills in the oval that will be moving
- g.setColor(Color.black);//Sets colour for next entries
- g.drawOval(x, y, 25, 25);//Makes an outline of the oval
- time.start();
- }
- public void actionPerformed(ActionEvent e)
- {
- if(x > 14 && x < 215 && y == 115) //Draws circle moving
- {
- x = x + speed + 1;
- repaint();//Repaints image after variable changes removing old image
- }
- if(x == 215 && y > 114 && y < 217)//Draws circle moving
- {
- y = y + speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if(y == 217 && x > 168 && x < 218)//Draws circle moving
- {
- x = x - speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if(x == 167 && y > 216 && y < 315)//Draws circle moving
- {
- y = y + speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if(y == 316 && x < 169 && x > 16)//Draws circle moving
- {
- x = x - speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if(x == 14 && y < 318 && y > 216)//Draws circle moving
- {
- y = y - speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if(y == 217 && x > 13 && x < 65)//Draws circle moving
- {
- x = x + speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if(x == 65 && y < 219 && y > 170)//Draws circle moving
- {
- y = y - speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if( y == 169 && x > 64 && x < 167)//Draws circle moving
- {
- x = x + speed + 1;
- repaint();//Repaints image after variable changes removing old image
- }
- if(x == 169 && y < 170 && y > 20)//Draws circle moving
- {
- y = y - speed - 1;
- repaint();//Repaints image after variable changes removing old image
- }
- if(y == 17 && x < 170 && x > 65)//Draws circle moving
- {
- x = x - speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if(x == 64 && y > 16 && y < 60)//Draws circle moving
- {
- y = y + speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if(y == 62 && x > 63 && x < 112)//Draws circle moving
- {
- x = x + speed;
- repaint();//Repaints image after variable changes removing old image
- }
- if(x == 112 && y > 61 && y < 212)//Draws circle moving
- {
- y = y + speed + 1;
- repaint();//Repaints image after variable changes removing old image
- }
- }
- public static void main(String[] args)
- {
- TiltMaze m = new TiltMaze();
- JFrame f = new JFrame("Tilt Maze Solution");//Name of JFrame
- f.add(m);
- f.setSize(373, 395);//Size of JFrame
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//When JFrame is closed program finishes running
- f.setLocationRelativeTo(null);
- f.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement