If I compile this, I get 'cannot find symbol' errors with the setDefaultCloseOperation, setSize and setVisible. My problem is I don't understand why. and This is the part of myhomework. But I can't even start next part Because of this problem
//AdderSubtracterFrame.java
//This class displays a Frame which can add or subtract two numbers
import javax.swing.JFrame;
public class AdderSubtracterProgram
{
public static void main(String [] args)
{
AdderSubtracterFrame frame1 = new AdderSubtracterFrame("Adder and Subtracter");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setSize(400,100);
frame1.setVisible(true);
}
}
I add AdderSubtracterFrame code two classes are in the same project. This project is to make a calculator
//AdderSubtracterFrame.java
//This class displays a Frame which can add or subtract two numbers
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.FlowLayout;
public class AdderSubtracterFrame
{
private JTextField num1TextField;
private JTextField num2TextField;
private JTextField resultTextField;
private JButton clearButton;
private JButton addButton;
private JButton subtractButton;
private JButton buttonPanel;
//Constructor
public AdderSubtracterFrame(String title)
{
//Set the title of the AdderSubtracterFrame by
//using the superclass JFrame constructor
super();
//Set the JFrame to be a 2*2 Grid
//Set a gap of 5pixels between each row and column.
setLayout(new GridLayout(2,2,5,5));
//Create and instance of the components appearing in the 2*2 grid
num1TextField = new JTextField("0",5);//Begin with 0
num2TextField = new JTextField("0",5);//Begin with 0
resultTextField = new JTextField((5));//Begin empty
buttonPanel = getButtonPanel();
//Add components to 2*2 Grid
add(num1TextField);
add(num2TextField);
add(resultTextField);
add(buttonPanel);
}
//Create and return a panel containing the buttons
private JPanel getButtonPanel()
{
JPanel myPanel = new JPanel();
myPanel.setLayout(new FlowLayout());
//Create an instance of each button
addButton = new JButton("+");
subtractButton = new JButton("-");
clearButton = new JButton("CLEAR");
//Add the 3button to myPanel
myPanel.add(addButton);
myPanel.add(subtractButton);
myPanel.add(clearButton);
return myPanel;
}
}