Results 1 to 20 of 20
  1. #1
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Cannot find symbol

    Hi, I am trying to let my program call another class: A calculator, and I do not know what I am doing wrong, because I keep getting the same error. I want to let the class run that is a calculator when you click on a button. Help please.

    The part of the program:

    private void SakrekenaarMouseClicked(MouseEvent e)
    {
    Calculator cal = new Calculator("Java Swing Calculator");
    }

    The error:

    Lone.java:439: cannot find symbol
    symbol : constructor Calculator(java.lang.String)
    location: class Calculator
    Calculator cal = new Calculator("Java Swing Calculator");
    ^


    PS: please tell my how to paste code in the proper way!

  2. #2
    bayan is offline Member
    Join Date
    Apr 2010
    Posts
    55
    Rep Power
    0

    Default

    Could you please post the calculator class?

    This can be due to three reasons:
    1. The class does not exist
    OR
    2. The class is in a different directory.
    OR
    3. The class name is misspelled in one of the source files
    Make sure you have the two classes in the same directory before you compile and that the Object is the same as the class name.

    Hope this helps

  3. #3
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Quote Originally Posted by bayan View Post
    Could you please post the calculator class?

    This can be due to three reasons:
    1. The class does not exist...
    I checked all that, this is why I am so frustrated.
    Here's the calculator class; I do not know how to paste code if you could maybe help me with that to, I would appreciate it.:)

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.Window;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    import javax.swing.KeyStroke;
    
    public class Calculator extends JFrame implements ActionListener{
    	// Variables
    	final int MAX_INPUT_LENGTH = 20;
    	final int INPUT_MODE = 0;
    	final int RESULT_MODE = 1;
    	final int ERROR_MODE = 2;
    	int displayMode;
    
    	boolean clearOnNextDigit, percent;
    	double lastNumber;
    	String lastOperator;
    
    	private JMenu jmenuFile, jmenuHelp;
    	private JMenuItem jmenuitemExit, jmenuitemAbout;
    	
    	private JLabel jlbOutput;
    	private JButton jbnButtons[];
    	private JPanel jplMaster, jplBackSpace, jplControl;
    	
    	/*
    	 * Font(String name, int style, int size)
          Creates a new Font from the specified name, style and point size.
    	 */
    	
    	Font f12 = new Font("Times New Roman", 0, 12);
    	Font f121 = new Font("Times New Roman", 1, 12);
    	
    	// Constructor 
    	public Calculator() 
    	{
    		/* Set Up the JMenuBar.
    		 * Have Provided All JMenu's with Mnemonics
    		 * Have Provided some JMenuItem components with Keyboard Accelerators
    		 */ 
    		
    		jmenuFile = new JMenu("File");
    		jmenuFile.setFont(f121);
    		jmenuFile.setMnemonic(KeyEvent.VK_F);
    		
    		jmenuitemExit = new JMenuItem("Exit");
    		jmenuitemExit.setFont(f12);
    		jmenuitemExit.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_X, 
    								ActionEvent.CTRL_MASK));
    		jmenuFile.add(jmenuitemExit);
    
    		jmenuHelp = new JMenu("Help");
    		jmenuHelp.setFont(f121);
    		jmenuHelp.setMnemonic(KeyEvent.VK_H);
    
    		jmenuitemAbout = new JMenuItem("About Calculator");
    		jmenuitemAbout.setFont(f12);
    		jmenuHelp.add(jmenuitemAbout);
    		
    		JMenuBar mb = new JMenuBar();
    		mb.add(jmenuFile);
    		mb.add(jmenuHelp);
    		setJMenuBar(mb);
    		
    		//Set frame layout manager
    
    		setBackground(Color.gray);
    
    		jplMaster = new JPanel();
    
    		jlbOutput = new JLabel("0");
    		jlbOutput.setHorizontalTextPosition(JLabel.RIGHT);
    		jlbOutput.setBackground(Color.WHITE);
    		jlbOutput.setOpaque(true);
    		
    		// Add components to frame
    		getContentPane().add(jlbOutput, BorderLayout.NORTH);
    
    		jbnButtons = new JButton[23];
    //		GridLayout(int rows, int cols, int hgap, int vgap) 
    
    		JPanel jplButtons = new JPanel();		// container for Jbuttons
    
    		// Create numeric Jbuttons
    		for (int i=0; i<=9; i++)
    		{
    			// set each Jbutton label to the value of index
    			jbnButtons[i] = new JButton(String.valueOf(i));
    		}
    
    		// Create operator Jbuttons
    		jbnButtons[10] = new JButton("+/-");
    		jbnButtons[11] = new JButton(".");
    		jbnButtons[12] = new JButton("=");
    		jbnButtons[13] = new JButton("/");
    		jbnButtons[14] = new JButton("*");
    		jbnButtons[15] = new JButton("-");
    		jbnButtons[16] = new JButton("+");
    		jbnButtons[17] = new JButton("sqrt");
    		jbnButtons[18] = new JButton("1/x");
    		jbnButtons[19] = new JButton("%");
    		
    		jplBackSpace = new JPanel();
    		jplBackSpace.setLayout(new GridLayout(1, 1, 2, 2));
    
    		jbnButtons[20] = new JButton("Backspace");
    		jplBackSpace.add(jbnButtons[20]);
    
    		jplControl = new JPanel();
    		jplControl.setLayout(new GridLayout(1, 2, 2 ,2));
    
    		jbnButtons[21] = new JButton(" CE ");
    		jbnButtons[22] = new JButton("C");
    
    		jplControl.add(jbnButtons[21]);
    		jplControl.add(jbnButtons[22]);
    
    //		Setting all Numbered JButton's to Blue. The rest to Red
    		for (int i=0; i<jbnButtons.length; i++)	{
    			jbnButtons[i].setFont(f12);
    
    			if (i<10)
    				jbnButtons[i].setForeground(Color.blue);
    				
    			else
    				jbnButtons[i].setForeground(Color.red);
    		}
    	
    		// Set panel layout manager for a 4 by 5 grid
    		jplButtons.setLayout(new GridLayout(4, 5, 2, 2));
    		
    		//Add buttons to keypad panel starting at top left
    		// First row
    		for(int i=7; i<=9; i++)		{
    			jplButtons.add(jbnButtons[i]);
    		}
    		
    		// add button / and sqrt
    		jplButtons.add(jbnButtons[13]);
    		jplButtons.add(jbnButtons[17]);
    		
    		// Second row
    		for(int i=4; i<=6; i++)
    		{
    			jplButtons.add(jbnButtons[i]);
    		}
    		
    		// add button * and x^2
    		jplButtons.add(jbnButtons[14]);
    		jplButtons.add(jbnButtons[18]);
    
    		// Third row
    		for( int i=1; i<=3; i++)
    		{
    			jplButtons.add(jbnButtons[i]);
    		}
    		
    		//adds button - and %
    		jplButtons.add(jbnButtons[15]);
    		jplButtons.add(jbnButtons[19]);
    		
    		//Fourth Row
    		// add 0, +/-, ., +, and =
    		jplButtons.add(jbnButtons[0]);
    		jplButtons.add(jbnButtons[10]);
    		jplButtons.add(jbnButtons[11]);
    		jplButtons.add(jbnButtons[16]);
    		jplButtons.add(jbnButtons[12]);
    		
    		jplMaster.setLayout(new BorderLayout());
    		jplMaster.add(jplBackSpace, BorderLayout.WEST);
    		jplMaster.add(jplControl, BorderLayout.EAST);
    		jplMaster.add(jplButtons, BorderLayout.SOUTH);
    
    		// Add components to frame
    		getContentPane().add(jplMaster, BorderLayout.SOUTH);
    		requestFocus();
    		
    		//activate ActionListener
    		for (int i=0; i<jbnButtons.length; i++){
    			jbnButtons[i].addActionListener(this);
    		}
    		
    		jmenuitemAbout.addActionListener(this);
    		jmenuitemExit.addActionListener(this);
    
    		clearAll();
    
    		//add WindowListener for closing frame and ending program
    		addWindowListener(new WindowAdapter() {
    
    				public void windowClosed(WindowEvent e)
    				{
    					System.exit(0);
    				}
    			}
    		);
    	}	//End of Contructor Calculator
    
    	// Perform action
    	public void actionPerformed(ActionEvent e){
    		double result = 0;
    	   
    		if(e.getSource() == jmenuitemAbout){
    		  JDialog dlgAbout = new CustomABOUTDialog(this, 
    								"About Java Swing Calculator", true);
    			dlgAbout.setVisible(true);
    		}else if(e.getSource() == jmenuitemExit){
    			System.exit(0);
    		}	
    
    		// Search for the button pressed until end of array or key found
    		for (int i=0; i<jbnButtons.length; i++)
    		{
    			if(e.getSource() == jbnButtons[i])
    			{
    				switch(i)
    				{
    					case 0:
    						addDigitToDisplay(i);
    						break;
    
    					case 1:
    						addDigitToDisplay(i);
    						break;
    
    					case 2:
    						addDigitToDisplay(i);
    						break;
    
    					case 3:
    						addDigitToDisplay(i);
    						break;
    
    					case 4:
    						addDigitToDisplay(i);
    						break;
    
    					case 5:
    						addDigitToDisplay(i);
    						break;
    
    					case 6:
    						addDigitToDisplay(i);
    						break;
    
    					case 7:
    						addDigitToDisplay(i);
    						break;
    
    					case 8:
    						addDigitToDisplay(i);
    						break;
    
    					case 9:
    						addDigitToDisplay(i);
    						break;
    
    					case 10:	// +/-
    						processSignChange();
    						break;
    
    					case 11:	// decimal point
    						addDecimalPoint();
    						break;
    
    					case 12:	// =
    						processEquals();
    						break;
    
    					case 13:	// divide
    						processOperator("/");
    						break;
    
    					case 14:	// *
    						processOperator("*");
    						break;
    
    					case 15:	// -
    						processOperator("-");
    						break;
    
    					case 16:	// +
    						processOperator("+");
    						break;
    
    					case 17:	// sqrt
    						if (displayMode != ERROR_MODE)
    						{
    						   try
    							{
    								if (getDisplayString().indexOf("-") == 0)
    								    displayError("Invalid input for function!");
    
    								result = Math.sqrt(getNumberInDisplay());
    								displayResult(result);
    							}
    
    							catch(Exception ex)
    							{
    								displayError("Invalid input for function!");
    								displayMode = ERROR_MODE;
    							}
    						}
    						break;
    
    					case 18:	// 1/x
    						if (displayMode != ERROR_MODE){
    							try
    							{
    								if (getNumberInDisplay() == 0)
    									displayError("Cannot divide by zero!");
    	
    								result = 1 / getNumberInDisplay();
    								displayResult(result);
    							}
    							
    							catch(Exception ex)	{
    								displayError("Cannot divide by zero!");
    								displayMode = ERROR_MODE;
    							}
    						}
    						break;
    
    					case 19:	// %
    						if (displayMode != ERROR_MODE){
    							try	{
    								result = getNumberInDisplay() / 100;
    								displayResult(result);
    							}
    	
    							catch(Exception ex)	{
    								displayError("Invalid input for function!");
    								displayMode = ERROR_MODE;
    							}
    						}
    						break;
    
    					case 20:	// backspace
    						if (displayMode != ERROR_MODE){
    							setDisplayString(getDisplayString().substring(0,
    									  getDisplayString().length() - 1));
    							
    							if (getDisplayString().length() < 1)
    								setDisplayString("0");
    						}
    						break;
    
    					case 21:	// CE
    						clearExisting();
    						break;
    
    					case 22:	// C
    						clearAll();
    						break;
    				}
    			}
    		}
    	}
    
    	void setDisplayString(String s){
    		jlbOutput.setText(s);
    	}
    
    	String getDisplayString (){
    		return jlbOutput.getText();
    	}
    
    	void addDigitToDisplay(int digit){
    		if (clearOnNextDigit)
    			setDisplayString("");
    
    		String inputString = getDisplayString();
    		
    		if (inputString.indexOf("0") == 0){
    			inputString = inputString.substring(1);
    		}
    
    		if ((!inputString.equals("0") || digit > 0)  
    							&& inputString.length() < MAX_INPUT_LENGTH){
    			setDisplayString(inputString + digit);
    		}
    		
    
    		displayMode = INPUT_MODE;
    		clearOnNextDigit = false;
    	}
    
    	void addDecimalPoint(){
    		displayMode = INPUT_MODE;
    
    		if (clearOnNextDigit)
    			setDisplayString("");
    
    		String inputString = getDisplayString();
    	
    		// If the input string already contains a decimal point, don't
    		//  do anything to it.
    		if (inputString.indexOf(".") < 0)
    			setDisplayString(new String(inputString + "."));
    	}
    
    	void processSignChange(){
    		if (displayMode == INPUT_MODE)
    		{
    			String input = getDisplayString();
    
    			if (input.length() > 0 && !input.equals("0"))
    			{
    				if (input.indexOf("-") == 0)
    					setDisplayString(input.substring(1));
    
    				else
    					setDisplayString("-" + input);
    			}
    			
    		}
    
    		else if (displayMode == RESULT_MODE)
    		{
    			double numberInDisplay = getNumberInDisplay();
    		
    			if (numberInDisplay != 0)
    				displayResult(-numberInDisplay);
    		}
    	}
    
    	void clearAll()	{
    		setDisplayString("0");
    		lastOperator = "0";
    		lastNumber = 0;
    		displayMode = INPUT_MODE;
    		clearOnNextDigit = true;
    	}
    
    	void clearExisting(){
    		setDisplayString("0");
    		clearOnNextDigit = true;
    		displayMode = INPUT_MODE;
    	}
    
    	double getNumberInDisplay()	{
    		String input = jlbOutput.getText();
    		return Double.parseDouble(input);
    	}
    
    	void processOperator(String op) {
    		if (displayMode != ERROR_MODE)
    		{
    			double numberInDisplay = getNumberInDisplay();
    
    			if (!lastOperator.equals("0"))	
    			{
    				try
    				{
    					double result = processLastOperator();
    					displayResult(result);
    					lastNumber = result;
    				}
    
    				catch (DivideByZeroException e)
    				{
    				}
    			}
    		
    			else
    			{
    				lastNumber = numberInDisplay;
    			}
    			
    			clearOnNextDigit = true;
    			lastOperator = op;
    		}
    	}
    
    	void processEquals(){
    		double result = 0;
    
    		if (displayMode != ERROR_MODE){
    			try			
    			{
    				result = processLastOperator();
    				displayResult(result);
    			}
    			
    			catch (DivideByZeroException e)	{
    				displayError("Cannot divide by zero!");
    			}
    
    			lastOperator = "0";
    		}
    	}
    
    	double processLastOperator() throws DivideByZeroException {
    		double result = 0;
    		double numberInDisplay = getNumberInDisplay();
    
    		if (lastOperator.equals("/"))
    		{
    			if (numberInDisplay == 0)
    				throw (new DivideByZeroException());
    
    			result = lastNumber / numberInDisplay;
    		}
    			
    		if (lastOperator.equals("*"))
    			result = lastNumber * numberInDisplay;
    
    		if (lastOperator.equals("-"))
    			result = lastNumber - numberInDisplay;
    
    		if (lastOperator.equals("+"))
    			result = lastNumber + numberInDisplay;
    
    		return result;
    	}
    
    	void displayResult(double result){
    		setDisplayString(Double.toString(result));
    		lastNumber = result;
    		displayMode = RESULT_MODE;
    		clearOnNextDigit = true;
    	}
    
    	void displayError(String errorMessage){
    		setDisplayString(errorMessage);
    		lastNumber = 0;
    		displayMode = ERROR_MODE;
    		clearOnNextDigit = true;
    	}
    
    	public static void main(String args[]) {
    		Calculator calci = new Calculator();
    		Container contentPane = calci.getContentPane();
    //		contentPane.setLayout(new BorderLayout());
    		calci.setTitle("Java Swing Calculator");
    		calci.setSize(241, 217);
    		calci.pack();
    		calci.setLocation(400, 250);
    		calci.setVisible(true);
    		calci.setResizable(false);
    	}
    	
    }		//End of Swing Calculator Class.
    
    class DivideByZeroException extends Exception{
    	public DivideByZeroException()
    	{
    		super();
    	}
    	
    	public DivideByZeroException(String s)
    	{
    		super(s);
    	}
    }
    
    class CustomABOUTDialog extends JDialog implements ActionListener {
    	JButton jbnOk;
    
    	CustomABOUTDialog(JFrame parent, String title, boolean modal){
    		super(parent, title, modal);
    		setBackground(Color.black);
    		
    		JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
    
    		StringBuffer text = new StringBuffer();
    		text.append("Calculator Information\n\n");
    		text.append("Developer:	Hemanth\n");
    		text.append("Version:	1.0");
    		
    		JTextArea jtAreaAbout = new JTextArea(5, 21);
    		jtAreaAbout.setText(text.toString());
    		jtAreaAbout.setFont(new Font("Times New Roman", 1, 13));
    		jtAreaAbout.setEditable(false);
    
    		p1.add(jtAreaAbout);
    		p1.setBackground(Color.red);
    		getContentPane().add(p1, BorderLayout.CENTER);
    
    		JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
    		jbnOk = new JButton(" OK ");
    		jbnOk.addActionListener(this);
    
    		p2.add(jbnOk);
    		getContentPane().add(p2, BorderLayout.SOUTH);
    
    		setLocation(408, 270);
    		setResizable(false);
    
    		addWindowListener(new WindowAdapter() {
    				public void windowClosing(WindowEvent e)
    				{
    					Window aboutDialog = e.getWindow();
    					aboutDialog.dispose();
    				}
    			}
    		);
    
    		pack();
    	}
    
    	public void actionPerformed(ActionEvent e)
    	{
    		if(e.getSource() == jbnOk)	{
    			this.dispose();
    		}
    	}
    	
    }
    Last edited by Eranga; 11-04-2010 at 04:31 PM. Reason: code tags added

  4. #4
    bayan is offline Member
    Join Date
    Apr 2010
    Posts
    55
    Rep Power
    0

    Default

    Ah now I see it. Your constructor does not contain a String parameter therefore it cannot identify the constructor, since you passed a string parameter to it.

    Replace your constructor header with this

    Java Code:
    public Calculator(String param){//Code}

  5. #5
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Thanx for the code. I do not understand where to paste it: I tried it and it wouldn't work. In which class should I do it and where? Sorry, I'm still learning

  6. #6
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    I pasted the code you gave me in the right place, but it gives me another error elsewhere in the program. The error is:

    Calculator.java:569: cannot find symbol
    symbol : constructor Calculator()
    location: class Calculator
    Calculator calci = new Calculator();
    ^
    1 error

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Please use code tags next time, when you are posting code segments. Unformated codes are really hard to read.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  9. #9
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default

    Learn to read errors, they really help.

    This time it is looking for a Calculator constructor that doesn't require a String as a parameter. Since you probably just changed your old constructor to accept a String parameter, this is no longer valid. I would say just create another constructor in the Calculator class, but most of your initialization is done in that one. The construction of the GUI should really be moved out of the Constructor calls and into a seperate method.

    Try adding another constructor that doesn't require a String parameter, and have it call the constructor that does.
    Java Code:
         public Calculator() {
              this("DEFAULT");
         }

  10. #10
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Can you tell me how you comes with the error, on which event?
    Sorry, I do not understand what you are asking me.

  11. #11
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Quote Originally Posted by StormyWaters View Post
    Learn to read errors, they really help.

    This time it is looking for a Calculator constructor that doesn't require a String as a parameter...

    Try adding another constructor that doesn't require a String parameter, and have it call the constructor that does.
    Java Code:
         public Calculator() {
              this("DEFAULT");
         }
    StormyWaters, I am really confused on what I must do. Must I, in the calculator class, paste the code?
    Last edited by Johanis; 11-04-2010 at 05:11 PM. Reason: put in a comma

  12. #12
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default

    This is a very basic Java concept.

    In Java, classes are instantiated by calling their constructor methods.
    Java Code:
         //Create a new Calculator object
         Calculator calc = new Calculator();
    The above code assumes there is a constructor inside the Calculator class that accepts no parameters.
    Java Code:
         //Constructor
         public Calculator() {
              super();
              //... your code here
         }
    If you try to instantiate an instance of a class by using a constructor that doesn't exist, you will get the errors you have been seeing.

    In the beginning, you only had one constructor for the Calculator class(It's in the code you pasted above). This constructor did not accept any parameters. If you look at your first error...
    Lone.java:439: cannot find symbol
    symbol : constructor Calculator(java.lang.String)
    location: class Calculator
    Calculator cal = new Calculator("Java Swing Calculator");
    ^
    ...you see that in your Calculator class, at Line 439, you are calling a constructor of the Calculator class that accepts a String as a parameter. Since there is no Calculator constructor created which accepts only a String parameter, it gives you the error.

    As Bayan pointed out, you could get rid of this error by changing the current constructor to accept a String parameter
    Java Code:
         //Constructor
         public Calculator(String param1) {
              super();
              //... your code here
         }
    Since you now have a constructor that requires a String parameter be sent in, the call at Line 439 in your Calculator class is now valid.

    However, you had another line of code somewhere else that was instantiating the Calculator class using a constructor that required no parameters. Since there no longer is a constructor that requires no parameters, you get your second error....
    Calculator.java:569: cannot find symbol
    symbol : constructor Calculator()
    location: class Calculator
    Calculator calci = new Calculator();
    ^
    ... by looking at the error you can see that in your Calculator class, at Line 569, you are instantiating a Calculator object using a constructor that requires no parameters. Since you recently removed this constructor by changing it to require a String parameter, this is no longer valid.


    You need to do one of the following:
    • Change the places where you instantiate the Calculator objects to now pass a String parameter. Since you have a constructor that can handle this, this would be a valid call.
    • Add a constructor to the Calculator class that requires no parameters to be sent. This was the little snippet of code I posted above.

  13. #13
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Thanx you soooo much!! I am very grateful. You realy explained it very good and I understand it completely now! There is just one more problem. When I click on the Sakrekenaar (English=calculator) button in my main program the calculator doesn't appear. Here is the button:
    Java Code:
     private void SakrekenaarMouseClicked(MouseEvent e) 
          {
          Calculator cal = new Calculator("Java Swing Calculator");  		  
          }
    How am I suppose to do this?

  14. #14
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default

    You are creating the Calculator object, but are you ever setting it visible?

  15. #15
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    How do I do that? I tried this
    Java Code:
    private void SakrekenaarMouseClicked(MouseEvent e) 
          {
             Calculator cal = new Calculator("Java Swing Calculator");
             
          	initComponents();
             cal.setVisible(true);  		  
          }
    but it still does not work, its only gives me a small window.
    Last edited by Johanis; 11-04-2010 at 07:12 PM. Reason: added code

  16. #16
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    have you packed the calculator?
    Java Code:
    cal.pack();

  17. #17
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default

    Look at your main method inside the Caculator class. How did you get it to display there?

    Try replicating that inside the mouseClicked event.

  18. #18
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Quote Originally Posted by berkeleybross View Post
    have you packed the calculator?
    Java Code:
    cal.pack();
    Thanx, it works finaly!!

  19. #19
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Quote Originally Posted by StormyWaters View Post
    Look at your main method inside the Caculator class...
    Thank you that also works! And thank you for all your help!! Its a pity I can't rep you more than once in a row ;) haha Nice eveninge to you both!

  20. #20
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

Similar Threads

  1. Cannot find symbol
    By SarahB in forum New To Java
    Replies: 0
    Last Post: 03-06-2010, 03:03 PM
  2. Can not find symbol ???
    By AliceNewbie in forum New To Java
    Replies: 1
    Last Post: 02-17-2010, 01:44 AM
  3. cannot find symbol
    By GabWit in forum New To Java
    Replies: 3
    Last Post: 01-25-2009, 12:13 AM
  4. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •