Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing ActionListener to update variables in other classes
    text
    copied!<p>I am designing an applet so it allows a user to plot a graph. I am having problems to construct a code which from another file (ControlsB.java) the variables in the Graph.java file are updated. Below is my code:</p> <pre><code> import java.awt.*; import javax.swing.*; public class Calculator extends JFrame{ /** * */ private static final long serialVersionUID = 1L; private static final int HORIZONTAL_SCROLLBAR_NEVER = 0; private static final int VERTICAL_SCROLLBAR_ALWAYS = 0; public static void main (String[] args){ JFrame calculator = new JFrame("My Simple Calculator"); calculator.setSize(500,500); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); Box a = Box.createHorizontalBox(); JTextArea text = new JTextArea(10,15); </code></pre> <p>JScrollPane scroll = new JScrollPane(text, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); </p> <pre><code>Box b = Box.createHorizontalBox(); //JToolBar tool = new JToolBar(SwingConstants.HORIZONTAL); JButton add = new JButton("+"); JButton minus = new JButton("-"); JButton multi = new JButton("x"); JButton div = new JButton("/"); JButton c = new JButton("C"); JButton eq = new JButton("="); JTextField field = new JTextField(10); JButton enter = new JButton("Enter"); b.add(add); b.add(minus); b.add(multi); b.add(div); b.add(c); b.add(eq); a.add(field); a.add(enter); panel.add(scroll,BorderLayout.NORTH); panel.add(b,BorderLayout.CENTER); panel.add(a,BorderLayout.SOUTH); calculator.setContentPane(panel); calculator.setVisible(true); } } </code></pre> <p>Now my main concerns are in the ControlsB.java file, where I want that when the user inputs the the x-axis and y-axis <strong>ranges</strong> and hits the button <strong>Resize</strong> the variables in the graph.java file are updated accordingly and thus the graph resizes.</p> <p><em>The variables which I am talking about in Graph.java file are in lines between 57 and 65.</em></p> <p>Thanks</p>
 

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