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");

}

}

}

[6485 byte] By [Sequalita] at [2007-10-2 10:51:18]
# 1

how can we possibly copy/paste/compile/run/observe your problem when:

you are using 3rd Party classes

import BreezySwing.*;

you haven't supplied the support classes

private Client client;

what you have posted is incomplete

file = addMenuItem("FILE", "Exit");//where is this method?

all I can do is give you a working demo, and let you adapt it to your code.

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class Testing extends JFrame implements ActionListener

{

JMenuItem open = new JMenuItem("Open");

JMenuItem exit = new JMenuItem("Exit");

public Testing()

{

setDefaultCloseOperation(EXIT_ON_CLOSE);

setLocation(400,200);

JMenu menu = new JMenu("File");

menu.add(open);

menu.add(exit);

JMenuBar menuBar = new JMenuBar();

menuBar.add(menu);

setJMenuBar(menuBar);

getContentPane().add(new JTextArea(5,20));

pack();

open.addActionListener(this);

exit.addActionListener(this);

}

public void actionPerformed(ActionEvent ae)

{

if(ae.getSource() == open)

{

JOptionPane.showMessageDialog(getContentPane(),"'Open' menu item selected");

}

else if(ae.getSource() == exit)

{

System.exit(0);

}

}

public static void main(String[] args){new Testing().setVisible(true);}

}

Michael_Dunna at 2007-7-13 3:10:05 > top of Java-index,Desktop,Core GUI APIs...
# 2

If i just copied/pasted all my code to you, that would be over thousands of lines of code from game logic, server, ect/ ect, so i figured id just post this small little area and see if anyone could figure it out.

I realize a working demo is all you can give with what I provided

Thank you for the demo, it should help me alot.

Last question:

So i guess JFrame is a better way to go when your developing game applications instead of BreezySwing?

link for breezyswing

http://faculty.cs.wwu.edu/martin/Software%20Packages/BreezySwing/Default.htm

Sequalita at 2007-7-13 3:10:05 > top of Java-index,Desktop,Core GUI APIs...