Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.DefaultListModel;
- import javax.swing.JOptionPane;
- /*
- * 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.
- */
- /**
- *
- * @author sused
- */
- public class MojeOkno extends javax.swing.JFrame {
- private DefaultListModel data;
- private DefaultListModel dataVIP;
- /**
- * Creates new form MojeOkno
- */
- public MojeOkno() {
- initComponents();
- data = new DefaultListModel();
- jList1.setModel(data);
- }
- /**
- * 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">
- private void initComponents() {
- buttonGroup1 = new javax.swing.ButtonGroup();
- buttonGroup2 = new javax.swing.ButtonGroup();
- jButton1 = new javax.swing.JButton();
- jTextField1 = new javax.swing.JTextField();
- jLabel1 = new javax.swing.JLabel();
- jButton2 = new javax.swing.JButton();
- jRadioButton1 = new javax.swing.JRadioButton();
- jRadioButton2 = new javax.swing.JRadioButton();
- jRadioButton3 = new javax.swing.JRadioButton();
- jButton3 = new javax.swing.JButton();
- jCheckBox1 = new javax.swing.JCheckBox();
- jCheckBox2 = new javax.swing.JCheckBox();
- jCheckBox3 = new javax.swing.JCheckBox();
- jLabel2 = new javax.swing.JLabel();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- jScrollPane2 = new javax.swing.JScrollPane();
- jList1 = new javax.swing.JList<>();
- jButton4 = new javax.swing.JButton();
- jTextField3 = new javax.swing.JTextField();
- jComboBox1 = new javax.swing.JComboBox<>();
- jButton5 = new javax.swing.JButton();
- jRadioButton4 = new javax.swing.JRadioButton();
- jRadioButton5 = new javax.swing.JRadioButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jButton1.setText("Tlacidlo Ahoj");
- jButton1.setToolTipText("");
- jButton1.setActionCommand("Tlacidlo Ahoj");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jTextField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1ActionPerformed(evt);
- }
- });
- jLabel1.setText("Zadaj meno:");
- jButton2.setText("Pozdrav");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- buttonGroup1.add(jRadioButton1);
- jRadioButton1.setSelected(true);
- jRadioButton1.setText("SK");
- buttonGroup1.add(jRadioButton2);
- jRadioButton2.setText("DE");
- buttonGroup1.add(jRadioButton3);
- jRadioButton3.setText("EN");
- jButton3.setText("Vypočítaj vek");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jCheckBox1.setText("Veľa programujem");
- jCheckBox2.setText("Zdravo sa stravujem");
- jCheckBox3.setText("Chodím za babami");
- jLabel2.setText("Tvoj vek bude:");
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jScrollPane1.setViewportView(jTextArea1);
- jList1.setModel(new javax.swing.AbstractListModel<String>() {
- String[] strings = { "Menu 1", "Menu 2", "Menu 3" };
- public int getSize() { return strings.length; }
- public String getElementAt(int i) { return strings[i]; }
- });
- jScrollPane2.setViewportView(jList1);
- jButton4.setText("Pridaj kamoša");
- jButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton4ActionPerformed(evt);
- }
- });
- jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
- jComboBox1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox1ActionPerformed(evt);
- }
- });
- jButton5.setText("Odober");
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton5ActionPerformed(evt);
- }
- });
- buttonGroup2.add(jRadioButton4);
- jRadioButton4.setText("VIP");
- jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton4ActionPerformed(evt);
- }
- });
- buttonGroup2.add(jRadioButton5);
- jRadioButton5.setSelected(true);
- jRadioButton5.setText("Standard");
- jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton5ActionPerformed(evt);
- }
- });
- 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()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jButton3)
- .addGroup(layout.createSequentialGroup()
- .addGap(10, 10, 10)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton1)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))))
- .addGap(62, 62, 62)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jRadioButton1)
- .addComponent(jRadioButton2)
- .addComponent(jRadioButton3))
- .addGap(54, 54, 54)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addGap(92, 92, 92)
- .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addGap(122, 122, 122)
- .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGap(92, 92, 92)
- .addComponent(jTextField3))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jRadioButton4)
- .addComponent(jRadioButton5))))
- .addComponent(jButton4))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel2)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jCheckBox1)
- .addComponent(jCheckBox2)
- .addComponent(jCheckBox3))
- .addGap(14, 14, 14)))
- .addGap(18, 18, 18)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(33, 63, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton4)
- .addGap(2, 2, 2)
- .addComponent(jRadioButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jRadioButton2))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
- .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.LEADING)
- .addComponent(jButton5)
- .addComponent(jButton2))))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(35, 35, 35)
- .addComponent(jRadioButton3))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jRadioButton4)
- .addGap(18, 18, 18)
- .addComponent(jRadioButton5)))))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jButton3)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jCheckBox1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jCheckBox2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jCheckBox3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jLabel2))))
- .addContainerGap(132, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- JOptionPane.showMessageDialog(this, "Ahoj " + jTextField1.getText());
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- if (jRadioButton1.isSelected())
- JOptionPane.showMessageDialog(this, "Ahoj ");
- if (jRadioButton2.isSelected())
- JOptionPane.showMessageDialog(this, "Halo ");
- if (jRadioButton3.isSelected())
- JOptionPane.showMessageDialog(this, "Hello ");
- }
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int vek = 90;
- if (jCheckBox1.isSelected()) vek -= 10;
- if (jCheckBox2.isSelected()) vek += 10;
- if (jCheckBox3.isSelected()) vek += 20;
- jLabel2.setText("Tvoj vek bude " + vek);
- jTextArea1.setText("Tvoj vek bude " + vek);
- }
- private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- if (jRadioButton4.isSelected()) {
- dataVIP.addElement(jTextField3.getText());
- jList1.setModel(dataVIP);
- }
- if (jRadioButton5.isSelected()); {
- data.addElement(jTextField3.getText());}
- jList1.setModel(data);
- }
- private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int index = jList1.getSelectedIndex();
- if (index >-1) {
- data.removeElementAt(index);
- } else {
- JOptionPane.showMessageDialog(this, "Nevybral si nikoho ");
- }
- }
- private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- jList1.setModel(dataVIP);
- }
- private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- jList1.setModel(data);
- }
- /**
- * @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(MojeOkno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(MojeOkno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(MojeOkno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(MojeOkno.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 MojeOkno().setVisible(true);
- }
- });
- }
Add Comment
Please, Sign In to add comment