Hello all...
I want to place a popup menu when i right click the button.
Is it possible ? I tried with the below code but it is not showing any
button & is only showing a popup menu at the position i set in Show()
& when i click on the choices the button appears.
import java.awt.*;
import java.awt.event.*;
public class ACDemo extends Frame implements ActionListener
{
Button b;
TextArea t;
ACDemo()
{
setLayout(new FlowLayout());
b = new Button("Click");
add(b);
b.addActionListener(this);
TextField t = new TextField(10);
add(t);
PopupMenu p = new PopupMenu();
MenuItem m1 = new MenuItem("Hot");
MenuItem m2 = new MenuItem("Cold");
MenuItem m3 = new MenuItem("Spicy");
p.add(m1);
p.add(m2);
p.add(m3);
b.add(p);
setVisible(true);
p.show(this,52,52);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==b)
{
System.exit(0);
}
}
public static void main(
String args[])
{
ACDemo f = new ACDemo();
f.setBounds(100,100,400,400);
}
}
Can someone tell me where i m wrong ?
Thanks.