public class Calc extends JFrame implements ActionListener { private Button button1; public Calc() { super(); this.setSize(100, 100); this.setVisible(true); this.button1 = new JButton("1"); this.button1.addActionListener(this); this.add(button1); } public static void main(String[] args) { Calc calc = new Calc(); calc.setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getSource() == button1) } }
Control control = new Control(model, view); JLabel label = new JLabel("Guess what color!", JLabel.CENTER); this.add(label, BorderLayout.NORTH); this.add(view, BorderLayout.CENTER); this.add(control, BorderLayout.SOUTH); private JButton reset = new JButton("Reset"); this.view = view; this.add(reset); reset.addActionListener(new ButtonHandler()); String cmd = e.getActionCommand(); if ("Reset".equals(cmd)) { model.reset(); JPanel panel = new JPanel(); for (Piece p : Piece.values()) { PieceButton pb = new PieceButton(p); pb.addActionListener(new ButtonHandler()); panel.add(pb); this.setIcon(new ColorIcon(16, piece.color));
private JComponent createQuickOpenPanel(JList<QuickOpenAction> listPanel, String title, List<File> fileList) { listPanel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listPanel.addListSelectionListener(event -> { if (event.getValueIsAdjusting()) { return; } int selectedIndex = listPanel.getSelectedIndex(); if (selectedIndex < 0) { return; } QuickOpenAction action = listPanel.getModel().getElementAt(selectedIndex); action.actionPerformed(new ActionEvent(listPanel, -1, null)); }); refreshQuickOpenPanel(listPanel, fileList); JScrollPane scrollPane = new JScrollPane(listPanel); scrollPane.getVerticalScrollBar().setUnitIncrement(25); scrollPane.setMinimumSize(new Dimension(100, 80)); // Size fits into screen resolution 1024*768 scrollPane.setPreferredSize(new Dimension(180, 200)); JPanel titlePanel = new JPanel(new BorderLayout()); titlePanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); JLabel titleLabel = new JLabel(title); titleLabel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); titlePanel.add(titleLabel, BorderLayout.NORTH); titlePanel.add(scrollPane, BorderLayout.CENTER); return titlePanel; }
@Override public void actionPerformed(ActionEvent e) { if (focusOwner == null) return; String action = e.getActionCommand(); Action a = focusOwner.getActionMap().get(action); if (a != null) { a.actionPerformed(new ActionEvent(focusOwner, ActionEvent.ACTION_PERFORMED, null)); } } }
@Nullable public static KeyStroke convert(@NotNull ActionEvent event) { String cmd = event.getActionCommand(); int mods = event.getModifiers(); if (cmd != null && cmd.length() > 0) { char ch = cmd.charAt(0); if (ch < ' ') { if (mods == KeyEvent.CTRL_MASK) { return KeyStroke.getKeyStroke(KeyEvent.VK_A + ch - 1, mods); } } else { return KeyStroke.getKeyStroke(new Character(ch), mods); } } return null; }
/** * INTERNAL */ //## AWT ## @Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if ("exit".equals(command)) { shutdown(); } else if ("console".equals(command)) { startBrowser(); } else if ("status".equals(command)) { showWindow(); } else if (startBrowser == e.getSource()) { // for some reason, IKVM ignores setActionCommand startBrowser(); } } //*/
private void setupHandlers() { ripButton.addActionListener(new RipButtonHandler()); ripTextfield.addActionListener(new RipButtonHandler()); ripTextfield.getDocument().addDocumentListener(new DocumentListener() { stopButton.addActionListener(event -> { if (ripper != null) { ripper.stop(); isRipping = false; stopButton.setEnabled(false); statusProgress.setValue(0); statusProgress.setVisible(false); logPanel.setVisible(!logPanel.isVisible()); emptyPanel.setVisible(!logPanel.isVisible()); JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("Are you sure?"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }); configLogLevelCombobox.addActionListener(arg0 -> { String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString(); setLogLevel(level); }); configSelectLangComboBox.addActionListener(arg0 -> { String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString(); rb = Utils.getResourceBundle(level); changeLocale();
this.setLayout(borderLayoutPreferences); final JButton buttonCheckIp = new JButton("Check your IP"); buttonCheckIp.addActionListener(new ActionCheckIP()); buttonCheckIp.setToolTipText( "<html><b>Verify what public IP address is used by jSQL</b><br>" + "Usually it's your own public IP if you don't use a proxy. If you use a proxy<br>" if (actionEvent.getSource() != this.checkboxProcessCsrf) { this.checkboxProcessCsrf.setSelected(!this.checkboxProcessCsrf.isSelected()); }); JPanel panelTamperingPreferences = new JPanel(); panelTamperingPreferences.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); panelTampering.setBorder(BorderFactory.createEmptyBorder(10, 15, 0, 15)); panelTampering.add(new JLabel("<html><b>Tampering</b> / SQL expression alteration to bypass Web Application Firewall</html>"), BorderLayout.NORTH); panelTampering.add(panelTamperingPreferences, BorderLayout.CENTER); if (actionEvent.getSource() != this.checkboxIsCheckingAllParam) { this.checkboxIsCheckingAllParam.setSelected(!this.checkboxIsCheckingAllParam.isSelected());
String actionCommand = e.getActionCommand(); System.out.println("Key Binding: " + actionCommand); ArrowTest mainPanel = new ArrowTest(); JFrame frame = new JFrame("ArrowTest"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true);
JButton enter = new JButton("Enter"); JLabel conceptLabel = new JLabel("Concept: "); setSize(350, 180); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pane = new JPanel(); pane.add(conceptLabel); pane.add(concept); pane.add(enter); add(pane); enter.addActionListener(listener); setVisible(true); if(event.getSource() == enter){ conceptLabel.setText(concept.getText());
editorComponent = new JButton(); editorComponent.setBackground(Color.white); editorComponent.setBorderPainted(false); editorComponent.setContentAreaFilled( false ); popup.setLocation(p.x, p.y + editorComponent.getSize().height); popup.show(); fireEditingStopped(); editorComponent.setText( currentText ); return editorComponent; textArea.getInputMap().put(keyStroke, "none"); JScrollPane scrollPane = new JScrollPane( textArea ); getContentPane().add( scrollPane ); JButton cancel = new JButton("Cancel"); cancel.addActionListener( this ); JButton ok = new JButton("Ok"); ok.setPreferredSize( cancel.getPreferredSize() ); ok.addActionListener( this ); if ("Ok".equals( e.getActionCommand() ) ) table.getColumnModel().getColumn(1).setCellEditor( popupEditor );
JFrame frame = new JFrame("This is a Frame"); button = new JButton("Button"); button.addActionListener(new MyAction()); frame.add(button); frame.setSize(400, 400); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String text = (String)e.getActionCommand(); if (text.equals("Button2")){ button.setText("I am Sectona"); button.setText("Click Me");
getEngineByExtension("js"); ui = new JPanel(new BorderLayout(2, 2)); controls = new ArrayList<JButton>(); io.setHorizontalAlignment(SwingConstants.TRAILING); io.setFocusable(false); text.add(io); JButton equals = new JButton("="); JButton b = new JButton(text); String command = ae.getActionCommand(); if (command.equals("C")) { io.setText(""); String s = button.getText(); if (text.endsWith(s) || (s.equals("=") if (b != null) { b.requestFocusInWindow(); b.doClick();
import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.GroupLayout;import javax.swing.GroupLayout.Alignment;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.LayoutStyle.ComponentPlacement;import javax.swing.border.EmptyBorder;import javax.swing.filechooser.FileFilter;import javax.swing.filechooser.FileNameExtensionFilter;public class ConfigureDialog extends JDialog implements ActionListener{private static final long serialVersionUID=1L;private final JPanel contentPanel=new JPanel();private JTextField driverPathTextField;private JLabel lblDriverPath;private JButton btnBrowse;public static void main(String[]args){try{ConfigureDialog dialog=new ConfigureDialog(new JFrame());dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);dialog.setVisible(true);}catch(Exception e){e.printStackTrace();}} public ConfigureDialog(JFrame parent){super(parent,"",true);if(parent!=null){Dimension parentSize=parent.getSize();Point p=parent.getLocation();setLocation(p.x+parentSize.width+100,p.y+parentSize.height/1);} setBounds(100,100,479,141);getContentPane().setLayout(new BorderLayout());contentPanel.setBorder(new EmptyBorder(5,5,5,5));getContentPane().add(contentPanel,BorderLayout.CENTER);{lblDriverPath=new JLabel("Driver Path : ");} {driverPathTextField=new JTextField(System.getProperty("web.ie.driver"));driverPathTextField.setColumns(10);} btnBrowse=new JButton("Browse");GroupLayout gl_contentPanel=new GroupLayout(contentPanel);gl_contentPanel.setHorizontalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addContainerGap().addComponent(lblDriverPath).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(btnBrowse).addComponent(driverPathTextField,GroupLayout.DEFAULT_SIZE,207,Short.MAX_VALUE)).addContainerGap()));gl_contentPanel.setVerticalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(5).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(driverPathTextField,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE).addComponent(lblDriverPath)).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(btnBrowse).addContainerGap(21,Short.MAX_VALUE)));contentPanel.setLayout(gl_contentPanel);{JPanel buttonPane=new JPanel();buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));getContentPane().add(buttonPane,BorderLayout.SOUTH);{JButton okButton=new JButton("OK");okButton.setActionCommand("OK");okButton.addActionListener(this);buttonPane.add(okButton);getRootPane().setDefaultButton(okButton);} {JButton cancelButton=new JButton("Cancel");cancelButton.setActionCommand("Cancel");cancelButton.addActionListener(this);buttonPane.add(cancelButton);}} btnBrowse.addActionListener(this);}@Override public void actionPerformed(ActionEvent e){if("Cancel".contains(e.getActionCommand())){dispose();}else if("Browse".contains(e.getActionCommand())){JFileChooser fileopen=new JFileChooser();FileFilter filter=new FileNameExtensionFilter("exe file","exe");fileopen.addChoosableFileFilter(filter);fileopen.setAcceptAllFileFilterUsed(false);fileopen.setFileFilter(filter);fileopen.setFileSelectionMode(JFileChooser.FILES_ONLY);int ret=fileopen.showOpenDialog(this);if(ret==JFileChooser.APPROVE_OPTION){File file=fileopen.getSelectedFile();System.out.println(file);driverPathTextField.setText(file.getPath());}}else if("OK".contains(e.getActionCommand())){System.setProperty("web.ie.driver",driverPathTextField.getText());dispose();}}}
public void start() throws Exception { mainFrame=new JFrame("Chat demo"); mainFrame.setPreferredSize(new Dimension(600,600)); mainFrame.setBackground(Color.white); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { leaveButton=new JButton("Leave"); leaveButton.setPreferredSize(new Dimension(150, 30)); buttons.add(leaveButton); leaveButton.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { stomp_client.send(USER_LEFT, USER, username); txtField.setToolTipText("type and then press enter to send"); txtField.addActionListener(e -> { String cmd=e.getActionCommand(); if(cmd != null && !cmd.isEmpty()) { send(txtField.getText());
JButton button1; public static void main(String[] args) { JFrame calcFrame = new JFrame(); calcFrame.setSize(100, 100); calcFrame.setVisible(true); button1 = new JButton("1"); button1.addActionListener(this); calcFrame.add(button1); } public void actionPerformed(ActionEvent e) { if(e.getSource() == button1) }
String[] data = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}; JPanel panel = new JPanel(new GridLayout(0, 1)); MyButtonGroup myBtnGrp = new MyButtonGroup(); myBtnGrp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Action Command is: " + e.getActionCommand()); radioBtn.setActionCommand(text); myBtnGrp.add(radioBtn); panel.add(radioBtn); JFrame frame = new JFrame("MyButtonGroupTest"); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); for (int i = 0; i < letters.length; i++) { buttons[i] = new JButton(letters[i]); buttons[i].addActionListener(this); add(buttons[i]); add(text); pack(); setVisible(true); text.append(event.getActionCommand());
JFreeChart chart = createChart(dataset); final JButton run = new JButton(STOP); run.addActionListener(new ActionListener() { String cmd = e.getActionCommand(); if (STOP.equals(cmd)) { timer.stop(); run.setText(START); } else { timer.start(); run.setText(STOP); JPanel btnPanel = new JPanel(new FlowLayout()); btnPanel.add(run); btnPanel.add(combo); this.add(btnPanel, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); btn = new JButton("Open the other JFrame!"); btn.addActionListener(this); btn.setActionCommand("Open"); add(btn); pack(); public void actionPerformed(ActionEvent e) String cmd = e.getActionCommand(); dispose(); new AnotherJFrame(); public void run() new StartupWindow().setVisible(true);