⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fuzzydemopanel.java

📁 这是一个经典的程序
💻 JAVA
字号:
package kc.test.fuzzy;

import kc.test.fuzzy.actions.*;

import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.BevelBorder;
import javax.swing.border.CompoundBorder;
import java.awt.*;
import java.awt.print.PrinterJob;
import java.awt.print.PrinterException;
import java.awt.event.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Thomas Neidhart, thomas.neidhart@gmail.com, all rights by Know-Center
 * Date: Aug 3, 2005
 *
 * Main panel for the fuzzy demo
 */
public class FuzzyDemoPanel extends JPanel implements ActionListener
{
    private Map<String, FuzzyAbstractAction> actions;
    private CommandPanel controls;
    private DrawPanel drawing;

    private FuzzyAbstractAction exitAction, initAction, resetAction, startAction, stepAction, runAction;

    /**
     * Create the demo panel
     */
    public FuzzyDemoPanel(boolean showMenu)
    {
        setLayout(new BorderLayout());
        setBorder(new EtchedBorder());

        createActions();

        if (showMenu)
            add(createMenuBar(), BorderLayout.NORTH);

        controls = new CommandPanel(actions);

        JPanel p = new JPanel(new BorderLayout());
        EmptyBorder eb = new EmptyBorder(5,0,5,5);
        BevelBorder bb = new BevelBorder(BevelBorder.LOWERED);
        p.setBorder(new CompoundBorder(eb,bb));
        p.add(controls, BorderLayout.NORTH);
        add(p, BorderLayout.EAST);

        drawing = new DrawPanel(controls);

        JPanel q = new JPanel(new BorderLayout());
        q.setBorder(new CompoundBorder(eb,bb));
        q.add(drawing, BorderLayout.CENTER);
        add(q, BorderLayout.CENTER);
    }

    private void createActions() {
        actions = new HashMap<String, FuzzyAbstractAction>();

        exitAction = new ExitAction();
        registerAction(exitAction);

        initAction = new InitAction();
        registerAction(initAction);

        resetAction = new ResetAction();
        registerAction(resetAction);

        startAction = new StartAction();
        registerAction(startAction);

        stepAction = new StepAction();
        registerAction(stepAction);

        runAction = new RunAction();
        registerAction(runAction);
    }

    private void registerAction(FuzzyAbstractAction action)  {
        action.addActionListener(this);
        actions.put(action.getName(), action);
    }

    /**
     * Create the menu bar
     * @return the menu bar
     */
    private JMenuBar createMenuBar() {
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
        JMenuBar menuBar = new JMenuBar();

        JMenu file = (JMenu) menuBar.add(new JMenu("File"));
        file.add(exitAction);

        return menuBar;
    }

    public void actionPerformed(ActionEvent e) {
        String command = e.getActionCommand();

        // Compare the action command to the known actions.
        if (command.equals(exitAction.getActionCommand()))  {
            System.exit(0);
        } else if (command.equals(initAction.getActionCommand()))  {
            drawing.initialize();
        } else if (command.equals(resetAction.getActionCommand()))  {
            drawing.reset();
        } else if (command.equals(startAction.getActionCommand()))  {
            drawing.start();
        } else if (command.equals(stepAction.getActionCommand()))  {
            drawing.step();
        } else if (command.equals(runAction.getActionCommand()))  {
            drawing.run();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -