librejack

Blackjack clone written in java
git clone https://github.com/michaelneuper/librejack.git
README | Files | Log | Refs | LICENSE

commit a4d03f10f628787b26471c0efeaca97231515976
parent 3525373d686a044ddb48537f202e204a45ac7d15
Author: Michael Neuper <michael@michaelneuper.com>
Date:   Fri, 12 May 2023 17:09:03 +0200

Add labels to show statistics

Diffstat:
Msrc/view/StatisticsUI.form | 208++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/view/StatisticsUI.java | 149++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 337 insertions(+), 20 deletions(-)

diff --git a/src/view/StatisticsUI.form b/src/view/StatisticsUI.form @@ -18,18 +18,202 @@ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-123,0,0,3,40"/> </AuxValues> - <Layout> - <DimensionLayout dim="0"> - <Group type="103" groupAlignment="0" attributes="0"> - <EmptySpace min="0" pref="400" max="32767" attributes="0"/> - </Group> - </DimensionLayout> - <DimensionLayout dim="1"> - <Group type="103" groupAlignment="0" attributes="0"> - <EmptySpace min="0" pref="300" max="32767" attributes="0"/> - </Group> - </DimensionLayout> - </Layout> + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> + <SubComponents> + <Container class="javax.swing.JPanel" name="jPanelNorth"> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> + <BorderConstraints direction="North"/> + </Constraint> + </Constraints> + + <Layout> + <DimensionLayout dim="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace min="-2" pref="280" max="-2" attributes="0"/> + <Component id="jLabel1" min="-2" max="-2" attributes="0"/> + <EmptySpace pref="325" max="32767" attributes="0"/> + </Group> + </Group> + </DimensionLayout> + <DimensionLayout dim="1"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace min="-2" pref="17" max="-2" attributes="0"/> + <Component id="jLabel1" min="-2" max="-2" attributes="0"/> + <EmptySpace pref="21" max="32767" attributes="0"/> + </Group> + </Group> + </DimensionLayout> + </Layout> + <SubComponents> + <Component class="javax.swing.JLabel" name="jLabel1"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Segoe UI" size="48" style="1"/> + </Property> + <Property name="text" type="java.lang.String" value="Statistics"/> + </Properties> + </Component> + </SubComponents> + </Container> + <Container class="javax.swing.JPanel" name="jPanel1"> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> + <BorderConstraints direction="Center"/> + </Constraint> + </Constraints> + + <Layout> + <DimensionLayout dim="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" alignment="0" attributes="0"> + <Component id="jPanelStatisticsText" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="jPanelStatisticsChart" min="-2" max="-2" attributes="0"/> + </Group> + </Group> + </DimensionLayout> + <DimensionLayout dim="1"> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jPanelStatisticsChart" max="32767" attributes="0"/> + <Component id="jPanelStatisticsText" alignment="1" max="32767" attributes="0"/> + </Group> + </DimensionLayout> + </Layout> + <SubComponents> + <Container class="javax.swing.JPanel" name="jPanelStatisticsText"> + + <Layout> + <DimensionLayout dim="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" alignment="1" attributes="0"> + <EmptySpace min="-2" pref="69" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="jLabelPushes" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="jLabelLosses" alignment="0" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace pref="40" max="32767" attributes="0"/> + <Group type="103" groupAlignment="0" max="-2" attributes="0"> + <Component id="jLabelWinsAmount" min="-2" pref="136" max="-2" attributes="0"/> + <Component id="jLabelLossesAmount" pref="137" max="32767" attributes="0"/> + <Component id="jLabelPushesAmount" alignment="0" max="32767" attributes="0"/> + </Group> + <EmptySpace min="-2" pref="86" max="-2" attributes="0"/> + </Group> + <Group type="103" rootIndex="1" groupAlignment="0" attributes="0"> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace min="-2" pref="71" max="-2" attributes="0"/> + <Component id="jLabelWins" min="-2" max="-2" attributes="0"/> + <EmptySpace pref="261" max="32767" attributes="0"/> + </Group> + </Group> + </Group> + </DimensionLayout> + <DimensionLayout dim="1"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace min="-2" pref="38" max="-2" attributes="0"/> + <Component id="jLabelWinsAmount" min="-2" pref="43" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="27" max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="jLabelLosses" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jLabelPushesAmount" alignment="3" min="-2" pref="43" max="-2" attributes="0"/> + </Group> + <EmptySpace min="-2" pref="26" max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="jLabelPushes" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="jLabelLossesAmount" alignment="3" min="-2" pref="43" max="-2" attributes="0"/> + </Group> + <EmptySpace pref="67" max="32767" attributes="0"/> + </Group> + <Group type="103" rootIndex="1" groupAlignment="0" attributes="0"> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace min="-2" pref="43" max="-2" attributes="0"/> + <Component id="jLabelWins" min="-2" max="-2" attributes="0"/> + <EmptySpace pref="212" max="32767" attributes="0"/> + </Group> + </Group> + </Group> + </DimensionLayout> + </Layout> + <SubComponents> + <Component class="javax.swing.JLabel" name="jLabelLosses"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Segoe UI" size="24" style="0"/> + </Property> + <Property name="text" type="java.lang.String" value="Losses:"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelWins"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Segoe UI" size="24" style="0"/> + </Property> + <Property name="text" type="java.lang.String" value="Wins:"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelPushes"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Segoe UI" size="24" style="0"/> + </Property> + <Property name="text" type="java.lang.String" value="Pushes:"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelWinsAmount"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Segoe UI" size="18" style="0"/> + </Property> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> + <Connection code="&quot;&quot; + stats.getWins()" type="code"/> + </Property> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelLossesAmount"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Segoe UI" size="18" style="0"/> + </Property> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> + <Connection code="&quot;&quot; + stats.getLosses()" type="code"/> + </Property> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="jLabelPushesAmount"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Segoe UI" size="18" style="0"/> + </Property> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> + <Connection code="&quot;&quot; + stats.getPushes()" type="code"/> + </Property> + </Properties> + </Component> + </SubComponents> + </Container> + <Container class="javax.swing.JPanel" name="jPanelStatisticsChart"> + + <Layout> + <DimensionLayout dim="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <EmptySpace min="0" pref="391" max="32767" attributes="0"/> + </Group> + </DimensionLayout> + <DimensionLayout dim="1"> + <Group type="103" groupAlignment="0" attributes="0"> + <EmptySpace min="0" pref="0" max="32767" attributes="0"/> + </Group> + </DimensionLayout> + </Layout> + </Container> + </SubComponents> + </Container> + </SubComponents> </Form> diff --git a/src/view/StatisticsUI.java b/src/view/StatisticsUI.java @@ -1,8 +1,12 @@ package view; import com.formdev.flatlaf.FlatDarkLaf; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; +import model.Statistics; /** * GUI to display a pie chart and the following statistics: @@ -16,11 +20,18 @@ import javax.swing.UnsupportedLookAndFeelException; * <a href="mailto:michael@michaelneuper.com">michael@michaelneuper.com</a> */ public class StatisticsUI extends javax.swing.JFrame { + + Statistics stats; /** * Creates new form StatisticsUI */ public StatisticsUI() { + try { + this.stats = Statistics.load(); + } catch (IOException e) { + System.err.println(e);; + } initComponents(); } @@ -33,19 +44,130 @@ public class StatisticsUI extends javax.swing.JFrame { // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { + jPanelNorth = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + jPanel1 = new javax.swing.JPanel(); + jPanelStatisticsText = new javax.swing.JPanel(); + jLabelLosses = new javax.swing.JLabel(); + jLabelWins = new javax.swing.JLabel(); + jLabelPushes = new javax.swing.JLabel(); + jLabelWinsAmount = new javax.swing.JLabel(); + jLabelLossesAmount = new javax.swing.JLabel(); + jLabelPushesAmount = new javax.swing.JLabel(); + jPanelStatisticsChart = new javax.swing.JPanel(); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 400, Short.MAX_VALUE) + jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 48)); // NOI18N + jLabel1.setText("Statistics"); + + javax.swing.GroupLayout jPanelNorthLayout = new javax.swing.GroupLayout(jPanelNorth); + jPanelNorth.setLayout(jPanelNorthLayout); + jPanelNorthLayout.setHorizontalGroup( + jPanelNorthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanelNorthLayout.createSequentialGroup() + .addGap(280, 280, 280) + .addComponent(jLabel1) + .addContainerGap(325, Short.MAX_VALUE)) ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 300, Short.MAX_VALUE) + jPanelNorthLayout.setVerticalGroup( + jPanelNorthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanelNorthLayout.createSequentialGroup() + .addGap(17, 17, 17) + .addComponent(jLabel1) + .addContainerGap(21, Short.MAX_VALUE)) ); + getContentPane().add(jPanelNorth, java.awt.BorderLayout.NORTH); + + jLabelLosses.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N + jLabelLosses.setText("Losses:"); + + jLabelWins.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N + jLabelWins.setText("Wins:"); + + jLabelPushes.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N + jLabelPushes.setText("Pushes:"); + + jLabelWinsAmount.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N + jLabelWinsAmount.setText("" + stats.getWins()); + + jLabelLossesAmount.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N + jLabelLossesAmount.setText("" + stats.getLosses()); + + jLabelPushesAmount.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N + jLabelPushesAmount.setText("" + stats.getPushes()); + + javax.swing.GroupLayout jPanelStatisticsTextLayout = new javax.swing.GroupLayout(jPanelStatisticsText); + jPanelStatisticsText.setLayout(jPanelStatisticsTextLayout); + jPanelStatisticsTextLayout.setHorizontalGroup( + jPanelStatisticsTextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelStatisticsTextLayout.createSequentialGroup() + .addGap(69, 69, 69) + .addGroup(jPanelStatisticsTextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabelPushes) + .addComponent(jLabelLosses)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE) + .addGroup(jPanelStatisticsTextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jLabelWinsAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabelLossesAmount, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE) + .addComponent(jLabelPushesAmount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(86, 86, 86)) + .addGroup(jPanelStatisticsTextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanelStatisticsTextLayout.createSequentialGroup() + .addGap(71, 71, 71) + .addComponent(jLabelWins) + .addContainerGap(261, Short.MAX_VALUE))) + ); + jPanelStatisticsTextLayout.setVerticalGroup( + jPanelStatisticsTextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanelStatisticsTextLayout.createSequentialGroup() + .addGap(38, 38, 38) + .addComponent(jLabelWinsAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(27, 27, 27) + .addGroup(jPanelStatisticsTextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabelLosses) + .addComponent(jLabelPushesAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(26, 26, 26) + .addGroup(jPanelStatisticsTextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabelPushes) + .addComponent(jLabelLossesAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(67, Short.MAX_VALUE)) + .addGroup(jPanelStatisticsTextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanelStatisticsTextLayout.createSequentialGroup() + .addGap(43, 43, 43) + .addComponent(jLabelWins) + .addContainerGap(212, Short.MAX_VALUE))) + ); + + javax.swing.GroupLayout jPanelStatisticsChartLayout = new javax.swing.GroupLayout(jPanelStatisticsChart); + jPanelStatisticsChart.setLayout(jPanelStatisticsChartLayout); + jPanelStatisticsChartLayout.setHorizontalGroup( + jPanelStatisticsChartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 391, Short.MAX_VALUE) + ); + jPanelStatisticsChartLayout.setVerticalGroup( + jPanelStatisticsChartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 0, Short.MAX_VALUE) + ); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jPanelStatisticsText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanelStatisticsChart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanelStatisticsChart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanelStatisticsText, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + + getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); + pack(); }// </editor-fold>//GEN-END:initComponents @@ -67,5 +189,16 @@ public class StatisticsUI extends javax.swing.JFrame { } // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabelLosses; + private javax.swing.JLabel jLabelLossesAmount; + private javax.swing.JLabel jLabelPushes; + private javax.swing.JLabel jLabelPushesAmount; + private javax.swing.JLabel jLabelWins; + private javax.swing.JLabel jLabelWinsAmount; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanelNorth; + private javax.swing.JPanel jPanelStatisticsChart; + private javax.swing.JPanel jPanelStatisticsText; // End of variables declaration//GEN-END:variables }