Note that there are some explanatory texts on larger screens.

plurals
  1. POArrayList to store actions performed when button is clicked
    primarykey
    data
    text
    <p>I am having a lot of difficulty with my arrayList. I have got three buttons (in my jPanelBottom page) and when I click on the Start Button, every action i do from then on in (Selecting options from a menu or moving the jSlider) is supposed to be recorded. One I click the Stop button, it is supposed to stop recording and once I click on the Play button, every action I have done is supposed to be output to the screen. I have no idea how to do this. </p> <p>I will attach some of my classes so you are able to see. </p> <p>Here is my JPanelBottom page that contains everything ~I have created and my change event (for the jSlider)</p> <pre><code>public class jPanelBottom extends javax.swing.JPanel { private JTextField jtfBoundaryLength, jtfArea; private JSlider jsShapes; private JLabel jLabelBoundaryLength, jLabelArea, jLabelSlider; private JButton jbStart, jbStop, jbPlay; //private JPanel jpBottom; public jPanelBottom() { initComponents(); //JSlider jsShapes = new JSlider(); jsShapes = new javax.swing.JSlider(); jsShapes.setMajorTickSpacing(10); jsShapes.setPaintLabels(true); jsShapes.setPaintTicks(true); jsShapes.setSize(300, 100); this.add(jsShapes); jsShapes.addChangeListener(new event()); jtfBoundaryLength = new JTextField(); jtfBoundaryLength.setSize(100, 25); jtfBoundaryLength.setLocation(550, 30); this.add(jtfBoundaryLength); jLabelBoundaryLength = new JLabel(); jLabelBoundaryLength.setText("Boundary Length: "); jLabelBoundaryLength.setSize(130, 25); jLabelBoundaryLength.setLocation(400, 30); this.add(jLabelBoundaryLength); jtfArea = new JTextField(); jtfArea.setSize(100, 25); jtfArea.setLocation(550, 60); this.add(jtfArea); jLabelArea = new JLabel(); jLabelArea.setText("Area: "); jLabelArea.setSize(100, 25); jLabelArea.setLocation(400, 60); this.add(jLabelArea); jLabelSlider = new JLabel(); jLabelSlider.setText("Select the size please"); jLabelSlider.setSize(150, 150); jLabelSlider.setLocation(85, 30); this.add(jLabelSlider); jbStart = new JButton(); jbStart.setText("Start"); jbStart.setSize(80, 25); jbStart.setLocation(400, 95); this.add(jbStart); jbStop = new JButton(); jbStop.setText("Stop"); jbStop.setSize(80, 25); jbStop.setLocation(500, 95); this.add(jbStop); jbPlay = new JButton(); jbPlay.setText("Play"); jbPlay.setSize(80, 25); jbPlay.setLocation(600, 95); this.add(jbPlay); } public class event implements ChangeListener { @Override public void stateChanged(ChangeEvent e) { try { if (MyFrame.shape1 == null) { jtfBoundaryLength.setText("shape not set"); } else { DecimalFormat g = new DecimalFormat("0.0"); jtfBoundaryLength.setText("" + g.format(MyFrame.shape1.getBoundaryLength(jsShapes.getValue()))); jtfArea.setText("" + g.format(MyFrame.shape1.getArea(jsShapes.getValue()))); } MyFrame.shape1.setSliderValue(jsShapes.getValue()); } catch (Throwable ex) {} } } public int getSliderValue() { return this.jsShapes.getValue(); } public void actionPerformed(ActionEvent e) { System.out.println(MyFrame.shape1.getArrayList()); } } </code></pre> <p>Here is my code for the Shapes page in which I create my ArrayList</p> <pre><code>public abstract class Shapes { ArrayList&lt;String&gt; arrayList = new ArrayList(); protected double boundaryLength; protected double area; private int sliderValue; public int getSliderValue() { return sliderValue; } public void setSliderValue(int sliderValue) { this.sliderValue = sliderValue; } public double getBoundaryLength(double boundaryLength) { return boundaryLength; } public double getArea(double area) { return area; } public ArrayList&lt;String&gt; getArrayList() { return arrayList; } public void setArrayList(ArrayList arrayList) { this.arrayList = arrayList; } } </code></pre> <p>Here is my MyFrame page which is where the menu is created. I have three options from the menu (Triangle, Circle and Square). </p> <pre><code>public class MyFrame extends javax.swing.JFrame implements ActionListener, ChangeListener { public static Shapes shape1; private JMenuItem Square; private JMenuItem Triangle; private JMenuItem Circle; private MyControlPanel controlPanelShapes; private jPanelTop d1 = new jPanelTop(); private jPanelBottom d2 = new jPanelBottom(); public MyFrame() { initComponents(); controlPanelShapes = new MyControlPanel(); controlPanelShapes.setSize(1000, 1000); controlPanelShapes.setLocation(0, 20); add(controlPanelShapes); d1.setSize(550, 230); d1.setVisible(true); this.add(d1); JMenuBar jBarShape = new JMenuBar(); JMenu Shape = new JMenu(); Shape.setText("Shape"); Square = new JMenuItem(); Square.setText("Square"); Shape.add(Square); Square.addActionListener(this); Triangle = new JMenuItem(); Triangle.setText("Triangle"); Shape.add(Triangle); Triangle.addActionListener(this); Circle = new JMenuItem(); Circle.setText("Circle"); Shape.add(Circle); Circle.addActionListener(this); jBarShape.add(Shape); setJMenuBar(jBarShape); } @Override public void stateChanged(ChangeEvent e) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == Circle) { shape1 = new Circle(); d1.setCircle(true, false); shape1.setSliderValue(d2.getSliderValue()); System.out.println(MyFrame.shape1.getArrayList()); } else if (e.getSource() == Triangle) { shape1 = new Triangle(); d1.setTriangle(true, false); shape1.setSliderValue(d2.getSliderValue()); System.out.println(MyFrame.shape1.getArrayList()); } else if (e.getSource() == Square) { shape1 = new Square(); d1.setSquare(true, false); shape1.setSliderValue(d2.getSliderValue()); System.out.println(MyFrame.shape1.getArrayList()); } } } </code></pre> <p>Basically when I click the play button, any time I click on a menu option or move the slider, it is supposed to be recorded and when I click Stop it stops recording. When I click Play it outputs it to the screen. I am sure it is fairly simple I just have no idea and I have been trying to get it to work for ages! Thank You in advance for any help, it is extremely appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload