Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2010
    Location
    Troy Upstate New York USA (Not in New York City)
    Posts
    25
    Rep Power
    0

    Default getText(); problem

    I cannot seem to get my getText() and setText to work it throws these errors:

    C:\Users\Kyle\Documents\CoilGunOctogon25.java:50: cannot find symbol
    symbol : method getText()
    location: class test String input = test.getText();

    C:\Users\Kyle\Documents\CoilGunOctogon25.java:50: cannot find symbol
    symbol : method getText()
    location: class test
    String input = test.getText();

    C:\Users\Kyle\Documents\CoilGunOctogon25.java:50: cannot find symbol
    symbol : method getText()
    location: class test
    String input = test.getText();

    C:\Users\Kyle\Documents\CoilGunOctogon25.java:50: cannot find symbol
    symbol : method getText()
    location: class test
    String input = test.getText();


    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.geom.*;
    import java.io.*;
    
    
    
    public class CoiGOctogon25 extends JApplet implements ActionListener
    {
    	public void init()
    	{
    		int  appwidth, appheight, inputheight, inputwidth, startingpoint;
    		//add in a dynamic meathod binding array
    		JPanel Octogon_Panel = new JPanel();
    		JTextField test = new JTextField();
    		appwidth = getSize().width;
    		appheight = getSize().height;
    		inputheight = (int)(appheight * .33);
    		inputwidth = appwidth;
    		startingpoint = appheight - inputheight;
    		Container c = getContentPane();
    		c.setBackground(Color.lightGray);
    		Octogon_Panel.setLocation((startingpoint + 36), 0);
    		c.add(Octogon_Panel);
    		Octogon_Panel.repaint();
    		test.setSize(inputheight, inputwidth);
    		test.setLocation(startingpoint, 0);
    		test.setText("vvcgmki~: ");
    		test.setForeground(Color.green);
    		test.setBackground(Color.black);
    		c.add(test);
    		test.addActionListener(this);
    	}
    
    	public void actionPerformed(ActionEvent e)
    	{
    		String input = test.getText();
    		test.setText("Input Sucessful");
    		test.setText(input);
    
    	}
    
    
    
    	public void paintComponent(Graphics g)
    	{
    		super.paintComponent(g);
    		Graphics2D g2 = (Graphics2D)g;
    		g2.setColor(Color.green);
    		int x, y, pass = 0;
    		BasicStroke b;
    		b = new BasicStroke(2, BasicStroke.CAP_ROUND,
    		 					BasicStroke.JOIN_ROUND);
    		g2.setStroke(b);
    
    
    		if (pass == 0)
    		{
    			Rectangle2D.Float subset = new Rectangle2D.Float(36, 36, 144, 144);
    				//stand in for the Jframe that willeventually be there
    			g2.draw(subset);
    
    
    			GeneralPath triangleA;
    			GeneralPath triangleB;
    			GeneralPath triangleC;
    			GeneralPath triangleD;
    
    
    			triangleA = new GeneralPath();
    			triangleB = new GeneralPath();
    			triangleC = new GeneralPath();
    			triangleD = new GeneralPath();
    
    			triangleA.moveTo(36,36);
    			triangleA.lineTo(0, 108);//triangle 1
    			triangleA.lineTo(36, 180);
    			triangleA.closePath();
    			g2.fill(triangleA);
    
    
    			triangleB.moveTo(36,180);
    			triangleB.lineTo(108, 216);//triangle 2
    			triangleB.lineTo(180, 180);
    			triangleB.closePath();
    			g2.fill(triangleB);
    
    
    			triangleC.moveTo(180,180);
    			triangleC.lineTo(216,108);//triangle 3
    			triangleC.lineTo(180, 36);
    			triangleC.closePath();
    			g2.fill(triangleC);
    
    
    			triangleD.moveTo(36,36);
    			triangleD.lineTo(180,36);//triangle 4
    			triangleD.lineTo(108,0);
    			triangleD.closePath();
    			g2.fill(triangleD);
    
    			pass = 1;
    		}
    
    	}
    }
    You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by The_Sponzy_Paradox View Post
    I cannot seem to get my getText() and setText to work it throws these errors:
    Read up on scope of variables. Where do you declare the test variable? Based on this, where is the only place that the test variable is visible? If you want test to be visible in other methods of the class, where should it be declared?

    Please let me know if this does or doesn't make sense.

    Best of luck!

  3. #3
    Join Date
    Mar 2010
    Location
    Troy Upstate New York USA (Not in New York City)
    Posts
    25
    Rep Power
    0

    Default

    I declared the variable in my init() method I think so umm I cant say it makes much sense to me:confused:. That is why I am confused as to why it does not seem to function

    here is all the references to the code:
    Java Code:
    public void init()
    JTextField test = new JTextField();
    //blah
    test.setSize(inputheight, inputwidth);
    test.setLocation(startingpoint, 0);
    test.setText("vvcgmki~: ");
    test.setForeground(Color.green);
    test.setBackground(Color.black);
    c.add(test);
    test.addActionListener(this);
    
    public void actionPerformed(ActionEvent e)
    	{
    		String input = test.getText();
    		test.setText("Input Sucessful");
    		test.setText(input);
    
    	}
    You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please look at the code and comments here. Does this help you understand things better?

    Java Code:
    public class Fubar {
      // this guy is visible throughout the class
      private int privateClassVar = 0;
      
      public void methodA() {
        // this guy is *only* visible inside of methodA
        int methodAVar = 0;
      }
      
      public void methodB() {
        System.out.println(privateClassVar);  // no problem here
        System.out.println(methodAVar);  // BIG problem here!
                                      // methodB cannot see the var
                                      // that is hidden inside of methodA
      }
    }

  5. #5
    Join Date
    Mar 2010
    Location
    Troy Upstate New York USA (Not in New York City)
    Posts
    25
    Rep Power
    0

    Default

    So I need to do something like this:

    Java Code:
    public class CoiGOctogon25 extends JApplet implements ActionListener
    {
    		int  appwidth, appheight, inputheight, inputwidth, startingpoint;
    		//add in a dynamic meathod binding array
    		JPanel Octogon_Panel = new JPanel();
    		JTextField test = new JTextField();
    		appwidth = getSize().width;
    		appheight = getSize().height;
    		inputheight = (int)(appheight * .33);
    		inputwidth = appwidth;
    		startingpoint = appheight - inputheight;
    		Container c;
    
    	public void init()
    	{
    		c.getContentPane();
    		c.setBackground(Color.lightGray);
    		Octogon_Panel.setLocation((startingpoint + 36), 0);
    		c.add(Octogon_Panel);
    		Octogon_Panel.repaint();
    		test.setSize(inputheight, inputwidth);
    		test.setLocation(startingpoint, 0);
    		test.setText("vvcgmki~: ");
    		test.setForeground(Color.green);
    		test.setBackground(Color.black);
    		c.add(test);
    		test.addActionListener(this);
    	}
    
    	public void actionPerformed(ActionEvent e)
    	{
    		String input = test.getText();
    		test.setText("Input Sucessful");
    		test.setText(input);
    
    	}
    I still get this error:

    C:\Users\Kyle\Documents\CoilGunOctogon25.java:29: <identifier> expected
    appwidth = getSize().width;

    what is the identifier that it is talking about
    You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You can declare variables in the class and outside of methods/constructors, but that's about it. You can't do statements like that outside of methods/constructors/etc.

    Applets are no different from other classes in this regard.

Similar Threads

  1. What format is a getText()?
    By AJArmstron@aol.com in forum New To Java
    Replies: 1
    Last Post: 04-18-2010, 01:43 AM
  2. gettext problems
    By gisler in forum AWT / Swing
    Replies: 3
    Last Post: 12-01-2009, 07:35 PM
  3. how to getText() properly?
    By javamula in forum New To Java
    Replies: 12
    Last Post: 09-16-2009, 05:45 AM
  4. [SOLVED] new2java- gettext settext
    By obdi in forum New To Java
    Replies: 4
    Last Post: 07-21-2008, 09:28 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
  •