modular atwork handling system تیار کرنا نہایت ضروری ہے. sound and settleadoFX اطلاقیہ بنانے کے لیے system تیار کرنا بہت ضروری ہے. فدیہ ماڈل ان کے درمیان میں موجود system اور urlline رابطہ کو مؤثر طریقہ کار فراہم کرتا ہے. یہ مضمون جاوا ایف ایکس میں موجود modular acation system کو استعمال کرنے کے لیے کیسے عمل میں لایا جا سکتا ہے؟

س . ع .

یہ عمل ایک ایسا طریقہ ہے جس سے ایک مرکزی عضو کے ذریعے رابطہ قائم کرنے سے منعکس ہوتا ہے ۔

ڈی‌مین‌مین مواجہ‌اے ڈیزائن کرنا

بنگمین ایک ایسے داخلی تعملے سے تبدیل کرتا ہے جو اجزاء کو رجسٹر کرنے اور واقعات کو درست کرنے کے طریقے بتاتا ہے. یہ روبوٹ درمیانی کے اوصاف کے لیے ایک معاہدہ کے طور پر کام کرتا ہے.

public interface EventMediator {
 void registerComponent(String name, UIComponent component);
 void handleEvent(String eventType, String sourceComponent);
}

کال‌ناک

یہ مختلف واقعات کے جواب کے لئے ایک نقشہ قائم کرتا ہے اور اس میں مختلف واقعات کا جواب دینے کا طریقہ طے کِیا جاتا ہے ۔

public class ConcreteEventMediator implements EventMediator {
 private Map<String, UIComponent> components = new HashMap<>();

 @Override
 public void registerComponent(String name, UIComponent component) {
 components.put(name, component);
 }

 @Override
 public void handleEvent(String eventType, String sourceComponent) {
 // Example: handle button click
 if ("buttonClick".equals(eventType)) {
 UIComponent component = components.get(sourceComponent);
 // Perform actions based on the source component
 System.out.println(sourceComponent + " triggered a " + eventType);
 }
 }
}

یو آئی کے ارکان کی تخلیق

یو آئی اے کے اجزا جیسے بٹن یا ڈرافٹرز کو براہ راست ایک دوسرے سے براہ راست رابطہ کرنے کی بجائے مدیر سے رابطہ کرنا چاہیے۔ ہر اجزاء کو کسی واقعے کے وقت عضو کو ناجائز قرار دیتے ہیں۔

public interface UIComponent {
 void setMediator(EventMediator mediator);
 void triggerEvent(String eventType);
}

public class ButtonComponent implements UIComponent {
 private EventMediator mediator;
 private String name;

 public ButtonComponent(String name) {
 this.name = name;
 }

 @Override
 public void setMediator(EventMediator mediator) {
 this.mediator = mediator;
 }

 @Override
 public void triggerEvent(String eventType) {
 mediator.handleEvent(eventType, name);
 }
}

جاوا ایفکس میں انٹرینگ کومپونینٹ اور ایمپلر ہیں۔

آپ کے جاوا ایف ایکس درخواست میں، درمیانی اور اجزاء کو فوری طور پر، درمیانی حصے کے ساتھ حصے کو رجسٹر کریں اور تقریب کو فعال اطلاعات کو منتقل کرنے کے لئے قائم کریں.

public class MainApp extends Application {
 @Override
 public void start(Stage primaryStage) {
 ConcreteEventMediator mediator = new ConcreteEventMediator();

 ButtonComponent button1 = new ButtonComponent("Button1");
 ButtonComponent button2 = new ButtonComponent("Button2");

 button1.setMediator(mediator);
 button2.setMediator(mediator);

 mediator.registerComponent("Button1", button1);
 mediator.registerComponent("Button2", button2);

 Button javafxButton1 = new Button("Button 1");
 javafxButton1.setOnAction(e -> button1.triggerEvent("buttonClick"));

 Button javafxButton2 = new Button("Button 2");
 javafxButton2.setOnAction(e -> button2.triggerEvent("buttonClick"));

 VBox vbox = new VBox(10, javafxButton1, javafxButton2);
 Scene scene = new Scene(vbox, 300, 200);
 primaryStage.setScene(scene);
 primaryStage.setTitle("Mediator Pattern in JavaFX");
 primaryStage.show();
 }

 public static void main(String[] args) {
 launch(args);
 }
}

اس طریقہ کار کی پیروی سے آپ ایک مدوالہ، قابلِ عمل تقریب دستی نظام بناتے ہیں جو جاوا ایف ایکس کے اطلاقات میں شامل عناصر کو استعمال کرتے ہوئے