Commit 5b086538 authored by Antoine Sauray's avatar Antoine Sauray
Browse files

initial commit

parents
<?xml version="1.0"?>
<project name="ihm" default="compile">
<target name="init">
<property name="sourceDir" value="src"/>
<property name="outputDir" value="build" />
<property name="testDir" value="build/test"/>
<property name="junitLocation" value="lib/junit-4.12.jar" />
<property name="hamcrestLocation" value="lib/hamcrest-core-1.3.jar"/>
</target>
<target name="clean" depends="init">
<delete dir="${outputDir}" />
</target>
<target name="prepare" depends="init">
<mkdir dir="${outputDir}" />
</target>
<target name="compile" depends="prepare">
<javac srcdir="${sourceDir}" destdir="${outputDir}" classpath="${junitLocation}"
includeantruntime="false"/>
</target>
<path id="classpath">
<pathelement location="${outputDir}" />
<pathelement location="${junitLocation}"/>
<pathelement location="${testDir}" />
<pathelement location="${hamcrestLocation}" />
</path>
<target name="test" depends="compile">
<echo>Running the junit tests...</echo>
<junit fork="yes" haltonfailure="yes">
<test name="test" />
<formatter type="plain" usefile="false" />
<classpath refid="classpath" />
</junit>
</target>
<target name="exec">
<exec executable="java">
<arg value="Main"/>
</exec>
</target>
</project>
\ No newline at end of file
import model.*;
import controller.*;
import view.*;
public class Main{
public static void main(String[] args){
View v1 = new View();
v1.setVisible(true);
View v2 = new View();
v2.setVisible(true);
Model m1 = new Model();
Model m2 = new Model();
GeneralController gc = new GeneralController(v1, m1, v2, m2);
}
}
package controller;
import java.util.Observer;
import java.util.Observable;
import view.*;
import model.*;
import java.awt.*;
import java.awt.event.*;
public class Controller implements Observer{
private View view;
private Frame jframe;
private Model model;
public Controller(View view, Model model){
this.view=view;
this.model=model;
model.addObserver(this);
view.getLess().setEnabled(false);
MoreAction mAction = new MoreAction(view, model);
LessAction lAction = new LessAction(view, model);
TextAction tlAction = new TextAction(view, model);
}
public void update(Observable o,
Object arg){
System.out.println(""+((Model)o).getValue());
}
}
\ No newline at end of file
package controller;
import java.util.Observer;
import java.util.Observable;
import view.*;
import model.*;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;
public class GeneralController implements Observer{
private View v1, v2;
private Model m1, m2;
private MoreAction mAction, mAction2;
private LessAction lAction, lAction2;
private TextAction tlAction, tlAction2;
public GeneralController(View v1, Model m1, View v2, Model m2){
this.v1=v1;
this.m1=m1;
this.v2=v2;
this.m2=m2;
m1.addObserver(this);
m2.addObserver(this);
mAction = new MoreAction(v1, m1);
lAction = new LessAction(v1, m1);
tlAction = new TextAction(v1, m1);
mAction2 = new MoreAction(v2, m2);
lAction2 = new LessAction(v2, m2);
tlAction2 = new TextAction(v2, m2);
}
public void update(Observable o,
Object arg){
if((Model)o == m1){
m2.setValueWithoutNotifying(10-m1.getValue());
if(m2.getValue()==10){
v2.getMore().setEnabled(false);
v2.getLess().setEnabled(true);
}
else if(m2.getValue()==0){
v2.getMore().setEnabled(true);
v2.getLess().setEnabled(false);
}
else{
v2.getMore().setEnabled(true);
v2.getLess().setEnabled(true);
}
}
else{
m1.setValueWithoutNotifying(10-m2.getValue());
if(m1.getValue()==10){
v1.getMore().setEnabled(false);
v1.getLess().setEnabled(true);
}
else if(m1.getValue()==0){
v1.getMore().setEnabled(true);
v1.getLess().setEnabled(false);
}
else{
v1.getMore().setEnabled(true);
v1.getLess().setEnabled(true);
}
}
System.out.println("Model1["+m1.getValue()+"]");
System.out.println("Model2["+m2.getValue()+"]");
}
}
\ No newline at end of file
package controller;
import view.*;
import model.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.AbstractAction;
public class LessAction extends AbstractAction{
private View view;
private Model m;
public LessAction(View view, Model m){
this.view = view;
this.m=m;
view.getLess().addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
try{
view.getMore().setEnabled(true);
m.less();
if(m.getValue()==0){
view.getLess().setEnabled(false);
}
}
catch(IllegalValueException exc){
//view.showDialog(exc.getMessage());
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment