1
0

add simple GUI

This commit is contained in:
Joel Baldauf
2020-12-09 15:03:39 +01:00
parent f99dc5e78a
commit 9711ac4e32
2 changed files with 131 additions and 0 deletions
+21
View File
@@ -25,7 +25,28 @@ public class PunkteInNoten {
else else
System.out.printf("%d Punkte %d%%\n", point, pointPercentage); System.out.printf("%d Punkte %d%%\n", point, pointPercentage);
} }
}
public static String[][] calculateMarks (int maxPoints, int totalPercentage) {
int pointPercentage = 0;
double markIHK = 0.0;
String[][] output = new String[maxPoints+1][4];
for (int point=maxPoints; point>=0; point--) {
pointPercentage = (int) (((double)point/(double)maxPoints)*(double)totalPercentage);
markIHK = marksIHK[pointPercentage];
if (totalPercentage == 100) {
output[maxPoints-point][0] = Integer.toString(point);
output[maxPoints-point][1] = Integer.toString(pointPercentage) + " %";
output[maxPoints-point][2] = Double.toString(markIHK);
output[maxPoints-point][3] = Integer.toString((int)markIHK);
}
else {
output[maxPoints-point][0] = Integer.toString(point);
output[maxPoints-point][1] = Integer.toString(pointPercentage) + " %";
}
}
return output;
} }
} }
+110
View File
@@ -0,0 +1,110 @@
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.JLabel;
import java.awt.TextField;
import java.awt.Button;
import javax.swing.JList;
import javax.swing.JComboBox;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
public class frame extends JFrame {
private JPanel contentPane;
private JTable table;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame frame = new frame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public frame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 815, 369);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblTotalPercentage = new JLabel("Wievielen Prozenten sollen die Punkte entsprechen?");
lblTotalPercentage.setBounds(15, 84, 397, 20);
contentPane.add(lblTotalPercentage);
JLabel lblMaxPoints = new JLabel("Gesamtpunktzahl eingeben");
lblMaxPoints.setBounds(15, 16, 228, 20);
contentPane.add(lblMaxPoints);
// 0 als Startwert, von 0 bis ..., Schrittweite 1
SpinnerNumberModel modelMaxPoints = new SpinnerNumberModel(0, 0, null, 1);
JSpinner spMaxPoints = new JSpinner(modelMaxPoints);
spMaxPoints.setBounds(15, 42, 58, 26);
contentPane.add(spMaxPoints);
// 100 als Startwert, von 0 bis 100, Schrittweite 1
SpinnerNumberModel modelTotalPercentage = new SpinnerNumberModel(100, 0, 100, 10);
JSpinner spTotalPercentage = new JSpinner(modelTotalPercentage);
spTotalPercentage.setBounds(15, 120, 58, 26);
contentPane.add(spTotalPercentage);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(399, 16, 379, 281);
contentPane.add(scrollPane);
Button btnCalc = new Button("Berechnen");
btnCalc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String[][] result = PunkteInNoten.calculateMarks((int)spMaxPoints.getValue(), (int)spTotalPercentage.getValue());
String[] columnNames = {"Punkte",
"Prozente",
"IHK-Note",
"ganze Note"
};
table = new JTable(result, columnNames) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
table.setRowSelectionAllowed(false);
scrollPane.setViewportView(table);
}
});
btnCalc.setBounds(20, 167, 91, 27);
contentPane.add(btnCalc);
}
}