Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.
Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin. Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Javada Aggregation+Form(fxml) dan foydalanish

+1 ovoz
66 marta ko‘rilgan
so‘radi 21 fevral, 18 SARVARBEK (355 bal)
tahrirlandi 21 fevral, 18 SARVARBEK

Assalom aleykum. Javada ishlashni endi boshlayotgan edim. JavaFXda formla bilan ishlashda quyidagicha muammoga duch keldim.

StationForm nomli forma (StationForm.fxml) mavjud.

StationForm.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.canvas.Canvas?>
<AnchorPane fx:controller="StationController">
      //...
</AnchorPane>

StationFormga bog'langan StationController.java class mavjud.

StationController.java
  1. import ...

  2. public class StationController extends Application {

  3. //<editor-fold desc="Controls">

  4.     @FXML

  5.     public Label starttimelabel;

  6.     @FXML

  7.    public Label currenttimelabel;

  8.     @FXML

  9.     public Label nolvaluelabel;

  10.     @FXML

  11.     public Label maxvaluelabel;

  12.     @FXML

  13.     public Label minvaluelabel;

  14.     @FXML

  15.     public ScrollBar scrollbar;

  16.     @FXML

  17.     public Canvas canvas;

  18. //</editor-fold>

  19. //<editor-fold desc="Global variables">

  20.     Station station;

  21.     Date starttime;

  22.     Date currenttime;

  23.     double[] data;

  24.     Btime lastpacketBtime;

  25.     double packetlength;

  26.     int pointcount;

  27.     double peek;

  28.     GraphicsContext graphicsContext;

  29.     int maxpointcount;

  30.     Point2D p1;

  31.     double graphicswidth;

  32.     double graphicsheight;

  33.     int numberpacketfordatfiles;

  34.     int maxvalue;

  35.     int viewminutvalue;

  36.     boolean isworking;

  37. //</editor-fold>

  38. //...

  39.     public void Start(){

  40.         Application.launch(this.getClass(),null);

  41.     }

  42.     public StationController(Station s){

  43.         this.station=s;

  44.     }

  45.     @Override

  46.     public void start(Stage primaryStage) throws Exception {

  47.         Parent root = FXMLLoader.load(getClass().getResource("StationForm.fxml"));

  48.         Scene scene = new Scene(root);

  49.         primaryStage.setScene(scene);

  50.         primaryStage.show();

  51.     }

  52.     public static void main(String[] args) {

  53.         launch(args);

  54.     }

  55. //...

  56.  }

O'zim yaratgan Station nomli bosh sinf mavjud.

Station.java

  1. import ...

  2. public class Station {

  3.     public String host;

  4.     public int port;

  5.     public String stationname;

  6.     public double amplituda;

  7.     public String datfilepath;

  8.     public String location;

  9.     public String network;

  10.     public String stationcode;

  11.     public TypeServer typeserver;

  12.     public SeedlinkReader seedlinkreader;

  13.     public StationController stationController;

  14.     public String channel;

  15.     public String start;

  16.     public String end;

  17.     public String infoType;

  18.     public String ioutFile;

  19.     public java.io.DataOutputStream dos;

  20.     public java.io.File file;

  21.     public java.io.PrintWriter out1;

  22.     public int timeoutSeconds;

  23.     //public TreeNode treenode;

  24. //...

  25.      public Station()

  26.     {

  27.         stationController = new StationController(this);

  28.     }

  29.     public void Start() throws FileNotFoundException {

  30.         this.channel="BHZ";

  31.         this.start = SeedlinkReader.EMPTY;

  32.         this.end = SeedlinkReader.EMPTY;

  33.         this.timeoutSeconds = SeedlinkReader.DEFAULT_TIMEOUT_SECOND;

  34.         this.infoType = SeedlinkReader.EMPTY;

  35.         this.ioutFile = SeedlinkReader.EMPTY;

  36.         this.dos = null;

  37.         this.file = new java.io.File(this.stationname + ".log");

  38.         this.out1 = new java.io.PrintWriter(this.file);

  39.         this.stationController.Start();

  40.     }

  41. //...

  42.  }

Dasturni ishga tushish nuqtasi hisoblanadigan MainClass nomli class mavjud.

MainClass.java

  1. import ...

  2. public class MainClass {

  3.     public static void main(String[] args) throws FileNotFoundException {       

  4.         Station station=new Station();

  5. //...

  6.         station.Start();

  7. }

  8. }

Station sinfida field(maydon) sifatida StationController turida obyekt yaratilgan bo'lib, g'oya shundan iboratki har bir stationda o'zining formasi mavjud bo'lishi kerak. MainClass sinfining 6-qatoridagi station.Start() funksiyasi ishga tushganda Station sinfidagi 29-qatorda yozilgan funksiyaga murojaat qilinadi.Station.java sinfining 39-qatoriga kelganda StationController sinfidagi 39-qatorda yozilgan funksiyaga murojaat qiladi va shu yerda xatolik kelib chiqadi.

Muammo: StationController turidagi obyektni yaratishda. Qanday qilib StationController turidagi obyektni Station sinfi ichida yaratsam bo'ladi?

Oldindan rahmat!

1 ta javob

0 ovoz
javob berdi 16 mart, 18 SARVARBEK (355 bal)
tahrirlandi 16 mart, 18 SARVARBEK
 
Eng yaxshi javob
StationController.java sinfi UI ga tegishli bo'lganligi uchun uni to'g'ridan - tog'ri ishlatish mumkin emas. Buning uchun Platform.runLater() - funksiyasidan foydalanishingiz kerak, ya'ni:

Platform.runLater(()->{

//UI ga tegishli ishlar bajariladi

});

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...