Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could try something like this: </p> <pre><code> public class RainApplet extends JFrame { public RainApplet(){ final JTextField rainEntryField = new JTextField("0", 10); final JTextField dayEntryField = new JTextField("0", 10); final JTextArea dataArea = new JTextArea("", 10, 10); rainEntryField.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { // Fetch the new reading details int newDay = Integer.parseInt(dayEntryField.getText()); double newRain = Double.parseDouble(rainEntryField.getText()); // Clear the input dayEntryField.setText(""); rainEntryField.setText(""); dataArea.append(newDay + ": " + newRain + " cm" + "\n"); arr.add(newRain); } // end of ActionListener }); // create new JPanel 'content' and add all components using BorderLayout JPanel content = new JPanel(); content.setLayout(new BorderLayout(5, 5)); // placing components around the JPanel content.add(rainEntryField , BorderLayout.NORTH); content.add( dayEntryField, BorderLayout.EAST ); content.add( dataArea , BorderLayout.EAST ); // set desirable properties for panel this.setContentPane(content); this.pack(); this.setTitle("Rain Applet"); this.setResizable(false); this.setLocationRelativeTo(null); this.setVisible(true); this.setDefaultCloseOperation(EXIT_ON_CLOSE); } private ArrayList&lt;Double&gt; arr = new ArrayList&lt;Double&gt;(); public void addRain(Double d) { arr.add(d); } } </code></pre> <p>This should do the trick and uses the array above for reasons explained by @John Snow</p>
    singulars
    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. VO
      singulars
      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