Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are trying to make modifications or execute statements out side of the context of an executable context.</p> <p>You can only make declarations and assign default values to variables out side of methods and constructors</p> <p>Move </p> <pre><code>frame.setPreferredSize(new Dimension(200, 250)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); </code></pre> <p>To within the context of the classes constructor</p> <pre><code>public Cal(){ frame.setPreferredSize(new Dimension(200, 250)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); </code></pre> <p><strong>Updated</strong></p> <p>You are having a number of reference issues. You are define objects within the constructor that you are then wanting to access else where in you code. There is no context for these variables out side of the constructor. Instead, you should be declaring them at the class level, so that they are visible to the whole class.</p> <pre><code>public class Cal extends JFrame implements ActionListener { private JFrame frame = new JFrame(); private Button btn_1 = new Button("1"); private Button btn_2 = new Button("2"); private Button btn_3 = new Button("3"); private Button btn_4 = new Button("4"); private Button btn_5 = new Button("5"); private Button btn_6 = new Button("6"); private Button btn_7 = new Button("7"); private Button btn_8 = new Button("8"); private Button btn_9 = new Button("9"); private Button btn_0 = new Button("0"); private Button btn_dot = new Button("."); private Button btn_div = new Button("/"); private Button btn_mult = new Button("*"); private Button btn_sub = new Button("-"); private Button btn_addd = new Button("+"); private Button btn_equ = new Button("="); private JTextField jt = new JTextField(); public Cal(){ frame.setPreferredSize(new Dimension(200, 250)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // This is a bad idea, the layout manager will make these calls redudent... btn_1.setSize(5, 5); btn_2.setSize(5, 5); btn_3.setSize(5, 5); btn_4.setSize(5, 5); btn_5.setSize(5, 5); btn_6.setSize(5, 5); btn_7.setSize(5, 5); btn_8.setSize(5, 5); btn_9.setSize(5, 5); btn_0.setSize(5, 5); btn_dot.setSize(5, 5); btn_div.setSize(5, 5); btn_mult.setSize(5, 5); btn_sub.setSize(5, 5); btn_addd.setSize(5, 5); btn_equ.setSize(5, 5); jt.setHorizontalAlignment(JTextField.RIGHT); jt.setEditable(false); double fnum, snum, total; String op = null; JPanel players = new JPanel(); players.setLayout(new GridLayout(1, 1)); players.add(jt, BorderLayout.NORTH); players.setPreferredSize(new Dimension(10, 50)); JPanel players1 = new JPanel(new GridLayout(4, 3)); // adding buttons players1.add(btn_7); players1.add(btn_8); players1.add(btn_9); players1.add(btn_div); players1.add(btn_4); players1.add(btn_5); players1.add(btn_6); players1.add(btn_mult); players1.add(btn_1); players1.add(btn_2); players1.add(btn_3); players1.add(btn_sub); players1.add(btn_0); players1.add(btn_dot); players1.add(btn_equ); players1.add(btn_addd); players1.setPreferredSize(new Dimension(150, 150)); </code></pre> <p>You are also mixing heavy and light weight components, this is never a good idea. Use <code>JButton</code> instead of <code>Button</code></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.
    2. 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