*
The moose likes Beginning Java and the fly likes Mediatortype javaprog requiring solution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Mediatortype javaprog requiring solution" Watch "Mediatortype javaprog requiring solution" New topic
Author

Mediatortype javaprog requiring solution

C.R.Muthukumar
Ranch Hand

Joined: Dec 03, 2004
Posts: 59
Hello Friends/Programmers in Java
Pl help me clear this long waiting Mediator type of Programme that requires some finishing touches by way of making it error less. Shall be thankful if somebody helps .pl read the notes at the end for clarity.
import javax.swing.JPanel.*;
import javax.swing.JButton.*;
import javax.swing.JSeparator.*;
import javax.swing.JDialog.*;
import javax.swing.JList.*;
import javax.swing.JLabel.*;
import javax.swing.JComponent.*;
import javax.swing.JRadioButton.*;
import javax.swing.JInternalFrame.*;
import javax.swing.accessibility.*;
import java.awt.BorderLayout.*;
import java.awt.FlowLayout.*;
import java.util.Arrays.*;
import javax.swing.JButton.AccessibleJButton.*;
import javax.swing.JList.AccessibleJList.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.util.Date;


class ActionDialogMgr implements ActionListener {
private JButton OKButton;
private JButton cancelButton;
private JButton applyButton;
ActionDialogMgr{
OKButton.adddActionListener(this);
cancelButton.addActionListener(this);
applyButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt){
Object eventSource = evt.getSource();
if (eventSource == OKButton){
doIt();
dialog.setVisible(false);}
else if(eventSource == cancelButton)
{
dialog.setVisible(false);
}
else if(eventSource == applyButton)
{
doIt();
}
}


public void DinnerReservationDialog(Frame parent)
{
super(parent,"The DinnerReservationRoom");
DinnerMediator mediator= new DinnerMediator();
//Container contentPane =getContentPane;
contentPane.add(createDispositionPanel(mediator),BorderLayot.SOUTH);
contentPane.add(createBodyPanel(mediator),BorderLayot.CENTER);
contenPane.add(createTopPanel(mediator),BorderLayou.NORTH);
//pack
}
private JPanel createBodyPanel(DinnerMediator mediator)
{
JPanel BodyPanel = new JPanel(new BorderLayout (5,3));
bodyPanel.add(new JSeparator(),BorderLayout.NORTH);
bodyPane.add(createMainPanel(mediator),BorderLayout.CENTER);
bodyPanel.add(new JSeparator(),BorderLayout.SOUTH);
return bodyPanel;
}

private Container createMainPanel(DinnerMediator mediator)
{
JPanel mainPanel;
mainPanel= new JPanel(new BorderLayout(5,3));
mainPanel.add(creatDateTimePanel(mediator), BorderLayout.WEST);
mainPanel.add(createServicePanel(mediator),BorderLayout.CENTER);
String foods[] = { " " ," ", " ", " "};
JList foodList = new JList(foods);
int mode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION;
foodList.setSelectionMode(mode);
foodList.setVisibleRowCount(7);
mediator.registerFoodList(foodList);
mainPanel.add(foodList,BordrLayout.EAST);
retun mainPanel;
}

private JPanel createDispositionPanel(DinnerMeditor mediator)
{
JPanel p;
p= new JPanel(new FlowLayout(FlowLayout.CENTER(20,5)));
JButton okButton = new JButton("OK");
meiator.registerOkButton(okButton);
p.add(okButton);
JButton cancelButton = new JButton("Cancel");
p.add(cancelButton);
return p;
}
private JPanel createTopPanel(DinnerMediator mediator)
{
JPanel top = new JPanel(new BorderLayot(10,5));
Jpanel countPanel;
countPanel= new JPanel();
cuntPanel.add(new Label("NumberOfPeople(25-150);"));
JTextField countField = new TextField(4);
medaitor.registerPeopleCountField(countField);
countPanel.add(countField);
to.add(countField);
top.add(countPanel.BrderLayout.WEST);
return top;
}
}
class DinnerMediator
{
private JButton okButton;
private JTextComponent dateField;
private JTextComponent startField;

private JTextComponent endField;
private JRadioButton buffeButton,tableServiceButton;
private ItemAdapter itemAdapter = new ItemAdapter();

DinnerMediator()
{
WindowAdapter windowAdapter = new WindowAdapter();

windowOpened(WindowEvent e)
{
initialState();
}
}
DinnerReservationDialog enclosingDialog;
enclosingDialog = DinnerReservationDialog.this;
enclosing.addWindowListener(windowAdapter);
}
class ItemAdapter implements ItemListener
{
public void itemStateChanged(ItemEvent e)
{
enforceInvariants();
}
}
public void registerOkButton(JButton ok)
{
okButton = ok;
}
public void registerPeopleCountField( final JTextComponent field)
{
peopleCountField field = field;
DocumenAdaper docdapter =new DocumentAdapter()
{
protected void parseDocument()
{
int count =PEOPLE_COUNT_DEFAULT;
try
{
String countText = field.getText();
count= Integer.parseInt.countText();
}
catch(NumberFormatException e)
{
}

if(MIN_PEOPLE <= count && count <= MAX_PEOPLE)
peopleCount count;
else
peopleCount =PEOPLE_COUNT_DEFAULT;
}
Document doc= field.getDocument();
doc.addDocumentListener(docAdapter);

}
private boolean busy = false;
private void enforceInvariants()
{
if(busy)
return;
//busy = true;
if(EnforceInvariants(){
busy = false;}
}
}
private void protetedEnforceInvariants()
{
boolean enable = (peopleCount != PEOPLE_COUNT_DEFAULT)
dateField.setEnabled(enable);
startField.setEnabled(enable);
endField.setEnabled(enable);
buffetButton.setEnabled(enable);
tableServiceButton.setEnabled(enable);
if(enable)
{
enable=(buffetButton. isSelected()
|| tableServiceButton.isSelected());
foodList.setEnabled(enable && endAtleastOneHourAfterStart());
}
else
{
foodList.setEnabled(false);
buffetButton.seteleted(false);
tableServiceButton.setelcted(false);
}
okButton.setEnabled(foodList.isEnabled()
&& foodList.setMinSelectorIndex() > -1);
}
private boolean endAtleastOneHourAfterStart()
{
Calendar startCalendar = getStartCalendar();
if(StartCalendar == null)
return false;
Calendar endCalendar = getEndCalendar();
if(endCalendar== null)
return false;
startCalendar.add(Calendar.MINUTE,59)
retun getEndCalendar().after(startCalendar);
}

static public void main(String argv[])
{
JFrame frame = new JFrame("FlowLayout");
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
)
frame.getContentPane().add(new BorderLayout(),BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}


//The Mediator Pattern uses one Object to co ordinate state changes between other Objects.It puts the logic to manage state changes of other obejcts in one class instead of distributing the logic over the other classes.This results in more cohesive implementation of the logic and decreased coupling between the other classes.Here a dialogue box is getting implemented in order to specify information to reserve a dinning room in a Hotel.
AS Always
C.R.Muthukumar
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
First - it would help if you could edit your post to put the code inside code tags. This makes it a lot easier to read.

Second - what's your question ?
Is the code not compiling ? If so, post the error messages and an indication of which line in your code they refer to.
Is the program not doing what you expect it to do ? If so, tell us what it is doing and how this differs from what tou want it to do. If it is throwing an exception, post the full text of the exception.


Joanne
C.R.Muthukumar
Ranch Hand

Joined: Dec 03, 2004
Posts: 59
Originally posted by Joanne Neal:
First - it would help if you could edit your post to put the code inside code tags. This makes it a lot easier to read.

Second - what's your question ?
Is the code not compiling ? If so, post the error messages and an indication of which line in your code they refer to.
Is the program not doing what you expect it to do ? If so, tell us what it is doing and how this differs from what tou want it to do. If it is throwing an exception, post the full text of the exception.

Hello JoanneNeal,

This is a program to club various classes and keep the mediator class ready to lead .The main variables are No Of people who have to reserve a Hotel,date of their participation,time,along with the type of service requirement for the predetermined menu recipe(food).As u'r aware that each variable depends on the rules /scope of the hotel ,getting executed under different classes.
The errors are not much but quite intricate since the program reqires an executable stage in order make it useful for Hotel industries.
Shall be thankful if the needs of the the same is tried
As Always
C.R.Muthukumar


C:\jdk1.3\bin\DinnerMediator1.java:27: <identifier> expected
ActionDialogMgr{
^
C:\jdk1.3\bin\DinnerMediator1.java:107: ';' expected
}
^
C:\jdk1.3\bin\DinnerMediator1.java:122: ')' expected
windowOpened(WindowEvent e)
^
C:\jdk1.3\bin\DinnerMediator1.java:126: ';' expected
}
^
C:\jdk1.3\bin\DinnerMediator1.java:128: <identifier> expected
enclosingDialog = DinnerReservationDialog.this;
^
C:\jdk1.3\bin\DinnerMediator1.java:129: <identifier> expected
enclosing.addWindowListener(windowAdapter);
^
C:\jdk1.3\bin\DinnerMediator1.java:138: 'class' or 'interface' expected
public void registerOkButton(JButton ok)
^
7 errors
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
The first error is due to missing brackets on your constructor declaration
At line 27 change to
I would guess the rest of your errors are due to syntax errors and typos, but it is difficult to tell without seeing formatted code. Go to the line numbers given in each of the errors and look for missing ;s or unmatched {}.
C.R.Muthukumar
Ranch Hand

