java建立窗口,建立一个文本,和弹出窗口。怎么错了,点击鼠标右键释放,没有反应,高手请指点,谢谢
packagefangao;importjava.awt.*;importjava.awt.event.*;publicclassW8extendsFrameimplem...
package fangao;
import java.awt.*;
import java.awt.event.*;
public class W8 extends Frame implements ActionListener,MouseListener{
TextArea msg=new TextArea();
PopupMenu pm=new PopupMenu();
MenuItem item1=new MenuItem("复制");
MenuItem item2=new MenuItem("剪切");
MenuItem item3=new MenuItem("粘贴");
W8(){
setTitle("弹出式菜单");
setSize(350,200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
add(msg);
msg.add(pm);
pm.add(item1);
pm.add(item2);
pm.add(item3);
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
msg.addMouseListener(this);
show();
}
public void actionPerformed(ActionEvent e){
msg.append("你选择了"+e.getActionCommand()+"\n");
}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){
if(e.isPopupTrigger())
pm.show(this,e.getX(),e.getY());
}
public static void main(String args[]){
new W8();
}
} 展开
import java.awt.*;
import java.awt.event.*;
public class W8 extends Frame implements ActionListener,MouseListener{
TextArea msg=new TextArea();
PopupMenu pm=new PopupMenu();
MenuItem item1=new MenuItem("复制");
MenuItem item2=new MenuItem("剪切");
MenuItem item3=new MenuItem("粘贴");
W8(){
setTitle("弹出式菜单");
setSize(350,200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
add(msg);
msg.add(pm);
pm.add(item1);
pm.add(item2);
pm.add(item3);
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
msg.addMouseListener(this);
show();
}
public void actionPerformed(ActionEvent e){
msg.append("你选择了"+e.getActionCommand()+"\n");
}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){
if(e.isPopupTrigger())
pm.show(this,e.getX(),e.getY());
}
public static void main(String args[]){
new W8();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询