import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class gamePanel01 extends JPanel implements KeyListener
{
character ch1 = new character("Hero");
int w,l;
JButton blocker01;
JButton blocker02;
JButton blocker03;
JButton blocker04;
JButton blocker05;
JButton r_wall;
int limit2=0;
int delay=0;
Timer tim;
int x=100;
int y=100;
ClassLoader cl = this.getClass().getClassLoader();
Image gamePanelBG = new ImageIcon(cl.getResource("images/gamePanel01.jpg")).getImage();
ImageIcon PSUBlocker = new ImageIcon(cl.getResource("images/PSU_Helmet_Blocker.gif"));
ImageIcon PSULionRight = new ImageIcon(cl.getResource("images/NittanyLion_Mini_Right.png"));
ImageIcon PSULionLeft = new ImageIcon(cl.getResource("images/NittanyLion_Mini_Left.png"));
public gamePanel01()
{
super();
setLayout(null);
add(ch1);
ch1.setIcon(PSULionRight);
ch1.setBounds(new Rectangle(x,y,45,45));
ch1.addKeyListener(this);
ch1.setFocusPainted(false);
ch1.setContentAreaFilled(false);
ch1.setBorderPainted(false);
blocker01 = new JButton();
blocker02 = new JButton();
blocker03 = new JButton();
blocker04 = new JButton();
blocker05 = new JButton();
r_wall= new JButton();
add(blocker01);
add(blocker02);
add(blocker03);
add(blocker04);
add(blocker05);
blocker01.setBounds(new Rectangle(250,150,45,45));
blocker02.setBounds(new Rectangle(250,195,45,45));
blocker03.setBounds(new Rectangle(400,240,45,45));
blocker04.setBounds(new Rectangle(400,285,45,45));
blocker05.setBounds(new Rectangle(400,330,45,45));
r_wall.setBounds(new Rectangle (250,150,45,45));
blocker01.setIcon(PSUBlocker);
blocker01.setFocusPainted(false);
blocker01.setContentAreaFilled(false);
blocker01.setBorderPainted(false);
blocker02.setIcon(PSUBlocker);
blocker02.setFocusPainted(false);
blocker02.setContentAreaFilled(false);
blocker02.setBorderPainted(false);
blocker03.setIcon(PSUBlocker);
blocker03.setFocusPainted(false);
blocker03.setContentAreaFilled(false);
blocker03.setBorderPainted(false);
blocker04.setIcon(PSUBlocker);
blocker04.setFocusPainted(false);
blocker04.setContentAreaFilled(false);
blocker04.setBorderPainted(false);
blocker05.setIcon(PSUBlocker);
blocker05.setFocusPainted(false);
blocker05.setContentAreaFilled(false);
blocker05.setBorderPainted(false);
}
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(gamePanelBG, 0, 0, this);
}
public void keyPressed(KeyEvent ev)
{
int k= ev.getKeyCode();
if (k==KeyEvent.VK_LEFT)
{
x=x-5;
ch1.setIcon(PSULionLeft);
}
if(k==KeyEvent.VK_RIGHT)
{
x=x+5;
ch1.setIcon(PSULionRight);
}
if(k==KeyEvent.VK_UP) {y=y-5;}
if(k==KeyEvent.VK_DOWN) {y=y+5;}
ch1.setBounds(new Rectangle(x,y,45,45));
//Rectangle r1=new Rectangle(x,y,45,45);
//setBounds(r1);
tim=new Timer(delay, (ActionListener) this);
tim.start();
{
public void actionPerformed(ActionEvent e)//error
{
Object obj = e.getSource();
if (obj == tim)
{
blocker01.setBounds(x,y,w,l);
}
if (obj==tim)
{
if(blocker01.getBounds().intersects(r_wall))//error
{
}
else
blocker01.setBounds(x,y,w,l);
}
}
public void keyReleased(KeyEvent evt) { }
public void keyTyped(KeyEvent evt) { }
}