📄 simpledraw.java
字号:
/* Generated by Together */
package com.javapatterns.command.drawlines;
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 + -