Graphical User Interfaces > Example Graphical User Interface > Displaying Results in the GUI

Displaying Results in the GUI
The aim of the GUI is to provide calculations of areas and moments of inertia based on the model. These results are added in a panel to the right of the graphics panel.
1
Add these fields to the top of the BeamModelDemo class file:
JTextField editA;
JTextField editIy;
JTextField editIz;
JTextField editJ;
2
Add a method rightPanel at the end of the BeamModelDeom.java that contains the output. Choose JTextFields to display the result. It is possible to copy text from these fields for use in other applications.
private JPanel rightPanel() {
  MigLayout layout = new MigLayout("wrap 2");
  JPanel panel = new JPanel(layout);
 
  JLabel label = new JLabel("A:");
  panel.add(label);
  editA = new JTextField(16);
  panel.add(editA);
 
  label = new JLabel("Iy:");
  panel.add(label);
  editIy = new JTextField(16);
  panel.add(editIy);
  label = new JLabel("Iz:");
  panel.add(label);
  editIz = new JTextField(16);
  panel.add(editIz);
  label = new JLabel("J:");
  panel.add(label);
  editJ = new JTextField(16);
  panel.add(editJ, "wrap 10px");
 
  return panel;
}
3
private String getScalar(NumericalFeature num) {
  double[][] array = num.getData(0);
  double A = array[0][0];
  return Double.toString(A);
}
4
editA.setText(getScalar(model.result().numerical("glA")));
editIy.setText(getScalar(model.result().numerical("glIy")));
editIz.setText(getScalar(model.result().numerical("glIz")));
editJ.setText(getScalar(model.result().numerical("glJ")));
5
Add code for producing the rightPanel to the start method just below the addition of the graphicsPanel:
panel = rightPanel();
mainPanel.add(panel, BorderLayout.LINE_END);
6