aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Command pattern java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Command pattern java" Watch "Command pattern java" New topic
Author

Command pattern java

Jhilam Gupta
Greenhorn

Joined: Jun 04, 2005
Posts: 1
Hello everybody,

I need help in puting a program IN Command Pattern and Bridge Pattern.
I am very new to java.. Any help will be highly appreciated.

I am sending you the code and requirement. Hope You can understand.

I have to write a class called �CommandPattern�, which has the following interface:

public interface Command {
public void execute();
}

Additionally, this same class will have four inner classes for each RadioButton component. The JRadioButtonA is an example of one of those buttons.

class JRadioButtonA extends JRadioButton implements Command {
public JRadioButtonActorA(String caption) {
super(caption);
}
public void execute() {
// I have to add logic here for Bridge Pattern that outputs review
}
}

In the execute methods for all three of your button components (A, B ,C) you will implement your Bridge pattern logic that emulates code shown in http://www.fluffycat.com. Moreover, log statements should be interspersed in the code to display operational statuses. Lets assume all the button components represensts individual Dancer.. DancerA, DancerB, DancerC.

public class DancerA extends Dancer
private static Logger logger = Logger.getLogger(��);
public A()
{
setAImp();
}
public String displayReview()
{
DancerImp = this.getDancerImp;
return(�<input review here>�);
}
}

�In addition to Command.java and BRIDGE Pattern.java, I have to write nine individual classes called: Dancer,
� DancerImp.java), DancerImpSingleton, DancerA, DancerB, DancerC,
�DancerAImp, DancerBImp and DancerCImp
that closely resemble the reference Bridge pattern classes in http://www.fluffycat.com.



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

class Testu extends JFrame{
JButton button;
JRadioButton radioButtonA;
JRadioButton radioButtonB;
JRadioButton radioButtonC;
ButtonGroup bg;
JPanel toolbar;
JTextArea textArea;
JScrollPane jsp;
RadioButton_Handler handler;

public Testu(){
super();
setTitle ("HELLO");
setSize(200, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);

radioButtonA = new JRadioButton("A");
radioButtonB = new JRadioButton("B");
radioButtonC = new JRadioButton("C");
bg = new ButtonGroup();
bg.add(radioButtonA);
bg.add(radioButtonB);
bg.add(radioButtonC);
radioButtonA.setActionCommand("I am radiobutton A, what's up?");
radioButtonB.setActionCommand("I am radiobutton B, may I help?");
radioButtonC.setActionCommand("I am radiobutton C, go away idiot!");

// add action listeners to the radio buttons
handler = new RadioButton_Handler(this);
radioButtonA.addActionListener(handler);
radioButtonB.addActionListener(handler);
radioButtonC.addActionListener(handler);

// create a subpanel for the toolbar
toolbar = new JPanel();

// adding some buttons
toolbar.add(radioButtonA);
toolbar.add(radioButtonB);
toolbar.add(radioButtonC);

//add the toolbar to the main panel
getContentPane().add(toolbar, BorderLayout.NORTH);



//add a multiline editor
textArea = new JTextArea();
jsp = new JScrollPane(textArea);
getContentPane().add(jsp, BorderLayout.CENTER);

setVisible(true);
}

class RadioButton_Handler implements ActionListener {
JRadioButton selectedRadioButton;
ArrayList selectedRadioButtons;
Testu master;

public RadioButton_Handler(Testu tu) {
master = tu;
selectedRadioButtons = new ArrayList();
}

public void actionPerformed(ActionEvent e){
selectedRadioButton = (JRadioButton)(e.getSource());
master.textArea.setText(selectedRadioButton.getActionCommand() + "\n");

}
}

public static void main(String[] args){
new Testu();
}
}
 
 
subject: Command pattern java