sk.upjs.ics.paz1c.debilnicek.UlohaForm.java Source code

Java tutorial

Introduction

Here is the source code for sk.upjs.ics.paz1c.debilnicek.UlohaForm.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sk.upjs.ics.paz1c.debilnicek;

import java.awt.Frame;
import org.springframework.dao.support.DaoSupport;

/**
 *
 * @author student
 */
public class UlohaForm extends javax.swing.JDialog {
    private UlohaDao ulohaDao = UlohaDaoFactory.INSTANCE.getUlohaDao();

    public UlohaForm(Frame parent, Uloha uloha) {
        super(parent, /* modal */ true);
        initComponents();

        //----
        this.uloha = uloha;

        nazovTextField.setText(uloha.getPopis());
        kategoriaComboBox.setSelectedItem(uloha.getKategoria());

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nazovTextField = new javax.swing.JTextField();
        nazovLabel = new javax.swing.JLabel();
        kategoriaComboBox = new javax.swing.JComboBox<>();
        kategoriaLabel = new javax.swing.JLabel();
        okButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        nazovLabel.setText("Nzov:");

        kategoriaComboBox.setModel(new KategoriaComboBoxModel());

        kategoriaLabel.setText("Kategria:");

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(
                                okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(nazovLabel).addComponent(kategoriaLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(kategoriaComboBox, 0, 329, Short.MAX_VALUE)
                                        .addComponent(nazovTextField))))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(nazovTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(nazovLabel))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(kategoriaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(kategoriaLabel))
                        .addGap(18, 18, 18).addComponent(okButton)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        uloha.setPopis(nazovTextField.getText());
        uloha.setKategoria((Kategoria) kategoriaComboBox.getSelectedItem());

        //------ uloz

        ulohaDao.saveOrUpdate(uloha);

        // zatvor okno
        dispose();
    }//GEN-LAST:event_okButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox<Kategoria> kategoriaComboBox;
    private javax.swing.JLabel kategoriaLabel;
    private javax.swing.JLabel nazovLabel;
    private javax.swing.JTextField nazovTextField;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables

    private Uloha uloha;
}