java代码运行450提示_这段java代码为什么要这样才能运行

import javax.swing.*;

import java.awt.*;

import java.io.*;

import java.awt.event.*;

public class Editor extends JFrame implements ActionListener {

JPanel Panel = new JPanel();

JTextArea editor = new JTextArea(30, 60);

JMenuItem kaiti = new JMenuItem("楷体");

JMenuItem lishu = new JMenuItem("隶书");

JMenuItem yahei = new JMenuItem("微软雅黑");

Editor() {

super("文本编辑器 ");

setBounds(250, 100, 700, 450);

setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

int option = JOptionPane.showConfirmDialog(Editor.this, "确定要退出吗? ", "Warning ",

JOptionPane.YES_NO_OPTION);

if (option == JOptionPane.YES_OPTION)

if (e.getWindow() == Editor.this) {

System.exit(0);

} else {

return;

}

}

});

add(new JScrollPane(editor));// );

editor.setFont(new Font("宋体", Font.PLAIN, 20));

JMenuBar wenben = new JMenuBar();

this.setJMenuBar(wenben);

wenben.setOpaque(true);

JMenu custom = new JMenu("自定义");

JMenu OptionM = new JMenu("字体");

custom.add(OptionM);

OptionM.add(kaiti);

OptionM.add(lishu);

OptionM.add(yahei);

wenben.add(custom);

kaiti.addActionListener(this);

lishu.addActionListener(this);

yahei.addActionListener(this);

}

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

String actionCommand = e.getActionCommand();

if (e.getSource() instanceof JMenu) {

if (e.getSource() == kaiti) {

editor.setFont(new Font("楷体", Font.PLAIN, editor.getFont().getSize()));

} else if (e.getSource() == lishu) {

editor.setFont(new Font("隶书", Font.PLAIN, editor.getFont().getSize()));

} else if (e.getSource() == yahei) {

editor.setFont(new Font("微软雅黑", Font.PLAIN, editor.getFont().getSize()));

}

}

}

}

还是说这写不行。求指教,就是actionPerformed不执行。

//我发现在if (e.getSource() instanceof JMenu)的后面加上分号就可以运行了,这是什么原因呢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值