List of usage examples for javax.swing JButton addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:edu.harvard.mcz.imagecapture.VerbatimToTranscribeDialog.java
/** * Create the dialog./* w w w . jav a 2s.c om*/ */ public VerbatimToTranscribeDialog() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); setBounds(100, 100, 726, 557); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new BorderLayout(0, 0)); { table = new JTable(); SpecimenLifeCycle sls = new SpecimenLifeCycle(); GenusSpeciesCountTableModel model = new GenusSpeciesCountTableModel(sls.countSpecimensForVerbatim()); table.setModel(model); table.setDefaultRenderer(GenusSpeciesCount.class, new ButtonRenderer("Transcribe")); table.setDefaultEditor(GenusSpeciesCount.class, new ButtonEditor(ButtonEditor.OPEN_SPECIMEN_VERBATIM, this)); contentPanel.add(table, BorderLayout.CENTER); } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton cancelButton = new JButton("Close"); cancelButton.setActionCommand("Close"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); buttonPane.add(cancelButton); } } }
From source file:org.sunzoft.sunstock.StockMain.java
protected void initGUI() { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1024, 600);//from w ww . j a v a 2 s. c om frame.setLocationRelativeTo(null); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // Container contentPane = frame.getContentPane(); contentPane.setLayout(new BorderLayout(0, 0)); JFreeChart chart = createChart(); // 6:chartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseZoomable(true); contentPane.add(chartPanel, BorderLayout.CENTER); JPanel pCtrl = new JPanel(); if (profits.size() > 0) { startInput.setText(profits.get(0).date); endInput.setText(profits.get(profits.size() - 1).date); } else { startInput.setText("20100101"); endInput.setText("20100101"); } pCtrl.add(new JLabel("")); pCtrl.add(startInput); pCtrl.add(new JLabel("")); pCtrl.add(endInput); JButton confirm = new JButton(""); confirm.addActionListener(StockMain.this); pCtrl.add(confirm); contentPane.add(pCtrl, BorderLayout.NORTH); JPanel pStatus = new JPanel(); statusLabel = new JLabel(getStatusText()); pStatus.add(statusLabel); contentPane.add(pStatus, BorderLayout.SOUTH); frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH); frame.setVisible(true); //dataSource.close(); } }); }
From source file:edu.uci.ics.jung.samples.GraphFromGraphMLDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features./*from w w w . j av a 2s . co m*/ * @throws SAXException * @throws ParserConfigurationException * @throws IOException * */ public GraphFromGraphMLDemo(String filename) throws ParserConfigurationException, SAXException, IOException { Factory<Number> vertexFactory = new Factory<Number>() { int n = 0; public Number create() { return n++; } }; Factory<Number> edgeFactory = new Factory<Number>() { int n = 0; public Number create() { return n++; } }; GraphMLReader<Graph<Number, Number>, Number, Number> gmlr = new GraphMLReader<Graph<Number, Number>, Number, Number>( vertexFactory, edgeFactory); //final DirectedGraph<Number,Number> graph = new DirectedSparseMultigraph<Number,Number>(); final Graph<Number, Number> graph = new SparseGraph<Number, Number>(); gmlr.load(filename, graph); // create a simple graph for the demo vv = new VisualizationViewer<Number, Number>(new FRLayout<Number, Number>(graph)); vv.addGraphMouseListener(new TestGraphMouseListener<Number>()); vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<Number, Number>(Color.white, Color.red, Color.white, Color.blue, vv.getPickedVertexState(), false)); // add my listeners for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Number>()); vv.setEdgeToolTipTransformer(new Transformer<Number, String>() { public String transform(Number edge) { return "E" + graph.getEndpoints(edge).toString(); } }); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO); // create a frome to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<Number, Number>(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); JMenuBar menubar = new JMenuBar(); menubar.add(graphMouse.getModeMenu()); panel.setCorner(menubar); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:net.chaosserver.timelord.swingui.AddTimeDialog.java
/** * Builds the Add Time Panel.//from w w w .j ava 2s. c o m * * @return the newly created add time panel */ public JPanel buildAddTimePanel() { JPanel addTimePanel = new JPanel(); Collection<TimelordTask> taskCollection = timelordData.getTaskCollection(); Vector<TimelordTask> taskVector = new Vector<TimelordTask>(taskCollection); comboBox = new JComboBox(taskVector); comboBox.setEditable(true); addTimePanel.add(comboBox); JButton button = new JButton("+0.25"); button.setActionCommand(ACTION_OK); button.addActionListener(this); addTimePanel.add(button); return addTimePanel; }
From source file:edu.harvard.mcz.imagecapture.VerbatimListDialog.java
protected void init() { setTitle("Verbatim Transcriptions to parse into fields"); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setBounds(100, 100, 1000, 600);/* ww w . j a v a 2 s . co m*/ getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new BorderLayout(0, 0)); SpecimenLifeCycle sls = new SpecimenLifeCycle(); table = new JTable(new VerbatimCountTableModel(sls.countDistinctVerbatimValues())); table.setDefaultRenderer(VerbatimCount.class, new ButtonRenderer("Edit")); table.setDefaultEditor(VerbatimCount.class, new ButtonEditor(ButtonEditor.OPEN_VERBATIM_CLASSIFY, this)); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(table); contentPanel.add(scrollPane, BorderLayout.CENTER); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton cancelButton = new JButton("Close"); cancelButton.setActionCommand("Close"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); buttonPane.add(cancelButton); } } }
From source file:sample.fa.ScriptRunnerApplication.java
void createGUI() { Box buttonBox = Box.createHorizontalBox(); JButton loadButton = new JButton("Load"); loadButton.addActionListener(this::loadScript); buttonBox.add(loadButton);// w ww .ja v a 2 s . c om JButton saveButton = new JButton("Save"); saveButton.addActionListener(this::saveScript); buttonBox.add(saveButton); JButton executeButton = new JButton("Execute"); executeButton.addActionListener(this::executeScript); buttonBox.add(executeButton); languagesModel = new DefaultComboBoxModel(); ScriptEngineManager sem = new ScriptEngineManager(); for (ScriptEngineFactory sef : sem.getEngineFactories()) { languagesModel.addElement(sef.getScriptEngine()); } JComboBox<ScriptEngine> languagesCombo = new JComboBox<>(languagesModel); JLabel languageLabel = new JLabel(); languagesCombo.setRenderer((JList<? extends ScriptEngine> list, ScriptEngine se, int index, boolean isSelected, boolean cellHasFocus) -> { ScriptEngineFactory sef = se.getFactory(); languageLabel.setText(sef.getEngineName() + " - " + sef.getLanguageName() + " (*." + String.join(", *.", sef.getExtensions()) + ")"); return languageLabel; }); buttonBox.add(Box.createHorizontalGlue()); buttonBox.add(languagesCombo); scriptContents = new JTextArea(); scriptContents.setRows(8); scriptContents.setColumns(40); scriptResults = new JTextArea(); scriptResults.setEditable(false); scriptResults.setRows(8); scriptResults.setColumns(40); JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptContents, scriptResults); JFrame frame = new JFrame("Script Runner"); frame.add(buttonBox, BorderLayout.NORTH); frame.add(jsp, BorderLayout.CENTER); frame.pack(); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setVisible(true); }
From source file:eu.fbk.sonet.snatool.GraphVisualizer.java
/** * create an instance of a simple graph with controls to * demo the zoom features./*from ww w.j av a2 s . c om*/ * @throws SAXException * @throws ParserConfigurationException * @throws IOException * */ public GraphVisualizer(String filename) throws ParserConfigurationException, SAXException, IOException { Factory<Number> vertexFactory = new Factory<Number>() { int n = 0; public Number create() { return n++; } }; Factory<Number> edgeFactory = new Factory<Number>() { int n = 0; public Number create() { return n++; } }; GraphMLReader<DirectedGraph<Number, Number>, Number, Number> gmlr = new GraphMLReader<DirectedGraph<Number, Number>, Number, Number>( vertexFactory, edgeFactory); final DirectedGraph<Number, Number> graph = new DirectedSparseMultigraph<Number, Number>(); gmlr.load(filename, graph); // create a simple graph for the demo vv = new VisualizationViewer<Number, Number>(new FRLayout<Number, Number>(graph)); //vv.addGraphMouseListener(new TestGraphMouseListener<Number>()); vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<Number, Number>(Color.white, Color.red, Color.white, Color.blue, vv.getPickedVertexState(), false)); // add my listeners for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Number>()); vv.setEdgeToolTipTransformer(new Transformer<Number, String>() { public String transform(Number edge) { return "E" + graph.getEndpoints(edge).toString(); } }); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO); // create a frome to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<Number, Number>(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); JMenuBar menubar = new JMenuBar(); menubar.add(graphMouse.getModeMenu()); panel.setCorner(menubar); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); // Scaling graph image final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); // Adding control to controls JPanel JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:Bounce.java
/** * Adds a button to a container./*from www . j a v a2 s . c o m*/ * * @param c * the container * @param title * the button title * @param listener * the action listener for the button */ public void addButton(Container c, String title, ActionListener listener) { JButton button = new JButton(title); c.add(button); button.addActionListener(listener); }
From source file:UndoDemo.java
/** Construct a GUI that demonstrates use of UndoManager */ public UndoDemo() { Container cp = getContentPane(); cp.add(ta = new JTextArea(20, 60), BorderLayout.CENTER); JPanel bp;/*from w w w. j a v a 2s . c o m*/ cp.add(bp = new JPanel(), BorderLayout.SOUTH); // Create a javax.swing.undo.UndoManager; this is an amazing class that // keeps a Stack of UndoableEdits and lets you invoke them; // by registering it as a Listener on the TextComponent.Document, // the Document will create the UndoableEdit objects and send them // to the UndoManager. Between them they do ALL the work! um = new UndoManager(); ta.getDocument().addUndoableEditListener(um); // Create the buttons JButton cutButton, copyButton, pasteButton, undoButton, redoButton; bp.add(cutButton = new JButton("Cut")); cutButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ta.cut(); } }); bp.add(copyButton = new JButton("Copy")); copyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ta.copy(); } }); bp.add(pasteButton = new JButton("Paste")); pasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ta.paste(); } }); bp.add(undoButton = new JButton("UnDo")); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (um.canUndo()) { um.undo(); } else { warn("Can't undo"); } } }); bp.add(redoButton = new JButton("ReDo")); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (um.canRedo()) { um.redo(); } else { warn("Can't redo"); } } }); pack(); setDefaultCloseOperation(EXIT_ON_CLOSE); }
From source file:ShowDocument.java
public URLWindow(AppletContext appletContext) { super("Show a Document!"); this.appletContext = appletContext; JPanel contentPane = new JPanel(new GridBagLayout()); setContentPane(contentPane);/*from www. j a v a 2s . c o m*/ contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel label1 = new JLabel("URL of document to show: ", JLabel.TRAILING); add(label1, c); urlField = new JTextField("http://java.sun.com/", 20); label1.setLabelFor(urlField); urlField.addActionListener(this); c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; add(urlField, c); JLabel label2 = new JLabel("Window/frame to show it in: ", JLabel.TRAILING); c.gridwidth = 1; c.weightx = 0.0; add(label2, c); String[] strings = { "(browser's choice)", //don't specify "My Personal Window", //a window named "My Personal Window" "_blank", //a new, unnamed window "_self", "_parent", "_top" //the Frame that contained this applet }; choice = new JComboBox(strings); label2.setLabelFor(choice); c.fill = GridBagConstraints.NONE; c.gridwidth = GridBagConstraints.REMAINDER; c.insets = new Insets(5, 0, 0, 0); c.anchor = GridBagConstraints.LINE_START; add(choice, c); JButton button = new JButton("Show document"); button.addActionListener(this); c.weighty = 1.0; c.ipadx = 10; c.ipady = 10; c.insets = new Insets(10, 0, 0, 0); c.anchor = GridBagConstraints.PAGE_END; add(button, c); }