import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class gamePanel01 extends JPanel implements KeyListener
{
character ch1 = new character("Hero");
//Global Variables
JButton blocker01;
JButton blocker02;
JButton blocker03;
JButton blocker04;
JButton blocker05;
JLabel msg1;
JLabel msg2;
//Character movement Variables
int x=100;
int y=100;
//Image for background of gamePanel01
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);
//Blocker Buttons created/added
blocker01 = new JButton();
blocker02 = new JButton();
blocker03 = new JButton();
blocker04 = new JButton();
blocker05 = new JButton();
add(blocker01);
add(blocker02);
add(blocker03);
add(blocker04);
add(blocker05);
//Blocker Button Placement-------------------------------------------------
//**********Rectangle Parameters (x,y,length,height)
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));
//Set Images to Buttons and Button Parameters
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);
msg1.setBounds(new Rectangle(320,50,400,50));
msg2.setBounds(new Rectangle(320,280,400,50));
add(msg1);
add(msg2);
if (ch1.intersects(blocker01))
{msg1.setText("ch1 and blocker01 intersect");}
else
{msg1.setText("ch1 and blocker01 do not intersect");}
if (ch1.intersects(blocker02))
{msg2.setText("ch1 and blocker02 intersect");}
else
{msg2.setText("ch1 and blocker02 do not intersect");}
}
@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);
}
public void keyReleased(KeyEvent evt) { }
public void keyTyped(KeyEvent evt) { }
}