List of usage examples for java.awt.event ActionListener ActionListener
ActionListener
From source file:Main.java
public Main() throws HeadlessException { setSize(300, 300);/* ww w .j av a 2 s . c om*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER)); JButton disable = new JButton("DISABLE"); disable.setToolTipText("disabled."); disable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ToolTipManager.sharedInstance().setEnabled(false); } }); JButton enable = new JButton("ENABLE"); enable.setToolTipText("enabled."); enable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ToolTipManager.sharedInstance().setEnabled(true); } }); getContentPane().add(enable); getContentPane().add(disable); }
From source file:Test.java
public Test() { this.setBounds(100, 100, 200, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setType(Type.UTILITY); this.setLayout(new FlowLayout()); JButton exitButton = new JButton("Exit"); this.add(exitButton); exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0);//from www .j a v a 2 s .co m } }); }
From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel pnl = new JPanel(); pnl.add(new JLabel("Enter text")); final JTextField txtText; txtText = new JTextField("to be removed"); pnl.add(txtText);//from w w w . ja v a 2s . c o m JButton btnRemove = new JButton("Remove"); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { String text = txtText.getText(); text = Normalizer.normalize(text, Normalizer.Form.NFD); txtText.setText(text.replaceAll("[^\\p{ASCII}]", "")); } }; btnRemove.addActionListener(al); pnl.add(btnRemove); add(pnl); pack(); setVisible(true); }
From source file:Main.java
public Main() { textField.setText("Hit Enter to Add Text to Text Pane"); getContentPane().add(textField, BorderLayout.NORTH); textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Document doc = textPane.getDocument(); doc.insertString(doc.getLength(), " " + textField.getText(), null); textField.setText("");//clear Dimension d = textPane.getPreferredSize(); Rectangle r = textPane.modelToView(textPane.getDocument().getLength()); d.height = r.y + r.height; textPane.setPreferredSize(d); getContentPane().validate(); } catch (Exception e2) { }/* w w w .j a v a2s.co m*/ } }); JPanel south = new JPanel(); textPane = new JTextPane(); textPane.setText("Some \ntext"); textPane.setEditable(false); textPane.setPreferredSize(new Dimension(120, 23)); south.add(textPane); getContentPane().add(south, BorderLayout.SOUTH); }
From source file:Main.java
public Main() { popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed."); }//from w ww . j av a2 s. co m }; JMenuItem item; popup.add(item = new JMenuItem(new ImageIcon("left.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.addSeparator(); popup.add(item = new JMenuItem("Settings . . .")); item.addActionListener(menuListener); popup.setLabel("Justification"); popup.setBorder(new BevelBorder(BevelBorder.RAISED)); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }
From source file:Main.java
public Main() { popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed."); }/*from w ww . j a v a 2s . c om*/ }; JMenuItem item; popup.add(item = new JMenuItem("Left", new ImageIcon("left.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.addSeparator(); popup.add(item = new JMenuItem("Settings . . .")); item.addActionListener(menuListener); popup.setLabel("Justification"); popup.setBorder(new BevelBorder(BevelBorder.RAISED)); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }
From source file:Main.java
public Main() { popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed."); }//from w w w . j a v a 2s . c om }; JMenuItem item; popup.add(item = new JMenuItem("Left")); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.addSeparator(); popup.add(item = new JMenuItem("Settings . . .")); item.addActionListener(menuListener); popup.setLabel("Justification"); popup.setBorder(new BevelBorder(BevelBorder.RAISED)); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }
From source file:Main.java
public TestPane() { Timer timer = new Timer(40, new ActionListener() { @Override//from w ww .jav a2 s. c o m public void actionPerformed(ActionEvent e) { x += xDelta; if (x + (radius * 2) > getWidth()) { x = getWidth() - (radius * 2); xDelta *= -1; } else if (x < 0) { x = 0; xDelta *= -1; } repaint(); } }); timer.start(); }
From source file:MainClass.java
public MainClass() { popup = new JPopupMenu(); ActionListener menuListener = new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed."); }/*w ww . ja va 2 s . co m*/ }; JMenuItem item; popup.add(item = new JMenuItem("Left", new ImageIcon("left.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif"))); item.setHorizontalTextPosition(JMenuItem.RIGHT); item.addActionListener(menuListener); popup.addSeparator(); popup.add(item = new JMenuItem("Settings . . .")); item.addActionListener(menuListener); popup.setLabel("Justification"); popup.setBorder(new BevelBorder(BevelBorder.RAISED)); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }
From source file:RemoveAccents.java
public RemoveAccents() { setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel pnl = new JPanel(); pnl.add(new JLabel("Enter text")); final JTextField txtText; txtText = new JTextField("to be removed"); pnl.add(txtText);/*from w ww. j a va 2s . c o m*/ JButton btnRemove = new JButton("Remove"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { String text = txtText.getText(); text = Normalizer.normalize(text, Normalizer.Form.NFD); txtText.setText(text.replaceAll("[^\\p{ASCII}]", "")); } }; btnRemove.addActionListener(al); pnl.add(btnRemove); getContentPane().add(pnl); pack(); setVisible(true); }