Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Command pattern java  RSS feed

Jhilam Gupta
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) {
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 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()
public String displayReview()
DancerImp = this.getDancerImp;
return(�<input review here>�);

�In addition to and BRIDGE, I have to write nine individual classes called: Dancer,
�, DancerImpSingleton, DancerA, DancerB, DancerC,
�DancerAImp, DancerBImp and DancerCImp
that closely resemble the reference Bridge pattern classes in

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(){
setTitle ("HELLO");
setSize(200, 200);

radioButtonA = new JRadioButton("A");
radioButtonB = new JRadioButton("B");
radioButtonC = new JRadioButton("C");
bg = new ButtonGroup();
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);

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

// adding some buttons

//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);


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();
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!