Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>to have the x-axis and y-axis controls on top of each other, you should have two panels, one including the labels and text fields for the x-axis in one and those for the y-axis in the other. You would then add those to a panel that is aligned vertically. (<code>Box.createVerticalBox()</code>, for example)</p></li> <li><p>You can make your <code>graph.java</code> an <code>ActionListener</code> of the 'Plot' and 'Refine' buttons. In the <code>actionPerformed</code> method of graph.java, you can initiate a repaint, gathering the ranges from the 'ControlsB' instance.</p></li> </ol> <p>EDIT: responding to your comments...</p> <p><em>'how to add another panel in order for me to place the x-axis above the y-axis'</em></p> <p>this can be as simple as (in ControlsB.java):</p> <pre><code>b = Box.createHorizontalBox(); b.add(new JLabel("Please enter range: ")); Box b0 = Box.createVerticalBox();//create a vertical box to stack the controls Box b1 = Box.createHorizontalBox(); // create a horizontal box for the x-axis b1.add(new JLabel(" x-axis ")); b1.add(new JLabel("from")); JTextField f1 = new JTextField("-5"); f1.setMaximumSize(new Dimension(100,30)); b1.add(f1); b1.add(new JLabel(" to ")); JTextField f2 = new JTextField("5"); f2.setMaximumSize(new Dimension(100,30)); b1.add(f2); b1.add(new JLabel(". ")); Box b2 = Box.createHorizontalBox(); // create a second horizontal box for the y-axis b2.add(new JLabel("y-axis ")); b2.add(new JLabel("from")); JTextField f3 = new JTextField("5"); f3.setMaximumSize(new Dimension(100,30)); b2.add(f3); b2.add(new JLabel("to")); JTextField f4 = new JTextField("-5"); f4.setMaximumSize(new Dimension(100,30)); b2.add(f4); b0.add(b1); // add the x-axis to the vertical box b0.add(b2); // add the y-axis to the vertical box b.add(b0); // add the vertical box to the parent b.add(new JButton("Plot")); b.add(new JButton("Refine")); add(b); //is this necessary? } </code></pre> <p><em>' and how to gather the ranges from the ControlsB instance...'</em></p> <p>You should look into <code>ActionListener</code>s in <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html" rel="nofollow">this tutorial</a> to understand how to make the button click events trigger action in a separate class.</p> <p>Also, two critiques:</p> <ol> <li><p>in your main class, <code>GraphApplet</code>, you are creating a <code>Box</code> before passing it into each of <code>ControlsA</code> and <code>ControlsB</code>'s constructor. In the constructor, you then reassign the Box that you've passed in. I don't think that you need to do that. Either create the correctly aligned box in <code>GraphApplet</code>, pass that in and don't reassign, or don't pass anything in at all.</p></li> <li><p>Your <code>ControlsA</code> and <code>ControlsB</code> classes both extend <code>JPanel</code>. Although you go to the trouble of adding your <code>Box</code> containers to each of these at the end of their constructors, you don't ever add those Controls+ objects to any parent container. In your current implementation, i would suggest that extending <code>JPanel</code> is not necessary.</p></li> </ol>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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