Joined: Dec 03, 2004
Posts: 59
Originally posted by Joanne Neal:
The first error is due to missing brackets on your constructor declaration
At line 27 change to
I would guess the rest of your errors are due to syntax errors and typos, but it is difficult to tell without seeing formatted code. Go to the line numbers given in each of the errors and look for missing ;s or unmatched {}.


Hello Mr.Joanne Neal,

Thanks for your hints which,after trying and trying got the the same program brought to nine errors.Can you now help to get complete soltion
.Also please accept BestWishes for the new year.
Hope to get your reply favourably .


import java.io.*;
import java.util.Arrays.*;
import java.util.Iterator;
import java.util.regex.Matcher.*;
import java.util.regex.Pattern.*;
import java.awt.event.*;
import java.awt.event.ActionEvent.*;
import java.awt.event.ActionListener.*;
import javax.swing.JPanel;
import javax.swing.JComponent.*;
import java.lang.Thread;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.Timer;
import java.util.Enumeration;
import javax.swing.border.*;
import java.security.*;
import javax.swing.text.*;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JScrollPane;
import java.awt.AWTEvent;
import java.lang.Math;
import java.text.*;
import java.util.*;
import java.lang.reflect.*;
import java.util.RandomAccess;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.EventObject;
import java.awt.Font;
import java.awt.Dimension;
import java.awt.*;
import javax.swing.JPanel.*;
import javax.swing.JButton.*;
import javax.swing.JSeparator.*;
import javax.swing.JDialog.*;
import javax.swing.JList.*;
import javax.swing.JLabel.*;
import javax.swing.JComponent.*;
import javax.swing.JRadioButton.*;
import javax.swing.JInternalFrame.*;
import java.awt.BorderLayout.*;
import java.awt.FlowLayout.*;
import java.util.Arrays.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.util.Date;

