Hello, Can anyone assist me to implement a component-based project? I have designed two components i.e calculator and engine (source codes below) which need to be inside any of the swing components (either JList , JTree, or any). Then there should be an ability of dragging any of the two components (calculator or engine) unto the editor pane for composition using a connector (code give below). If the composition is right, let the composite return unto the palette where the initial components were dragged from.
Components:
public class Engine {
private String name = "";
private boolean running = false;
private int speed;
public Engine(String name) {
this.name = name;
}
public void start() {
if (!running) {
running = true;
System.out.println("Engine starts.");
}
else
System.out.println("Engine already starts.");
}
public void stop() {
if (running) {
running = false;
speed = 0;
System.out.println("Engine stops.");
}
else
System.out.println("Engine already stops.");
}
public void setSpeed(int speed) {
if (speed >=0)
this.speed = speed;
}
} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
public class Calc {
public Calc() {
}
public Double squareRoot(Double a_double){
return Math.sqrt(a_double);
}
// pre an_int >= 0
public synchronized Integer factorial(Integer an_int){
int fact=1;
for(int i=1;i<=an_int;i++){
fact *= i;
}
return fact;
}
/**
*
* @param an_int
* @return the squared root of the input integer
*/
public Integer getSquareRoot(Integer an_int){
return (int) Math.sqrt(an_int);
}
public Double getSquareRoot(Double aDouble){
return Math.sqrt(aDouble);
}
/**
* Converts an Integer object into a Double object.
*
* @param an_int The Integer to be converted.
* @return The Double object representing the same value.
*
*/
public Double integerToDouble(Integer an_int){
return new Double(an_int.intValue());
}
/**
* Converts a Double object into an Integer object. Decimal digits are
* truncated. Useful when passing the output of a method as the input to another.
*
* @param a_double The Double to be converted.
* @return The Integer object representing the same value.
*
*/
public Integer doubleToInteger(Double a_double){
return new Integer(a_double.intValue());
}
public Integer sum(Integer a, Integer b) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return a+b;
}
/**
* Returns a string representation of the calculator.
*/
public String toString(){
return("Calculator computation unit:\n"+super.toString());
}
void doNothing(){
}}
/////////////////////////////////////////////////////////////////////////////////////////