Skip to content

Commit 0fd0968

Browse files
committed
Implement basic display of values
1 parent a44513e commit 0fd0968

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed
Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,93 @@
11
package net.hontheim;
22

33
import javafx.application.Application;
4+
import javafx.event.ActionEvent;
5+
import javafx.event.EventHandler;
6+
import javafx.geometry.Insets;
7+
import javafx.geometry.Pos;
48
import javafx.scene.Scene;
9+
import javafx.scene.control.Button;
510
import javafx.scene.control.Label;
611
import javafx.scene.layout.GridPane;
712
import javafx.stage.Stage;
813

14+
import java.io.IOException;
15+
import java.nio.ByteBuffer;
16+
917
public class MainApp extends Application {
1018

19+
private GridPane pane = new GridPane();
20+
private Label lblTitle, lblDirectAllocation, lblNativeUsed, lblmaxMemory;
21+
private Label valDirectAllocation, valNativeUsed, valmaxMemory;
22+
private Button btnUpdate, btnReopen;
23+
24+
private static ByteBuffer humonguosBuffer = ByteBuffer.allocateDirect(1024*1024*1024);
25+
1126
public static void main(String[] args) {
1227
launch(args);
1328
}
1429

1530
@Override
1631
public void start(Stage stage) throws Exception {
17-
stage.setScene(new Scene(new GridPane(), 160, 90));
32+
stage.setTitle("Java Memory");
33+
this.initializeComponents();
34+
this.updateValues();
35+
this.placeComponents(stage);
36+
this.registerListener();
37+
stage.setResizable(false);
1838
stage.show();
1939
}
40+
41+
private void initializeComponents() {
42+
lblTitle = new Label("Java Memory");
43+
lblTitle.setStyle("-fx-font-size: 18; -fx-font-weight: bold;");
44+
45+
lblDirectAllocation = new Label("Direct allocation:");
46+
lblNativeUsed = new Label("Native memory used:");
47+
lblmaxMemory = new Label("Max direct memory:");
48+
49+
valDirectAllocation = new Label();
50+
valNativeUsed = new Label();
51+
valmaxMemory = new Label();
52+
53+
btnUpdate = new Button("Update");
54+
btnUpdate.setDefaultButton(true);
55+
}
56+
57+
private void placeComponents(Stage stage) {
58+
pane.setHgap(10);
59+
pane.setVgap(10);
60+
pane.setPadding(new Insets(15, 25, 15, 25));
61+
62+
pane.add(lblTitle, 0, 0, 2, 1);
63+
64+
pane.add(lblDirectAllocation, 0, 2);
65+
pane.add(lblNativeUsed, 0, 3);
66+
pane.add(lblmaxMemory, 0, 4);
67+
68+
pane.add(valDirectAllocation, 1, 2);
69+
pane.add(valNativeUsed, 1, 3);
70+
pane.add(valmaxMemory, 1, 4);
71+
72+
pane.add(btnUpdate, 0, 6);
73+
74+
pane.setAlignment(Pos.CENTER);
75+
76+
stage.setScene(new Scene(pane, 300, 250));
77+
}
78+
79+
private void registerListener() {
80+
btnUpdate.setOnAction(new EventHandler<ActionEvent>() {
81+
@Override
82+
public void handle(ActionEvent event) {
83+
updateValues();
84+
}
85+
});
86+
}
87+
88+
private void updateValues() {
89+
this.valDirectAllocation.setText("" + humonguosBuffer.capacity());
90+
this.valNativeUsed.setText("" + sun.misc.SharedSecrets.getJavaNioAccess().getDirectBufferPool().getMemoryUsed());
91+
this.valmaxMemory.setText("" + sun.misc.VM.maxDirectMemory());
92+
}
2093
}

0 commit comments

Comments
 (0)