List of usage examples for javax.swing JButton setActionCommand
public void setActionCommand(String actionCommand)
From source file:MainClass.java
private void makeGUI() { setLayout(new FlowLayout()); ImageIcon france = new ImageIcon("france.gif"); JButton jb = new JButton(france); jb.setActionCommand("France"); jb.addActionListener(this); add(jb);/*from www. j a v a2 s . co m*/ ImageIcon germany = new ImageIcon("germany.gif"); jb = new JButton(germany); jb.setActionCommand("Germany"); jb.addActionListener(this); add(jb); ImageIcon italy = new ImageIcon("italy.gif"); jb = new JButton(italy); jb.setActionCommand("Italy"); jb.addActionListener(this); add(jb); ImageIcon japan = new ImageIcon("japan.gif"); jb = new JButton(japan); jb.setActionCommand("Japan"); jb.addActionListener(this); add(jb); jtf = new JTextField(15); add(jtf); }
From source file:org.jfree.chart.demo.CloneTest1.java
public CloneTest1(String s) { super(s);/*w ww. j av a2s. com*/ lastValue = 100D; series = new TimeSeries("Random Data"); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(series); JFreeChart jfreechart = createChart(timeseriescollection); JFreeChart jfreechart1 = null; try { jfreechart1 = (JFreeChart) jfreechart.clone(); } catch (Exception exception) { exception.printStackTrace(); } XYPlot xyplot = (XYPlot) jfreechart1.getPlot(); TimeSeriesCollection timeseriescollection1 = (TimeSeriesCollection) xyplot.getDataset(); series = timeseriescollection1.getSeries(0); ChartPanel chartpanel = new ChartPanel(jfreechart1); JButton jbutton = new JButton("Add New Data Item"); jbutton.setActionCommand("ADD_DATA"); jbutton.addActionListener(this); JPanel jpanel = new JPanel(new BorderLayout()); jpanel.add(chartpanel); jpanel.add(jbutton, "South"); chartpanel.setPreferredSize(new Dimension(500, 270)); setContentPane(jpanel); }
From source file:Main.java
private JButton makeButton(String caption) { JButton b = new JButton(caption); b.setActionCommand(caption); b.addActionListener(this); getContentPane().add(b);// w w w.ja v a 2 s. c o m return b; }
From source file:Main.java
void addTab() { JEditorPane ep = new JEditorPane(); ep.setEditable(false);//from ww w.j av a 2 s . c o m tp.addTab(null, new JScrollPane(ep)); JButton tabCloseButton = new JButton("Close"); tabCloseButton.setActionCommand("" + tabCounter); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent ae) { JButton btn = (JButton) ae.getSource(); String s1 = btn.getActionCommand(); for (int i = 1; i < tp.getTabCount(); i++) { JPanel pnl = (JPanel) tp.getTabComponentAt(i); btn = (JButton) pnl.getComponent(0); String s2 = btn.getActionCommand(); if (s1.equals(s2)) { tp.removeTabAt(i); break; } } } }; tabCloseButton.addActionListener(al); if (tabCounter != 0) { JPanel pnl = new JPanel(); pnl.setOpaque(false); pnl.add(tabCloseButton); tp.setTabComponentAt(tp.getTabCount() - 1, pnl); tp.setSelectedIndex(tp.getTabCount() - 1); } tabCounter++; }
From source file:Flipper.java
private JButton makeButton(String caption) { JButton b = new JButton(caption); b.setActionCommand(caption); b.addActionListener(this); getContentPane().add(b, constraints); return b;/*w ww . j a va 2 s . co m*/ }
From source file:org.jfree.chart.demo.Graph.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w w w . j av a 2s.c o m */ 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:components.DynamicTreeDemo.java
public DynamicTreeDemo() { super(new BorderLayout()); //Create the components. treePanel = new DynamicTree(); populateTree(treePanel);// ww w. jav a2 s . c om 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); }
From source file:components.ToolBarDemo.java
protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {/*from w w w. ja va2 s . com*/ //Look for the image. String imgLocation = "images/" + imageName + ".gif"; URL imageURL = ToolBarDemo.class.getResource(imgLocation); //Create and initialize the button. JButton button = new JButton(); button.setActionCommand(actionCommand); button.setToolTipText(toolTipText); button.addActionListener(this); if (imageURL != null) { //image found button.setIcon(new ImageIcon(imageURL, altText)); } else { //no image found button.setText(altText); System.err.println("Resource not found: " + imgLocation); } return button; }
From source file:com.github.woonsan.commons.scxml.examples.stopwatch.StopWatchFrame.java
private JButton createButton(final String command, final String text) { JButton button = new JButton(text); button.setActionCommand(command); button.addActionListener(this); return button; }
From source file:net.chaosserver.timelord.swingui.JCalendarDialog.java
/** * Creates the dialog.// w ww . ja v a 2s . com * * @param owner the owner frame * @param selectedDate the date to have the calendar on, or null for * current date. */ public JCalendarDialog(Frame owner, Date selectedDate) { super(owner, "Pick Date", true); calendar = new JCalendar(); if (selectedDate != null) { calendar.setDate(selectedDate); } this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(calendar, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(); JButton selectButton = new JButton("Select"); selectButton.setActionCommand(actionSelect); selectButton.addActionListener(this); buttonPanel.add(selectButton); JButton cancelButton = new JButton("Cancel"); cancelButton.setActionCommand(actionCancel); cancelButton.addActionListener(this); buttonPanel.add(cancelButton); this.getContentPane().add(buttonPanel, BorderLayout.SOUTH); }