menuItemSelected problem
Hi, I have a simple java net game I created to go on peoples computers.
I have my screen and I have added a JMenu to it, but I cannot figure out how to do anythign to the elements I added, like the Exit button i added... I ahve tried using a action listener, that works, but the screen pops up saying I need a menuItemSelected, how do i impliment that or keep it from asking?
here is my code:
GUI Class
import javax.swing.*;
import BreezySwing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
publicclass ClientGUIextends GBFrame{
private JMenuItem file;
private ClientGraphics graphics;
private GBPanel panel;
private Client client;
public ClientGUI(Client client){
setTitle("Gratorial");
this.client = client;
graphics =new ClientGraphics(this.client);
panel = addPanel(graphics, 1,1,500,500);
panel.setBackground(Color.darkGray);
graphics.setBackground(Color.RED);
file = addMenuItem("FILE","Exit");
file.addActionListener(new ClientKeyboardListener(client));
}
publicvoid menuItemSelected(MenuItem e){
if(e.getName() =="FILE"){
System.out.println("MENU ITEM SELECTED FILE");
}elseif(e.getName() =="Exit"){
System.out.println("MENU ITEM SELECTED Exit");
}
}
Client Listener Class
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
publicclass ClientKeyboardListenerimplements KeyListener, ActionListener{
private Client client;
privateint random1;
privateint random2;
public ClientKeyboardListener(Client client){
this.client = client;
}
publicvoid keyTyped(KeyEvent e){
//if(e.getID() == KeyEvent.VK_UP){
//System.out.println("KeyUP typed");
//client.createSprite(((int)Math.random()*800),((int)Math.random()*600),Color.green);
//}
}
publicvoid keyPressed(KeyEvent e){
System.out.println("Key Pressed");
if(e.getKeyCode() == KeyEvent.VK_UP){
client.shift("up");
}elseif(e.getKeyCode() == KeyEvent.VK_RIGHT){
client.shift("right");
}elseif(e.getKeyCode() == KeyEvent.VK_DOWN){
client.shift("down");
}elseif(e.getKeyCode() == KeyEvent.VK_LEFT){
client.shift("left");
}
}
publicvoid keyReleased(KeyEvent e){}
publicvoid menuItemSelected(MenuItem e){
if(e.getLabel() =="FILE"){
System.out.println("File Clicked 1");
}
if(e.getLabel() =="Exit"){
System.out.println("Exit clicked 1");
}
}
publicvoid actionPerformed(ActionEvent e){
if(e.getActionCommand() =="Exit"){
System.out.println("Exit Clicked");
}elseif(e.getActionCommand() =="FILE"){
System.out.println("File Clicked");
}
}
}

