Magazine
 

Design Pattern

 

ButtonClear.java

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.FontMetrics;
class ButtonClear extends JButton
implements Command {
Mediator mediator;
ButtonClear(ActionListener al, Mediator med)
{
super(“Clear”);
addActionListener(al);
mediator = med;
mediator.registerClear(this);
}
public void execute() {
mediator.clear();
}
}

ButtonPrevious.java

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.FontMetrics;
class ButtonPrevious extends JButton
implements Command {
Mediator mediator;
ButtonPrevious(ActionListener al, Mediator
med) {
super(“Previous”);
addActionListener(al);
mediator = med;
mediator.registerPrevious(this);
}
public void execute() {
mediator.previous();
}
}

 

Display.java

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.FontMetrics;
class Display extends JLabel{
Mediator mediator;
Display (Mediator med) {
super(“0”,JLabel.CENTER);
mediator = med;
mediator.registerDisplay(this);
setBackground(Color.white);
setBorder(new EtchedBorder(Color.blue,
Color.green));
Font font = new Font(“Arial”,Font.BOLD,40);
setFont(font);
}
}

Mediator.java

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.FontMetrics;
class Mediator {
ButtonDice btnDc;
ButtonPrevious btnPrvs;
ButtonClear btnClr;
Display display;
java.util.List list, undo;
boolean restart = true;
int counter = 0, ct = 0;
//....
Mediator() {
list = new ArrayList();
undo = new ArrayList();
}
void registerDice(ButtonDice bd) {
btnDc = bd;
}
void registerClear(ButtonClear bc) {
btnClr = bc;
}
void registerPrevious(ButtonPrevious bp) {
btnPrvs = bp;

Jan 2007 | Java Jazz Up | 94
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

83, 84 , 85 , 86, 87 , 88, 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103, 104 , 105 ,

106, 107,

Download PDF