Results 1 to 6 of 6
Thread: getText(); problem
- 04-22-2010, 01:02 AM #1
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
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.
-
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!
- 04-22-2010, 01:52 AM #3
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
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.
-
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 } }
- 04-22-2010, 03:00 AM #5
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
So I need to do something like this:
I still get this error: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); }
C:\Users\Kyle\Documents\CoilGunOctogon25.java:29: <identifier> expected
appwidth = getSize().width;
what is the identifier that it is talking aboutYou know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
-
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
-
What format is a getText()?
By AJArmstron@aol.com in forum New To JavaReplies: 1Last Post: 04-18-2010, 01:43 AM -
gettext problems
By gisler in forum AWT / SwingReplies: 3Last Post: 12-01-2009, 07:35 PM -
how to getText() properly?
By javamula in forum New To JavaReplies: 12Last Post: 09-16-2009, 05:45 AM -
[SOLVED] new2java- gettext settext
By obdi in forum New To JavaReplies: 4Last Post: 07-21-2008, 09:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks