List of usage examples for javax.swing JButton setActionCommand
public void setActionCommand(String actionCommand)
From source file:com.jdom.util.patterns.mvp.swing.RadioButtonGroupDialog.java
private RadioButtonGroupDialog(Frame frame, Component locationComp, String labelText, String title, Collection<String> data, String initialValue, String longValue) { super(frame, title, true); final JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); final JButton setButton = new JButton("OK"); setButton.setActionCommand("OK"); setButton.addActionListener(this); getRootPane().setDefaultButton(setButton); ButtonGroup radioButtonGroup = new ButtonGroup(); for (String option : data) { JRadioButton button = new JRadioButton(option); if (option.equals(initialValue)) { button.setSelected(true);// w ww . j a va 2 s . c o m } radioButtonGroup.add(button); panel.add(button); } JScrollPane listScroller = new JScrollPane(panel); listScroller.setPreferredSize(new Dimension(250, 80)); listScroller.setAlignmentX(LEFT_ALIGNMENT); JPanel listPane = new JPanel(); listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); if (!StringUtils.isEmpty(labelText)) { JLabel label = new JLabel(labelText); label.setText(labelText); listPane.add(label); } listPane.add(Box.createRigidArea(new Dimension(0, 5))); listPane.add(listScroller); listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(cancelButton); buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(setButton); Container contentPane = getContentPane(); contentPane.add(listPane, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.PAGE_END); pack(); setLocationRelativeTo(locationComp); }
From source file:org.jfree.chart.demo.SerializationTest1.java
/** * Constructs a new demonstration application. * * @param title the frame title./*ww w . j av a 2s .co m*/ */ public SerializationTest1(final String title) { super(title); this.series = new TimeSeries("Random Data", Millisecond.class); TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); JFreeChart chart = createChart(dataset); // SERIALIZE - DESERIALIZE for testing purposes JFreeChart deserializedChart = null; try { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(chart); out.close(); chart = null; dataset = null; this.series = null; System.gc(); final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); deserializedChart = (JFreeChart) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } final TimeSeriesCollection c = (TimeSeriesCollection) deserializedChart.getXYPlot().getDataset(); this.series = c.getSeries(0); // FINISHED TEST final ChartPanel chartPanel = new ChartPanel(deserializedChart); 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:DynamicDataDemo.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w ww .j a va2s. c o m */ public DynamicDataDemo(final String title, String xcoor, String ycoor, String data) { super(title); this.series = new TimeSeries(data, Millisecond.class); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); final JFreeChart chart = createChart(dataset, title, xcoor, ycoor); final ChartPanel chartPanel = new ChartPanel(chart); final JButton button = new JButton("Add New Data Item"); button.setActionCommand("ADD_DATA"); button.addActionListener(this); content = new JPanel(new BorderLayout()); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); //setContentPane(content); }
From source file:org.simbrain.plot.piechart.PieChartGui.java
/** * Construct the GUI Pie Chart.//from w ww . jav a2s .c o m * * @param frame Generic Frame * @param component Pie chart component */ public PieChartGui(final GenericFrame frame, final PieChartComponent 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:components.PasswordDemo.java
protected JComponent createButtonPanel() { JPanel p = new JPanel(new GridLayout(0, 1)); JButton okButton = new JButton("OK"); JButton helpButton = new JButton("Help"); okButton.setActionCommand(OK); helpButton.setActionCommand(HELP);/*from ww w .j a v a 2 s . c o m*/ okButton.addActionListener(this); helpButton.addActionListener(this); p.add(okButton); p.add(helpButton); return p; }
From source file:org.jfree.chart.demo.SecondaryDatasetDemo1.java
/** * Constructs a new demonstration application. * * @param title the frame title.//ww w.j ava2 s . c o m */ public SecondaryDatasetDemo1(String title) { super(title); TimeSeriesCollection dataset1 = createRandomDataset("Series 1"); JFreeChart chart = ChartFactory.createTimeSeriesChart("Secondary Dataset Demo 1", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getXYPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); ValueAxis axis = this.plot.getDomainAxis(); axis.setAutoRange(true); NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); JPanel content = new JPanel(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:org.jfree.chart.demo.SecondaryDatasetDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title./*from w w w.j ava 2 s.c om*/ */ public SecondaryDatasetDemo2(final String title) { super(title); final CategoryDataset dataset1 = createRandomDataset("Series 1"); final JFreeChart chart = ChartFactory.createLineChart("Secondary Dataset Demo 2", "Category", "Value", dataset1, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getCategoryPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); // this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final NumberAxis rangeAxis = (NumberAxis) this.plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); final JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:DynamiskDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from ww w. j a v a 2 s . c om */ public DynamiskDemo2(final String title) { super(title); this.series = new XYSeries(title, false, false); final XYSeriesCollection dataset = new XYSeriesCollection(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); String fil = "C:" + File.separator + "Users" + File.separator + "madso" + File.separator + "Documents" + File.separator + "!Privat" + File.separator + "DTU 2016-2020" + File.separator + "MATLAB"; String filnavn = "EKGdata"; try { Scanner sc = new Scanner(new FileReader(fil + File.separator + filnavn)); Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { if (sc.hasNext()) { final double newItem = Double.parseDouble(sc.next()); series.add(x, newItem); x += 10; } } }, 100, 2); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.jfree.chart.demo.MultipleDatasetDemo1.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from www .j a va 2s .co m */ public MultipleDatasetDemo1(final String title) { super(title); final TimeSeriesCollection dataset1 = createRandomDataset("Series 1"); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Dataset Demo 1", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getXYPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); // this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = this.plot.getDomainAxis(); axis.setAutoRange(true); final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); final JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:com.experiments.DynamicDataDemo.java
/** * Constructs a new demonstration application. * //w w w . j a va2s. co m * @param title * the frame title. */ public DynamicDataDemo(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); chartPanel.setFillZoomRectangle(false); final JButton button = new JButton("Add New Data Item"); button.setActionCommand("ADD_DATA"); button.addActionListener(this); final JButton start_button = new JButton("Start adding"); start_button.setActionCommand("START_ADDING"); start_button.addActionListener(this); final JButton stop_button = new JButton("Stop adding"); stop_button.setActionCommand("STOP_ADDING"); stop_button.addActionListener(this); final JPanel button_panel = new JPanel(); button_panel.add(button); button_panel.add(start_button); button_panel.add(stop_button); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); content.add(button_panel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }