java右键菜单问题请教
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjava.awt.event.Mous...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
public class PopupTest {
public PopupTest(){
final JFrame f=new JFrame("弹出菜单测试");
f.setSize(300,400);
f.setLocation(200,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
f.setResizable(false);
final PopupMenu popupmenu1=new PopupMenu("背景");
String[] colorstring={"红色","绿色","蓝色","青色","洋红","黄色","黑色"};
for(int i=0;i<=6;i++){
MenuItem colorItem=new MenuItem(colorstring[i]);
popupmenu1.add(colorItem);
}
f.add(popupmenu1);
f.addMouseListener(new MouseAdapter()){
public void mouseClicked(MouseEvent e){
if(e.getButton()==MouseEvent.BUTTON3){
popupmenu1.show(f,e.getX(), e.getY());
}
}
};
}
public static void main(String[] args){
PopupTest p=new PopupTest();
}
}
我运行不出来右键菜单,请大家帮帮我~ 展开
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
public class PopupTest {
public PopupTest(){
final JFrame f=new JFrame("弹出菜单测试");
f.setSize(300,400);
f.setLocation(200,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
f.setResizable(false);
final PopupMenu popupmenu1=new PopupMenu("背景");
String[] colorstring={"红色","绿色","蓝色","青色","洋红","黄色","黑色"};
for(int i=0;i<=6;i++){
MenuItem colorItem=new MenuItem(colorstring[i]);
popupmenu1.add(colorItem);
}
f.add(popupmenu1);
f.addMouseListener(new MouseAdapter()){
public void mouseClicked(MouseEvent e){
if(e.getButton()==MouseEvent.BUTTON3){
popupmenu1.show(f,e.getX(), e.getY());
}
}
};
}
public static void main(String[] args){
PopupTest p=new PopupTest();
}
}
我运行不出来右键菜单,请大家帮帮我~ 展开
2个回答
展开全部
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
public class PopupTest {
public PopupTest(){
final JFrame f=new JFrame("弹出菜单测试");
f.setSize(300,400);
f.setLocation(200,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
f.setResizable(false);
final PopupMenu popupmenu1=new PopupMenu("背景");
String[] colorstring={"红色","绿色","蓝色","青色","洋红","黄色","黑色"};
for(int i=0;i<=6;i++){
MenuItem colorItem=new MenuItem(colorstring[i]);
popupmenu1.add(colorItem);
}
f.add(popupmenu1);
f.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
if(e.getButton()==MouseEvent.BUTTON3){
popupmenu1.show(f,e.getX(), e.getY());
}
}
});//这个地方错了。
}
public static void main(String[] args){
PopupTest p=new PopupTest();
}
}
完美解决。。接分。。。
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
public class PopupTest {
public PopupTest(){
final JFrame f=new JFrame("弹出菜单测试");
f.setSize(300,400);
f.setLocation(200,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
f.setResizable(false);
final PopupMenu popupmenu1=new PopupMenu("背景");
String[] colorstring={"红色","绿色","蓝色","青色","洋红","黄色","黑色"};
for(int i=0;i<=6;i++){
MenuItem colorItem=new MenuItem(colorstring[i]);
popupmenu1.add(colorItem);
}
f.add(popupmenu1);
f.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
if(e.getButton()==MouseEvent.BUTTON3){
popupmenu1.show(f,e.getX(), e.getY());
}
}
});//这个地方错了。
}
public static void main(String[] args){
PopupTest p=new PopupTest();
}
}
完美解决。。接分。。。
2012-03-19
展开全部
资深JAVA专家 小班授课
企业真实项目驱动
毕业即就业 最低起薪3500
零学费入学 详情搜索“疯狂JAVA”
企业真实项目驱动
毕业即就业 最低起薪3500
零学费入学 详情搜索“疯狂JAVA”
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询