我是新手,在eclipse中运行下面程序总是提示Multiple markers at this line的错误 求原因
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import java.awt.event.KeyEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.JOptionPane;
public class Jnotepaui extends JFrame{
public Jnotepaui(){
super("新建文本文件");
getContentPane().setLayout(new BorderLayout());
setSize(640,480);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
//菜单栏
JMenuBar menuBar=new JMenuBar();
JMenu fileMenu=new JMenu("文件");
JMenuItem menuOpenItem=new JMenuItem("打开");
//快捷键的设置
menuOpenItem.setMnemonic('O');
menuOpenItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,java.awt.event.InputEvent.CTRL_MASK));
JMenuItem menuSave=new JMenuItem("保存");
menuSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
JMenuItem menuSaveAs=new JMenuItem("另存为");
JMenuItem menuClose=new JMenuItem("关闭");
menuClose.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_Q,
InputEvent.CTRL_MASK));
menuOpen.add(openMenu);
fileMenu.addSeparator();
fileMenu.add(menuSave);
fileMenu.addSeparator();
fileMenu.add(menuSaveAs);
fileMenu.addSeparator();
fileMenu.add(menuClose);
JMenu editMenu=new JMenu("编辑");
JMenuItem menuCut=new JMenuItem("剪切");
menuCut.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_X,
InputEvent.CTRL_MASK));
JMenuItem menuCopy=new JMenuItem("复制");
menuCopy.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_C,
InputEvent.CTRL_MASK));
JMenuItem menuPaste=new JMenuItem("粘贴");
menuPaste.setAccelerator(
KeyStroke.getKeyStroke(
KeyEvent.VK_P,
InputEvent.CTRL_MASK));
editMenu.add(menuCut);
editMenu.addSeparator();
editMenu.add(menuCopy);
editMenu.addSeparator();
editMenu.add(menuPaste);
JMenu aboutMenu=new JMenu("关于");
JMenuItem menuAbout=new JMenuItem("关于作者");
aboutMenu.add(menuAbout);
menuBar.add(editMenu);
menuBar.add(aboutMenu);
menuBar.add(fileMenu);
//配置菜单栏
setJMenuBar(menuBar);
public static void main(String[] args){
new Jnotepaui();
}
}
------解决方案--------------------
从
//菜单栏
到
main方法前那大段代码,要放到一个方法里。
------解决方案--------------------Multiple markers at this line意思是这行的重复错误
------解决方案--------------------package com.csdn;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import java.awt.event.KeyEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.JOptionPane;
public class Test8 extends JFrame {
public Test8() {
super("新建文本文件");
getContentPane().setLayout(new BorderLayout());
//首先把这些代码放到构造函数里面
// 菜单栏
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("文件");
JMenuItem menuOpenItem = new JMenuItem("打开");