List of usage examples for javax.swing JButton setActionCommand
public void setActionCommand(String actionCommand)
From source file:net.chaosserver.timelord.swingui.PreviousDayPanel.java
/** * Constructs a new previous day panel./*from ww w .j a v a2 s . co m*/ * * @param timelordData the timelord data to pull information from. */ public PreviousDayPanel(TimelordData timelordData) { this.timelordData = timelordData; setLayout(new BorderLayout()); JButton pickDayButton = new JButton("Select Day"); pickDayButton.setActionCommand(ACTION_PICK_DAY); pickDayButton.addActionListener(this); add(pickDayButton, BorderLayout.NORTH); Calendar calendarDay = Calendar.getInstance(); calendarDay.add(Calendar.DAY_OF_WEEK, -1); setDisplayDate(DateUtil.trunc(calendarDay.getTime())); }
From source file:InternalFrameEventDemo.java
protected void createDisplayWindow() { JButton b1 = new JButton("Show internal frame"); b1.setActionCommand(SHOW); b1.addActionListener(this); JButton b2 = new JButton("Clear event info"); b2.setActionCommand(CLEAR);/*www.ja va2s . c o m*/ b2.addActionListener(this); display = new JTextArea(3, 30); display.setEditable(false); JScrollPane textScroller = new JScrollPane(display); // Have to supply a preferred size, or else the scroll // area will try to stay as large as the text area. textScroller.setPreferredSize(new Dimension(200, 75)); textScroller.setMinimumSize(new Dimension(10, 10)); displayWindow = new JInternalFrame("Event Watcher", true, // resizable false, // not closable false, // not maximizable true); // iconifiable JPanel contentPane = new JPanel(); contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); b1.setAlignmentX(CENTER_ALIGNMENT); contentPane.add(b1); contentPane.add(Box.createRigidArea(new Dimension(0, 5))); contentPane.add(textScroller); contentPane.add(Box.createRigidArea(new Dimension(0, 5))); b2.setAlignmentX(CENTER_ALIGNMENT); contentPane.add(b2); displayWindow.setContentPane(contentPane); displayWindow.pack(); displayWindow.setVisible(true); }
From source file:org.jfree.chart.demo.DynamicDataDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w w w . jav a 2 s .com */ public DynamicDataDemo2(final String title) { super(title); this.series1 = new TimeSeries("Random 1", Millisecond.class); this.series2 = new TimeSeries("Random 2", Millisecond.class); final TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1); final TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Dynamic Data Demo 2", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); // 60 seconds plot.setDataset(1, dataset2); final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); plot.setRenderer(1, new DefaultXYItemRenderer()); plot.setRangeAxis(1, rangeAxis2); plot.mapDatasetToRangeAxis(1, 1); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add To Series 1"); button1.setActionCommand("ADD_DATA_1"); button1.addActionListener(this); final JButton button2 = new JButton("Add To Series 2"); button2.setActionCommand("ADD_DATA_2"); button2.addActionListener(this); final JButton button3 = new JButton("Add To Both"); button3.setActionCommand("ADD_BOTH"); button3.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); buttonPanel.add(button3); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:org.jfree.chart.demo.DynamicDataDemo3.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w w w .j av a 2s . c o m */ public DynamicDataDemo3(final String title) { super(title); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.datasets = new TimeSeriesCollection[SUBPLOT_COUNT]; for (int i = 0; i < SUBPLOT_COUNT; i++) { this.lastValue[i] = 100.0; final TimeSeries series = new TimeSeries("Random " + i, Millisecond.class); this.datasets[i] = new TimeSeriesCollection(series); final NumberAxis rangeAxis = new NumberAxis("Y" + i); rangeAxis.setAutoRangeIncludesZero(false); final XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot); } final JFreeChart chart = new JFreeChart("Dynamic Data Demo 3", plot); // chart.getLegend().setAnchor(Legend.EAST); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); // 60 seconds final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JPanel buttonPanel = new JPanel(new FlowLayout()); for (int i = 0; i < SUBPLOT_COUNT; i++) { final JButton button = new JButton("Series " + i); button.setActionCommand("ADD_DATA_" + i); button.addActionListener(this); buttonPanel.add(button); } final JButton buttonAll = new JButton("ALL"); buttonAll.setActionCommand("ADD_ALL"); buttonAll.addActionListener(this); buttonPanel.add(buttonAll); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 470)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(content); }
From source file:org.simbrain.plot.barchart.BarChartGui.java
/** * Construct the GUI Bar Chart.//from w w w . java2s. c o m * * @param frame Generic frame * @param component Bar chart component */ public BarChartGui(final GenericFrame frame, final BarChartComponent component) { super(frame, component); setPreferredSize(PREFERRED_SIZE); actionManager = new PlotActionManager(this); setLayout(new BorderLayout()); JButton deleteButton = new JButton("Delete"); deleteButton.setActionCommand("Delete"); deleteButton.addActionListener(this); JButton addButton = new JButton("Add"); addButton.setActionCommand("Add"); addButton.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.add(deleteButton); buttonPanel.add(addButton); createAttachMenuBar(); add("Center", chartPanel); add("South", buttonPanel); }
From source file:InternalFrameEventDemo.java
protected void createDisplayWindow() { JButton b1 = new JButton("Show internal frame"); b1.setActionCommand(SHOW); b1.addActionListener(this); JButton b2 = new JButton("Clear event info"); b2.setActionCommand(CLEAR);/*from w w w . j a va 2s.c om*/ b2.addActionListener(this); display = new JTextArea(3, 30); display.setEditable(false); JScrollPane textScroller = new JScrollPane(display); //Have to supply a preferred size, or else the scroll //area will try to stay as large as the text area. textScroller.setPreferredSize(new Dimension(200, 75)); textScroller.setMinimumSize(new Dimension(10, 10)); displayWindow = new JInternalFrame("Event Watcher", true, //resizable false, //not closable false, //not maximizable true); //iconifiable JPanel contentPane = new JPanel(); contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); b1.setAlignmentX(CENTER_ALIGNMENT); contentPane.add(b1); contentPane.add(Box.createRigidArea(new Dimension(0, 5))); contentPane.add(textScroller); contentPane.add(Box.createRigidArea(new Dimension(0, 5))); b2.setAlignmentX(CENTER_ALIGNMENT); contentPane.add(b2); displayWindow.setContentPane(contentPane); displayWindow.pack(); displayWindow.setVisible(true); }
From source file:mulavito.samples.GraphAlgorithmDemo.java
public GraphAlgorithmDemo() { super("MuLaViTo Algorithms Demo"); // Set the frame icon. ImageIcon icon = Resources.getIconByName("/img/mulavito-logo.png"); if (icon != null) setIconImage(icon.getImage());//from w w w . j a v a 2 s .c o m // Create toolbar. JToolBar toolbar = new JToolBar(); getToolBarPane().add(toolbar); JButton btn; btn = new JButton("New Graph"); btn.setActionCommand("graph"); btn.addActionListener(this); toolbar.add(btn); btn = new JButton("Auto Size"); btn.setActionCommand("autosize"); btn.addActionListener(this); toolbar.add(btn); btn = new JButton("Eppstein"); btn.setActionCommand("eppstein"); btn.addActionListener(this); toolbar.add(btn); btn = new JButton("Yen"); btn.setActionCommand("yen"); btn.addActionListener(this); toolbar.add(btn); btn = new JButton("Suurballe-Tarjan"); btn.setActionCommand("suurballe-tarjan"); btn.addActionListener(this); toolbar.add(btn); btn = new JButton("About"); btn.setActionCommand("about"); btn.addActionListener(this); toolbar.add(btn); normalOutput("Welcome to MuLaViTo demonstrator.\n"); debugOutput("Click on \"New Graph\" to create a new graph.\n"); warnOutput("Click Eppstein, Yen, or Suurballe-Tarjan to randomly " + "select source and destination and run the algorithm\n"); notifyOutput("Have fun!!!\n"); setPreferredSize(new Dimension(500, 600)); setMinimumSize(new Dimension(500, 600)); setVisible(true); }
From source file:org.simbrain.plot.scatterplot.ScatterPlotGui.java
/** * Construct the ScatterPlot./*from w w w . jav a 2 s .co m*/ * * @param frame Generic frame for gui use * @param component Scatter plot component */ public ScatterPlotGui(final GenericFrame frame, final ScatterPlotComponent component) { super(frame, component); this.component = component; setPreferredSize(new Dimension(PREFERRED_SIZE)); actionManager = new PlotActionManager(this); setLayout(new BorderLayout()); JButton deleteButton = new JButton("Delete"); deleteButton.setActionCommand("Delete"); deleteButton.addActionListener(this); JButton addButton = new JButton("Add"); addButton.setActionCommand("Add"); addButton.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.add(deleteButton); buttonPanel.add(addButton); createAttachMenuBar(); add("Center", chartPanel); add("South", buttonPanel); }
From source file:Main.java
public Main() { super(new BorderLayout()); listModel.addElement("A"); listModel.addElement("B"); listModel.addElement("C"); list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);/*from w ww . j a v a 2 s .c om*/ list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(addCommand); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(addCommand); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(deleteCommand); fireButton.setActionCommand(deleteCommand); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); System.out.println(name); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
From source file:net.chaosserver.timelord.swingui.AnnoyTimeDialog.java
/** * Constructs a annoy time dialog for setting the dialog. * * @param applicationFrame the parent frame *///from w ww. ja va 2 s .co m public AnnoyTimeDialog(JFrame applicationFrame) { super(applicationFrame, "Set Day Start Time", true); JPanel annoyTimePanel = new JPanel(); minuteSlider = new JSlider(0, 60); minuteSlider.setMajorTickSpacing(15); minuteSlider.setMinorTickSpacing(3); minuteSlider.setPaintLabels(true); minuteSlider.setPaintTicks(true); minuteSlider.setSnapToTicks(true); Preferences preferences = Preferences.userNodeForPackage(Timelord.class); double timeIncrement = preferences.getDouble(Timelord.TIME_INCREMENT, 0.25); if (log.isDebugEnabled()) { log.debug("Loaded Time Increment Preference [" + timeIncrement + "] from preference [" + Timelord.TIME_INCREMENT + "]"); } minuteSlider.setValue((int) (timeIncrement * 60)); annoyTimePanel.add(minuteSlider); JButton okayButton = new JButton( resourceBundle.getString("net.chaosserver.timelord.swingui.TimelordMenu.okay")); okayButton.setActionCommand(ACTION_OK); okayButton.addActionListener(this); annoyTimePanel.add(okayButton); JButton cancelButton = new JButton( resourceBundle.getString("net.chaosserver.timelord.swingui.TimelordMenu.cancel")); cancelButton.setActionCommand(ACTION_CANCEL); cancelButton.addActionListener(this); annoyTimePanel.add(cancelButton); this.getContentPane().add(annoyTimePanel); this.pack(); this.setLocationRelativeTo(applicationFrame); }