List of usage examples for javax.swing JButton addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:DatabaseTest.java
public DatabaseTest() { super("Database Test Frame"); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(350, 200);/*from w ww. j a va 2 s .co m*/ qtm = new QueryTableModel(); JTable table = new JTable(qtm); JScrollPane scrollpane = new JScrollPane(table); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(3, 2)); p1.add(new JLabel("Enter the Host URL: ")); p1.add(hostField = new JTextField()); p1.add(new JLabel("Enter your query: ")); p1.add(queryField = new JTextField()); p1.add(new JLabel("Click here to send: ")); JButton jb = new JButton("Search"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { qtm.setHostURL(hostField.getText().trim()); qtm.setQuery(queryField.getText().trim()); } }); p1.add(jb); getContentPane().add(p1, BorderLayout.NORTH); getContentPane().add(scrollpane, BorderLayout.CENTER); }
From source file:org.jfree.chart.demo.Graph.java
/** * Constructs a new demonstration application. * * @param title the frame title./*from w ww . j a v a 2 s . c om*/ */ public Graph(final String title) { super(title); this.series = new TimeSeries("Random Data", Millisecond.class); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JButton button = new JButton("Add New Data Item"); button.setActionCommand("ADD_DATA"); button.addActionListener(this); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); // content.add(button, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:com.thoughtworks.go.agent.bootstrapper.osx.MacPreferencesPane.java
public MacPreferencesPane(final AgentMacWindow agentMacWindow) { super();/*from w ww . ja v a 2 s. c o m*/ getContentPane().setLayout(new BorderLayout(10, 10)); JLabel prefsText = new JLabel("Go Server Hostname or IP"); serverTextField = new JTextField(""); serverTextField.setColumns(15); serverTextField.selectAll(); JPanel textPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10)); textPanel.add(prefsText); textPanel.add(serverTextField); getContentPane().add(textPanel, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10)); JButton okButton = new JButton("OK"); buttonPanel.add(okButton); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent newEvent) { String newHost = serverTextField.getText(); if (!originalHost.equals(newHost)) { LOG.info("Server changed to " + newHost); agentMacWindow.setHost(newHost); } else { LOG.info("Server is still " + originalHost); } setVisible(false); } }); getContentPane().add(buttonPanel, BorderLayout.SOUTH); setSize(getPreferredSize()); setLocation(20, 40); setResizable(false); }
From source file:MiniBrowser.java
public MiniBrowser() { setSize(640, 480);// w w w .j a va 2s. c o m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel buttonPanel = new JPanel(); backButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { actionBack(); } }); backButton.setEnabled(false); buttonPanel.add(backButton); forwardButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { actionForward(); } }); forwardButton.setEnabled(false); buttonPanel.add(forwardButton); locationTextField.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { actionGo(); } } }); buttonPanel.add(locationTextField); JButton goButton = new JButton("GO"); goButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { actionGo(); } }); buttonPanel.add(goButton); displayEditorPane.setContentType("text/html"); displayEditorPane.setEditable(false); displayEditorPane.addHyperlinkListener(this); getContentPane().setLayout(new BorderLayout()); getContentPane().add(buttonPanel, BorderLayout.NORTH); getContentPane().add(new JScrollPane(displayEditorPane), BorderLayout.CENTER); }
From source file:AlgorithmAnimation.java
public AnimationFrame() { ArrayComponent comp = new ArrayComponent(); add(comp, BorderLayout.CENTER); final Sorter sorter = new Sorter(comp); JButton runButton = new JButton("Run"); runButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { sorter.setRun();//from ww w. j a v a 2 s . com } }); JButton stepButton = new JButton("Step"); stepButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { sorter.setStep(); } }); JPanel buttons = new JPanel(); buttons.add(runButton); buttons.add(stepButton); add(buttons, BorderLayout.NORTH); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); Thread t = new Thread(sorter); t.start(); }
From source file:SerialTransferTest.java
public SerialTransferFrame() { setTitle("SerialTransferTest"); chooser = new JColorChooser(); add(chooser, BorderLayout.CENTER); JPanel panel = new JPanel(); JButton copyButton = new JButton("Copy"); panel.add(copyButton);// w w w .j a v a 2 s .c o m copyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { copy(); } }); JButton pasteButton = new JButton("Paste"); panel.add(pasteButton); pasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { paste(); } }); add(panel, BorderLayout.SOUTH); pack(); }
From source file:PersistentFrameTest.java
public void init() { frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("PersistentFrameTest"); frame.setSize(400, 200);/* w w w .jav a 2 s .c om*/ JButton loadButton = new JButton("Load"); frame.add(loadButton); loadButton.addActionListener(EventHandler.create(ActionListener.class, this, "load")); JButton saveButton = new JButton("Save"); frame.add(saveButton); saveButton.addActionListener(EventHandler.create(ActionListener.class, this, "save")); frame.setVisible(true); }
From source file:KeyEventDemo.java
public KeyEventDemo() { super(new BorderLayout()); JButton button = new JButton("Clear"); button.addActionListener(this); typingArea = new JTextField(20); typingArea.addKeyListener(this); //Uncomment this if you wish to turn off focus //traversal. The focus subsystem consumes //focus traversal keys, such as Tab and Shift Tab. //If you uncomment the following line of code, this //disables focus traversal and the Tab events will //become available to the key event listener. //typingArea.setFocusTraversalKeysEnabled(false); displayArea = new JTextArea(); displayArea.setEditable(false);/* w w w . j a va2 s.co m*/ JScrollPane scrollPane = new JScrollPane(displayArea); scrollPane.setPreferredSize(new Dimension(375, 125)); add(typingArea, BorderLayout.PAGE_START); add(scrollPane, BorderLayout.CENTER); add(button, BorderLayout.PAGE_END); }
From source file:SynthApplication.java
public Component createComponents() { JButton button = new JButton("I'm a Swing button!"); button.setMnemonic(KeyEvent.VK_I); button.addActionListener(this); label.setLabelFor(button);// www. j a v a2 s . c o m /* * An easy way to put space between a top-level container * and its contents is to put the contents in a JPanel * that has an "empty" border. */ JPanel pane = new JPanel(new GridLayout(0, 1)); pane.add(button); pane.add(label); pane.setBorder(BorderFactory.createEmptyBorder(30, //top 30, //left 10, //bottom 30) //right ); return pane; }
From source file:components.DynamicTreeDemo.java
public DynamicTreeDemo() { super(new BorderLayout()); //Create the components. treePanel = new DynamicTree(); populateTree(treePanel);//from w w w.j a v a 2 s.c o m JButton addButton = new JButton("Add"); addButton.setActionCommand(ADD_COMMAND); addButton.addActionListener(this); JButton removeButton = new JButton("Remove"); removeButton.setActionCommand(REMOVE_COMMAND); removeButton.addActionListener(this); JButton clearButton = new JButton("Clear"); clearButton.setActionCommand(CLEAR_COMMAND); clearButton.addActionListener(this); //Lay everything out. treePanel.setPreferredSize(new Dimension(300, 150)); add(treePanel, BorderLayout.CENTER); JPanel panel = new JPanel(new GridLayout(0, 3)); panel.add(addButton); panel.add(removeButton); panel.add(clearButton); add(panel, BorderLayout.SOUTH); }