Java 鼠标监听器
importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassFrameextendsJF...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Frame extends JFrame{
static JFrame frame = new JFrame("MyFrame");
public static void main(String[] args){
frame.setSize(314,314);
frame.setVisible(true);
JMenuBar();
}
public static void JMenuBar(){
JMenuBar menubar = new JMenuBar();//菜单初始化
frame.setJMenuBar(menubar);//建立菜单
JMenu startFile = new JMenu("开始");
JMenu helpFile = new JMenu("帮助");
JMenu aboutFile = new JMenu("关于");
menubar.add(startFile);
menubar.add(helpFile);
menubar.add(aboutFile);
JMenuItem againItem = startFile.add("再玩一次");//建立子菜单
JMenuItem heroItem = startFile.add("英雄榜");
JMenuItem howItem = helpFile.add("如何游戏");
JMenuItem writerItem = aboutFile.add("制作组成员");
JMenuItem callItem = aboutFile.add("联系方式");
againItem.addActionListener(new ActionHandler());//建立鼠标监听器
class ActionHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"Hello world!","Display",JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
编译总说31行找不到符号 求解(againItem.addActionListener(new ActionHandler());//建立鼠标监听器 这一行) 展开
import java.awt.*;
import java.awt.event.*;
public class Frame extends JFrame{
static JFrame frame = new JFrame("MyFrame");
public static void main(String[] args){
frame.setSize(314,314);
frame.setVisible(true);
JMenuBar();
}
public static void JMenuBar(){
JMenuBar menubar = new JMenuBar();//菜单初始化
frame.setJMenuBar(menubar);//建立菜单
JMenu startFile = new JMenu("开始");
JMenu helpFile = new JMenu("帮助");
JMenu aboutFile = new JMenu("关于");
menubar.add(startFile);
menubar.add(helpFile);
menubar.add(aboutFile);
JMenuItem againItem = startFile.add("再玩一次");//建立子菜单
JMenuItem heroItem = startFile.add("英雄榜");
JMenuItem howItem = helpFile.add("如何游戏");
JMenuItem writerItem = aboutFile.add("制作组成员");
JMenuItem callItem = aboutFile.add("联系方式");
againItem.addActionListener(new ActionHandler());//建立鼠标监听器
class ActionHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"Hello world!","Display",JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
编译总说31行找不到符号 求解(againItem.addActionListener(new ActionHandler());//建立鼠标监听器 这一行) 展开
2个回答
展开全部
JMenuItem againItem = startFile.add("再玩一次");//建立子菜单
JMenuItem heroItem = startFile.add("英雄榜");
JMenuItem howItem = helpFile.add("如何游戏");
JMenuItem writerItem = aboutFile.add("制作组成员");
JMenuItem callItem = aboutFile.add("联系方式");
againItem.addActionListener(new ActionHandler());//建立鼠标监听器
}
}
class ActionHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"Hello world!","Display",JOptionPane.INFORMATION_MESSAGE);
}
}
或者:
JMenuItem againItem = startFile.add("再玩一次");//建立子菜单
JMenuItem heroItem = startFile.add("英雄榜");
JMenuItem howItem = helpFile.add("如何游戏");
JMenuItem writerItem = aboutFile.add("制作组成员");
JMenuItem callItem = aboutFile.add("联系方式");
againItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"Hello world!","Display",JOptionPane.INFORMATION_MESSAGE);
}
}
);//建立鼠标监听器
}
}
JMenuItem heroItem = startFile.add("英雄榜");
JMenuItem howItem = helpFile.add("如何游戏");
JMenuItem writerItem = aboutFile.add("制作组成员");
JMenuItem callItem = aboutFile.add("联系方式");
againItem.addActionListener(new ActionHandler());//建立鼠标监听器
}
}
class ActionHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"Hello world!","Display",JOptionPane.INFORMATION_MESSAGE);
}
}
或者:
JMenuItem againItem = startFile.add("再玩一次");//建立子菜单
JMenuItem heroItem = startFile.add("英雄榜");
JMenuItem howItem = helpFile.add("如何游戏");
JMenuItem writerItem = aboutFile.add("制作组成员");
JMenuItem callItem = aboutFile.add("联系方式");
againItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,"Hello world!","Display",JOptionPane.INFORMATION_MESSAGE);
}
}
);//建立鼠标监听器
}
}
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询