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

📄 simpledraw.java

📁 这个文件里面包含了java设计模式的一些例子讲解
💻 JAVA
字号:
/* Generated by Together */

package com.javapatterns.command.drawapplet;

import java.awt.*;
import java.applet.*;
import java.util.*;
import java.awt.event.*;

public class SimpleDraw extends Applet implements ActionListener {
    /**
     * @link aggregation
     * @clientRole applet
     * @supplierRole drawing 
     */
    private Drawing	drawing;

    /**
     * @link aggregation
     * @supplierRole commands*/
    private CommandList	commands;
    private Button	undoButton;
    private Button	redoButton;

    public void init() {
        Panel panel = new Panel();
        commands = new CommandList();
        setLayout( new BorderLayout() );
        drawing = new Drawing( this );
        add( "Center", drawing );
        undoButton = new Button( "Undo" );
        redoButton = new Button( "Redo" );
        undoButton.addActionListener( this );
        redoButton.addActionListener( this );
        panel.add( undoButton );
        panel.add( redoButton );
        add( "South", panel );
        updateButtons();
     }

     public void execute( Command command ) {
        commands.execute( command );
        updateButtons();
     }

     private void updateButtons() {
        undoButton.setEnabled( commands.canUnexecuteCommand() );
        redoButton.setEnabled( commands.canReexecuteCommand() );
     }

     public void actionPerformed(ActionEvent event) {
        if (event.getSource() == undoButton) {
            commands.unexecute();
            updateButtons();
        }
        if (event.getSource() == redoButton) {
            commands.reexecute();
            updateButtons();
           }
     }
}

⌨️ 快捷键说明

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