Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ManyToOne.gui;
- import java.awt.BorderLayout;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.List;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JDialog;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import javax.swing.SwingConstants;
- import javax.swing.border.EmptyBorder;
- import ManyToOne.crud.RadnikCrud;
- import ManyToOne.crud.RadnoMestoCrud;
- import ManyToOne.entities.Radnik;
- import ManyToOne.entities.RadnoMesto;
- public class DijalogUnosRadnika extends JDialog {
- private final JPanel contentPanel = new JPanel();
- private JTextField textFieldMBRRadnika;
- private JTextField textFieldImeRadnika;
- private JTextField textFieldPrezimeRadnika;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- try {
- DijalogUnosRadnika dialog = new DijalogUnosRadnika();
- dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- dialog.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Create the dialog.
- */
- @SuppressWarnings({ "rawtypes", "unchecked", "unused" })
- public DijalogUnosRadnika() {
- setBounds(100, 100, 450, 300);
- getContentPane().setLayout(new BorderLayout());
- contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
- getContentPane().add(contentPanel, BorderLayout.CENTER);
- contentPanel.setLayout(null);
- textFieldMBRRadnika = new JTextField();
- textFieldMBRRadnika.setToolTipText("MBR radnika");
- textFieldMBRRadnika.setBounds(120, 25, 180, 20);
- contentPanel.add(textFieldMBRRadnika);
- textFieldMBRRadnika.setColumns(10);
- JLabel lblMbrRadnika = new JLabel("MBR radnika");
- lblMbrRadnika.setHorizontalAlignment(SwingConstants.RIGHT);
- lblMbrRadnika.setBounds(20, 28, 90, 14);
- contentPanel.add(lblMbrRadnika);
- JLabel lblImeRadnika = new JLabel("Ime radnika");
- lblImeRadnika.setHorizontalAlignment(SwingConstants.RIGHT);
- lblImeRadnika.setBounds(20, 68, 90, 14);
- contentPanel.add(lblImeRadnika);
- JLabel lblPrezimeRadnika = new JLabel("Prezime radnika");
- lblPrezimeRadnika.setHorizontalAlignment(SwingConstants.RIGHT);
- lblPrezimeRadnika.setBounds(20, 108, 90, 14);
- contentPanel.add(lblPrezimeRadnika);
- textFieldImeRadnika = new JTextField();
- textFieldImeRadnika.setBounds(120, 65, 180, 20);
- contentPanel.add(textFieldImeRadnika);
- textFieldImeRadnika.setColumns(10);
- textFieldPrezimeRadnika = new JTextField();
- textFieldPrezimeRadnika.setColumns(10);
- textFieldPrezimeRadnika.setBounds(120, 105, 180, 20);
- contentPanel.add(textFieldPrezimeRadnika);
- JComboBox<RadnoMesto> comboBoxRadnoMesto = new JComboBox<RadnoMesto>();
- comboBoxRadnoMesto.setBounds(120, 147, 180, 20);
- RadnoMestoCrud rmc = new RadnoMestoCrud();
- List<RadnoMesto> radnaMesta = rmc.getLista();
- for(RadnoMesto rm : radnaMesta)
- comboBoxRadnoMesto.addItem(rm);
- contentPanel.add(comboBoxRadnoMesto);
- JLabel lblRadnoMesto = new JLabel("Radno mesto");
- lblRadnoMesto.setHorizontalAlignment(SwingConstants.RIGHT);
- lblRadnoMesto.setBounds(30, 150, 80, 14);
- contentPanel.add(lblRadnoMesto);
- {
- JPanel buttonPane = new JPanel();
- buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
- getContentPane().add(buttonPane, BorderLayout.SOUTH);
- {
- JButton okButton = new JButton("OK");
- okButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int mbr = Integer.parseInt(textFieldMBRRadnika.getText());
- String ime = textFieldImeRadnika.getText();
- String prezime = textFieldPrezimeRadnika.getText();
- RadnoMesto rm = (RadnoMesto) comboBoxRadnoMesto.getSelectedItem();
- Radnik r = new Radnik(mbr, ime, prezime);
- r.setRadnoMesto(rm);
- RadnikCrud rc = new RadnikCrud();
- if (rc.insertRadnik(r)) {
- JOptionPane.showMessageDialog(DijalogUnosRadnika.this, "Uspešan unos radnika");
- textFieldMBRRadnika.setText("");
- textFieldImeRadnika.setText("");
- textFieldPrezimeRadnika.setText("");
- } else {
- JOptionPane.showMessageDialog(DijalogUnosRadnika.this, "Neuspešan unos radnika");
- textFieldMBRRadnika.setText("");
- textFieldImeRadnika.setText("");
- textFieldPrezimeRadnika.setText("");
- }
- }
- });
- okButton.setActionCommand("OK");
- buttonPane.add(okButton);
- getRootPane().setDefaultButton(okButton);
- }
- {
- JButton cancelButton = new JButton("Cancel");
- cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- dispose();
- }
- });
- cancelButton.setActionCommand("Cancel");
- buttonPane.add(cancelButton);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement