Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class JFrame extends javax.swing.JFrame {
- int sum;
- int difference;
- int multiplication;
- int quotient;
- int sucet[] = sucet();
- int rozdiel[] = rozdiel();
- int sucin[] = sucin();
- int podiel[] = podiel();
- String sum_s;
- String difference_s;
- String multiplication_s;
- String quotient_s;
- int accepted = 0;
- public JFrame() {
- initComponents();
- }
- protected int[] sucet() {
- int x = (int) (Math.random()* 20);
- int y = (int) (Math.random()* 20);
- return new int[] {x, y};
- }
- protected int[] rozdiel() {
- int x = (int) (Math.random()* 20);
- int y = (int) (Math.random()* 20);
- return new int[] {x, y};
- }
- protected int[] sucin() {
- int x = (int) (Math.random()* 20);
- int y = (int) (Math.random()* 20);
- return new int[] {x, y};
- }
- protected int[] podiel() {
- int x = (int) (Math.random()* 20);
- int y = (int) (Math.random()* 20);
- return new int[] {x, y};
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jTextField2 = new javax.swing.JTextField();
- jTextField3 = new javax.swing.JTextField();
- jTextField4 = new javax.swing.JTextField();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- jLabel5 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jButton1.setText("Daj príklady");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Skontroluj");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jLabel1.setText("Príklad 1");
- jLabel2.setText("Príklad 2");
- jLabel3.setText("Príklad 3");
- jLabel4.setText("Priklad 4");
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jScrollPane1.setViewportView(jTextArea1);
- jLabel5.setText("Hodnotenie");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jButton1)
- .addGap(41, 41, 41)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(jLabel4)
- .addComponent(jLabel3)
- .addComponent(jLabel2))
- .addGap(77, 77, 77)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(jButton2))
- .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addComponent(jScrollPane1)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel5)
- .addGap(0, 0, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2)
- .addComponent(jLabel1)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel4)
- .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
- .addComponent(jLabel5))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- sum = sucet[0] + sucet[1];
- difference = rozdiel[0] - rozdiel[1];
- multiplication = sucin[0] * sucin[1];
- quotient = podiel[0] / podiel[1];
- jLabel1.setText("" + Integer.toString(sucet[0]) + " + " + Integer.toString(sucet[1]) + " =");
- jLabel2.setText("" + Integer.toString(rozdiel[0]) + " - " + Integer.toString(rozdiel[1]) + " =");
- jLabel3.setText("" + Integer.toString(sucin[0]) + " * " + Integer.toString(sucin[1]) + " =");
- jLabel4.setText("" + Integer.toString(podiel[0]) + " / " + Integer.toString(podiel[1]) + " =");
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- int sucet_i = Integer.parseInt(jTextField1.getText());
- int rozdiel_i = Integer.parseInt(jTextField2.getText());
- int sucin_i = Integer.parseInt(jTextField3.getText());
- int podiel_i = Integer.parseInt(jTextField4.getText());
- if (sum == sucet_i) {
- sum_s = "" + Integer.toString(sucet[0]) + " + " + Integer.toString(sucet[1]) + " = " + Integer.toString(sum) + " správne";
- accepted++;
- } else {
- sum_s = "" + Integer.toString(sucet[0]) + " + " + Integer.toString(sucet[1]) + " = " + Integer.toString(sucet_i) + " nesprávne (výsledok je " + Integer.toString(sum) + ").";
- }
- if (difference == rozdiel_i) {
- difference_s = "" + Integer.toString(rozdiel[0]) + " - " + Integer.toString(rozdiel[1]) + " = " + Integer.toString(difference) + " správne";
- accepted++;
- } else {
- difference_s = "" + Integer.toString(rozdiel[0]) + " - " + Integer.toString(rozdiel[1]) + " = " + Integer.toString(rozdiel_i) + " nesprávne (výsledok je " + Integer.toString(difference) + ").";
- }
- if (multiplication == sucin_i) {
- multiplication_s = "" + Integer.toString(sucin[0]) + " * " + Integer.toString(sucin[1]) + " = " + Integer.toString(difference) + " správne";
- accepted++;
- } else {
- multiplication_s = "" + Integer.toString(sucin[0]) + " * " + Integer.toString(sucin[1]) + " = " + Integer.toString(sucin_i) + " nesprávne (výsledok je " + Integer.toString(multiplication) + ").";
- }
- if (quotient == podiel_i) {
- quotient_s = "" + Integer.toString(podiel[0]) + " / " + Integer.toString(podiel[1]) + " = " + Integer.toString(quotient) + " správne";
- accepted++;
- } else {
- quotient_s = "" + Integer.toString(podiel[0]) + " / " + Integer.toString(podiel[1]) + " = " + Integer.toString(podiel_i) + " nesprávne (výsledok je " + Integer.toString(quotient) + ").";
- }
- jTextArea1.setText(sum_s + "\n" + difference_s + "\n" + multiplication_s + "\n" + quotient_s);
- jLabel5.setText("Počet správnych odpovedí: " + accepted);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new JFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextArea jTextArea1;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField2;
- private javax.swing.JTextField jTextField3;
- private javax.swing.JTextField jTextField4;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement