package elte.java2_utikalauz5.beans; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.beans.*; /** Ez az osztály az eseménykezelést demonstrálja. @link.forrásfájl {@docRoot}/../data/beans/src SmileyEventDemo.java @link.letöltés {@docRoot}/../data/beans SmileyEventDemo.jar @since Java 2 Útikalauz programozóknak */ public class SmileyEventDemo extends JFrame { /** Verziószám */ private final static long serialVersionUID = 15L; private JTextField jTextField; private SmileyBean smileyBean; private SmileyChangedLabel smileyChangedLabel; public SmileyEventDemo() { smileyBean = new SmileyBean(); jTextField = new JTextField(); smileyChangedLabel = new SmileyChangedLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); smileyBean.addSmileyListener(smileyChangedLabel); getContentPane().add(smileyBean, BorderLayout.WEST); jTextField.setText(""); jTextField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { smileyBean.setFunPercent(Integer.parseInt(jTextField.getText())); } catch (PropertyVetoException ev) { ev.printStackTrace(); } catch (NumberFormatException ev) { jTextField.setText(Integer.toString(smileyBean.getFunPercent())); } } }); getContentPane().add(jTextField, BorderLayout.SOUTH); smileyChangedLabel.setText("..."); getContentPane().add(smileyChangedLabel, BorderLayout.CENTER); pack(); } public static void main(String args[]) { EventQueue.invokeLater(new Runnable() { public void run() { new SmileyEventDemo().setVisible(true); } }); } }