public class DinnerMediator1 extends JFrame{

private JButton okButton,cancelButton;
private JTextComponent noOfPeopleField;
private JTextComponent dateField;

private JTextComponent startField;
private JTextComponent endField;
private JRadioButton buffeButton,tableServiceButton;
private ItemAdapter itemAdapter;
private WindowAdapter windowAdapter ;
private DinnerMediator1 mediator;
private JPanel jPanel;


public class Dinner1 extends DinnerMediator1{


// DinnerMediator1 mediator=new DinnerMediator1();


noOfPeopleField= new JTextComponent();

dateField=new JTextComponent();

startField = new JTextComponent();

endField = new JTextComponent();

buffeButton= new JRadioButton();

tableServiceButton=new JRadioButton();
windowAdapter = new WindowAdapter();
itemAdapter = new ItemAdapter();
jPanel=new JPanel();

class JPanel extends DinnerMediator1{

public void createBodyPanel(DinnerMediator1 mediator)
{
JPanel BodyPanel = new JPanel(new BorderLayout (5,3));
bodyPanel.add(new JSeparator(),BorderLayout.NORTH);
bodyPane.add(createMainPanel(mediator),BorderLayout.CENTER);
bodyPanel.add(new JSeparator(),BorderLayout.SOUTH);
//return bodyPanel;
}

public void createMainPanel(DinnerMediator1 mediator)
{
JPanel mainPanel;
mainPanel= new JPanel(new BorderLayout(5,3));
mainPanel.add(creatDateTimePanel(mediator), BorderLayout.WEST);
mainPanel.add(createServicePanel(mediator),BorderLayout.CENTER);
String foods[] = { " " ," ", " ", " "};
JList foodList = new JList(foods);
int mode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION;
foodList.setSelectionMode(mode);
foodList.setVisibleRowCount(7);
mediator.registerFoodList(foodList);
mainPanel.add(foodList,BordrLayout.EAST);
//retun mainPanel;
}
public void createDispositionPanel(DinnerMeditor1 mediator)
{
JPanel p;
p= new JPanel(new FlowLayout(FlowLayout.CENTER(20,5)));
JButton okButton = new JButton("OK");
meiator.registerOkButton(okButton);
p.add(okButton);
JButton cancelButton = new JButton("Cancel");
p.add(cancelButton);
//return p;
}
public void createTopPanel(DinnerMediator1 mediator)
{
JPanel top = new JPanel(new BorderLayot(10,5));
Jpanel countPanel;
countPanel= new JPanel();
cuntPanel.add(new Label("NumberOfPeople(25-150);"));
JTextField countField = new TextField(4);
medaitor.registerPeopleCountField(countField);
countPanel.add(countField);
to.add(countField);
top.add(countPanel.BrderLayout.WEST);
//return top;
}



public static void main(String args[])
{

mediator.setLayout(new FlowLayout());
mediator.setSize(300,300);
mediator.setVisible(true);
KeyAdpt keyadpt= new KeyAdpt(mediator);
WindowClosing wc=new WindowClosing();
mediator.addWindowListener(wc);
mediator.add();
mediator.addKeyListener(keyadpt);


try
{


JFrame frame = new DinnerMediator1();

DinnerMediator1 mediator = new DinnerMediator1();

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {


new DinnerMediator();
DinnerMediator1 mediator= new DinnerMediator1();
new DinnerMediator1();
mediator.show();
mediator.setVisible(true);

}
});

frame.setSize(700, 500);
frame.setVisible(true);


}
catch(Exception ex)
{

System.out.println();
}

}




public void registerOkButton(JButton ok)
{
okButton = ok;
}

public void registerPeopleCountField( final JTextComponent field)
{
peopleCountField field = field;
DocumenAdaper docdapter =new DocumentAdapter()
{
protected void parseDocument()
{
int count =PEOPLE_COUNT_DEFAULT;
try
{
String countText = field.getText();
count= Integer.parseInt.countText();
}
catch(NumberFormatException e)
{
}

if(MIN_PEOPLE <= count && count <= MAX_PEOPLE)
count=0;
else
peopleCount =PEOPLE_COUNT_DEFAULT;
}
Document docAdapter = field.getDocument();
//doc.addDocumentListener(this);

};
boolean busy = false;

EnforceInvariants();
{
if(busy)
return;
busy = true;
if(true)
EnforceInvariants();

busy = false;
}
}

private void protetedEnforceInvariants()
{
boolean enable = (peopleCount != PEOPLE_COUNT_DEFAULT)
dateField.setEnabled(enable);
startField.setEnabled(enable);
endField.setEnabled(enable);
buffetButton.setEnabled(enable);
tableServiceButton.setEnabled(enable);
if(enable)
{
enable=(buffetButton. isSelected()
|| tableServiceButton.isSelected());
foodList.setEnabled(enable && endAtleastOneHourAfterStart());
}
else
{
foodList.setEnabled(false);
buffetButton.seteleted(false);
tableServiceButton.setelcted(false);
}
okButton.setEnabled(foodList.isEnabled()
&& foodList.setMinSelectorIndex() > -1);
}

public boolean endAtleastOneHourAfterStart()
{
Calendar startCalendar = getStartCalendar();
if(StartCalendar == null)
return false;
Calendar endCalendar = getEndCalendar();
if(endCalendar== null)
return false;
startCalendar.add(Calendar.MINUTE,59);
return getEndCalendar().after(startCalendar);
}


public void actionPerformed(ActionEvent evt){
Object eventSource = evt.getSource();
if (eventSource == OKButton){
doIt();
dialog.setVisible(false);}
else if(eventSource == cancelButton)
{
dialog.setVisible(false);
}
else if(eventSource == applyButton)
{
doIt();
}
}
Container contentPane =getContentPane();
{
contentPane.add(createDispositionPanel(mediator),BorderLayot.SOUTH);
contentPane.add(createBodyPanel(mediator),BorderLayot.CENTER);
contenPane.add(createTopPanel(mediator),BorderLayou.NORTH);
//pack
}
}
}

class buttonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {

if (e.getActionCommand().equals(DinnerMediator1.EXIT)) {
System.exit(1);
}
CommandInterface CommandObj = (CommandInterface) e.getSource();
CommandObj.processEvent();
}



interface CommandInterface {
public void processEvent();
}

class OkButton extends JButton implements CommandInterface {
DinnerMediator1 mdtr;

public void processEvent() {
mdtr.UploadItem();
}

}
}
class ItemAdapter implements ItemListener
{
public void itemStateChanged(ItemEvent e)
{
enforceInvariants();
}

public void itemStateChanged(ItemEvent ie)
{
if(ie.getStateChange() == (ie.SELECTED))
{
Dialog dialog= new Dialog(dm,"Dialog Window");
dialog.setSize(100,190);
dialog.setVisible(true);
WindowClosing wc= new WindowClosing();
dialog.addWindowListener(wc);
}

}
}
class KeyAdpt extends KeyAdapter{
DinnerMediator1 mediator;
KeyAdpt(DinnerMediator1 mediator1)
{
mediator=mediator1;
}

public void KeyPressed(KeyEvent ke)
{
int i=ke.getKeyCode();
if(i==ke.VK_ENTER)
{
Dialog dialog = new Dialog(mediator1,"DialogWindow");
dialog.setSize(100,100);
dialog.setVisible(true);
WindowClosing wc= new WindowClosing();
dialog.addWindowListener(wc);
}
}
class WindowClosing extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
}


}





}C:\jdk1.3\bin\DinnerMediator1.java:78: <identifier> expected
noOfPeopleField= new JTextComponent();
^
C:\jdk1.3\bin\DinnerMediator1.java:80: <identifier> expected
dateField=new JTextComponent();
^
C:\jdk1.3\bin\DinnerMediator1.java:82: <identifier> expected
startField = new JTextComponent();
^
C:\jdk1.3\bin\DinnerMediator1.java:84: <identifier> expected
endField = new JTextComponent();
^
C:\jdk1.3\bin\DinnerMediator1.java:86: <identifier> expected
buffeButton= new JRadioButton();
^
C:\jdk1.3\bin\DinnerMediator1.java:88: <identifier> expected
tableServiceButton=new JRadioButton();
^
C:\jdk1.3\bin\DinnerMediator1.java:89: <identifier> expected
windowAdapter = new WindowAdapter();
^
C:\jdk1.3\bin\DinnerMediator1.java:90: <identifier> expected
itemAdapter = new ItemAdapter();
^
C:\jdk1.3\bin\DinnerMediator1.java:91: <identifier> expected
jPanel=new JPanel();
^
9 errors

As Always
C.R.Muthukumar
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Look at the messages. Look at the lines of code mentioned in the messages. Look immediately before the lines. Try to figure out, starting with the first one, what's wrong with the code. You need to be able to do this for yourself.

Note that Joanne is a woman.

Moving to Java in General (Beginner).


[Jess in Action][AskingGoodQuestions]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
Originally posted by C.R.Muthukumar Muthukumar:


Hello Mr.Joanne Neal,


Originally posted by Ernest Friedman-Hill:
Note that Joanne is a woman.


Makes a change from being referred to just as 'Neal', and I've been called worse
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 557
    
    7

--------------------------------------------------------------------------------
Originally posted by Ernest Friedman-Hill:
Note that Joanne is a woman.

--------------------------------------------------------------------------------


Joanne is a lady.
[ January 08, 2007: Message edited by: Steve Fahlbusch ]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
Originally posted by Steve Fahlbusch:


Joanne is a lady.

[ January 08, 2007: Message edited by: Steve Fahlbusch ]


<flutters eyelashes>
Thank you, kind sir.
</flutters eyelashes>
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11175
    
  16

PLEASE, when posting your source code, use the "code" tags. before you paste it into the box, press that button below that says "code". this should put two tags that look like this:
[ CODE] [ /CODE]

only without the spaces after the first bracket. then, paste your source code BETWEEN those tags. This will preserve your formatting/indentation, and make your code MUCH easier to read.

Code that is easier to read is much more likely to get helpful answers.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
C.R.Muthukumar
Ranch Hand

Joined: Dec 03, 2004
Posts: 59
Originally posted by Ernest Friedman-Hill:
Look at the messages. Look at the lines of code mentioned in the messages. Look immediately before the lines. Try to figure out, starting with the first one, what's wrong with the code. You need to be able to do this for yourself.

Note that Joanne is a woman.

Moving to Java in General (Beginner).




Now atleast, you would be able to know what the mediator pattern is ,as you are able to get the insight of its crieteria from the above example(MediatorClient.txt).So The task at hand ,for a java programmer is to synchronise and co-ordinate the subject DinnerMediator program to fetch the ultimate clearence of the same .
Hope this is better understood from the above example than said are explained.In the event of a positive solutions, tons and tons of thanks in advance.
As Always
C.R.Muthukumar




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mediatortype javaprog requiring solution
 
Similar Threads
JTextField listener to enable button action
Help with Chat software
Setting color in a JComboBox
2D Array Help
Mediatortype javaprog requiring solution