using the setText() method - getting error cannot find symbol

Reply

Join Date: Mar 2008
Posts: 12
Reputation: rickilambert is an unknown quantity at this point 
Solved Threads: 0
rickilambert rickilambert is offline Offline
Newbie Poster

using the setText() method - getting error cannot find symbol

 
0
  #1
Mar 13th, 2008
ok, im trying to use the set text method and the code im using it on looks as follows;

  1. /** Convert the stringbuilder into an actual string, then return it */
  2. String completeMatchList = matchList.toString();
  3. String [] splitresult;
  4. String name = matchList.toString();
  5. splitresult= name.split("\\s");
  6. //txtbgreenentry.setText(splitresult[0]);
  7. //txtbyellowentry.setText(splitresult[0]);
  8. /** System.out.println(splitresult[5]); - this was added to test that the text has been broken down in to individual strings, then it prints off in an array to the console */
  9. for (int i = 0; i < 18; i++)
  10. {
  11. sd.getyh(i).getEmptyMatches();
  12. sd.getgh(i).getEmptyMatches();
  13. }
  14. return completeMatchList;
where the two names for the text areas are txtbgreenentry and txtbyellowentry, im under the assumption that i need to use

txtbgreenentry.setText(splitresult[0]);

but the problem is i am getting the error cannot find symbol variable txtbgreenentry, how can i fix this? is the problem to do with my actionlistener code? does it need to call the setetxt method and if so how do ido this? all my code (for the 2 classes of issue at least)
are below

matchlist
  1. public class Matchlist
  2. {
  3.  
  4. private studentdetails sd = new studentdetails();
  5. /** matchList StringBuilder stores the match list in progress */
  6. private StringBuilder matchList = new StringBuilder();
  7.  
  8. private int loop = 0;
  9. private int matches = 0;
  10. public Matchlist()
  11. {
  12. sd.createstudentdetails();
  13. }
  14.  
  15. /** Method to create the actual match list, returns the list as a string */
  16. public String CreateMatch()
  17. {
  18. int g;
  19. int y;
  20.  
  21. for (g = 0; g < 4; g++) /** this is for the game */
  22. {
  23. for (y = 17; y > -1; y--) /** used for the yellow house */
  24. {
  25. /** Check to see if the game is empty */
  26. if (sd.getgh(y).getGame(g).equals(""))
  27. {
  28. for (int x = 0; x < 18; x++) /** used for the yellow house */
  29. {
  30. if (sd.getyh(x).getGame(g).equals(""))
  31. {
  32. if (sd.getgh(y).getC_lass() != sd.getyh(x).getC_lass()) /** used for the green house */
  33. {
  34. /** Check to see if the person has played the other person */
  35. if (sd.getgh(y).checkPlayed(sd.getyh(x).getName()) == false)
  36. {
  37. /** Set the game to the name of the opponent played */
  38. sd.getyh(x).changeGame(g, sd.getgh(y).getName());
  39. sd.getgh(y).changeGame(g, sd.getyh(x).getName());
  40. /** Build the match list step by step using append with \n at the end to create a new line */
  41. matchList.append(sd.getyh(x).getName() + " vs " + sd.getgh(y).getName() +"\n");
  42. matches++; /** add to the matches */
  43. break;
  44. }
  45.  
  46. }
  47.  
  48. }
  49. }
  50. }
  51. }
  52.  
  53. }
  54. /** Convert the stringbuilder into an actual string, then return it */
  55. String completeMatchList = matchList.toString();
  56. String [] splitresult;
  57. String name = matchList.toString();
  58. splitresult= name.split("\\s");
  59. //txtbdisplaymatch.setText(splitresult[0]);
  60. txtbyellowentry.setText(splitresult[0]);
  61. /** System.out.println(splitresult[5]); - this was added to test that the text has been broken down in to individual strings, then it prints off in an array to the console */
  62. for (int i = 0; i < 18; i++)
  63. {
  64. sd.getyh(i).getEmptyMatches();
  65. sd.getgh(i).getEmptyMatches();
  66. }
  67.  
  68. return completeMatchList; /** returns the match list that has been completed */
  69. }
  70. }
interface
  1. a
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5. import javax.swing.event.*;
  6.  
  7. public class MyPanel extends JPanel implements ActionListener
  8. { //add the "implements ActionListener" line so the class knows its going to take an input
  9.  
  10. private Matchlist ml = new Matchlist();
  11. private JButton btngenerate;
  12. public JTextArea txtbdisplaymatch;
  13. private JLabel lblvs;
  14. private JLabel lblgreenhouse;
  15. private JLabel lblyellowhouse;
  16. private JLabel lblname;
  17. private JTextField txtbgreenentry;
  18. private JTextField txtbyellowentry;
  19. private JTextField txtbenterscoreg;
  20. private JTextField txtbenterscorey;
  21. private JButton btnfinalresults;
  22. private JScrollPane scrollpane;
  23. private JLabel lblcurrentscore;
  24. private JTextField txtbcurrentgs;
  25. private JTextField txtbcurrentys;
  26.  
  27.  
  28. public MyPanel()
  29. {
  30. //construct components
  31.  
  32. btngenerate = new JButton("Generate Match List");
  33. txtbdisplaymatch = new JTextArea(5, 5);
  34. scrollpane = new javax.swing.JScrollPane(txtbdisplaymatch);
  35. scrollpane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
  36. lblvs = new JLabel(" vs");
  37. lblgreenhouse = new JLabel(" Green House");
  38. lblyellowhouse = new JLabel(" Yellow House");
  39. lblname = new JLabel(" Name");
  40. txtbgreenentry = new JTextField(5);
  41. txtbyellowentry = new JTextField(5);
  42. txtbenterscoreg = new JTextField(5);
  43. txtbenterscorey = new JTextField(5);
  44. btnfinalresults = new JButton("Enter Match Score");
  45. lblcurrentscore = new JLabel ("Current Score");
  46. txtbcurrentgs = new JTextField (5);
  47. txtbcurrentys = new JTextField (5);
  48.  
  49. //adjust size and set layout
  50. setPreferredSize(new Dimension(542, 542));
  51. setLayout(null);
  52.  
  53. //add components
  54. add(btngenerate);
  55. add(scrollpane);
  56. add(lblvs);
  57. add(lblgreenhouse);
  58. add(lblyellowhouse);
  59. add(lblname);
  60. add(txtbgreenentry);
  61. add(txtbyellowentry);
  62. add(txtbenterscoreg);
  63. add(txtbenterscorey);
  64. add(btnfinalresults);
  65. add(lblcurrentscore);
  66. add(txtbcurrentgs);
  67. add(txtbcurrentys);
  68.  
  69. //set component bounds (only needed by Absolute Positioning)
  70. btngenerate.setBounds(185, 25, 165, 20);
  71. scrollpane.setBounds(60, 70, 415, 320); /**Changed it from setting the bounds on the textarea to setting them on the scrollpane */
  72. lblvs.setBounds(285, 415, 25, 25);
  73. lblgreenhouse.setBounds(385, 415, 100, 25);
  74. lblyellowhouse.setBounds(120, 415, 100, 25);
  75. lblname.setBounds(30, 445, 45, 25);
  76. txtbgreenentry.setBounds(75, 445, 155, 20);
  77. txtbyellowentry.setBounds(355, 445, 155, 20);
  78. txtbenterscoreg.setBounds(235, 445, 20, 20);
  79. txtbenterscorey.setBounds(330, 445, 20, 20);
  80. btnfinalresults.setBounds(185, 495, 205, 25);
  81. lblcurrentscore.setBounds(245, 560, 205, 25);
  82. txtbcurrentgs.setBounds(150, 580, 25, 25);
  83. txtbcurrentys.setBounds(390, 580, 25, 25);
  84.  
  85.  
  86.  
  87. //add action listener
  88. btngenerate.addActionListener(this); //use the components name and use the ".addActionListener()" method to enable this component to take inputs
  89.  
  90. }
  91.  
  92. public void actionPerformed(ActionEvent e)
  93. {//create a method called actionPerformed, this method will contain the code which is run when the component is pressed.
  94.  
  95. if (e.getSource() == btngenerate)
  96. { //use the getSource() method and use it to see if it is equal to the compoenent.
  97. txtbdisplaymatch.setText(ml.CreateMatch()); //use the setText() method to add text from variable a to the txtbdisplaymatch which will display in the text area when the generate button is pressed.
  98. }
  99. }
  100.  
  101. public static void main(String[] args)
  102. {
  103. JFrame frame = new JFrame("MyPanel");
  104. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  105. frame.getContentPane().add(new MyPanel());
  106. frame.pack();
  107. frame.setVisible(true);
  108. }
  109. }
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: using the setText() method - getting error cannot find symbol

 
0
  #2
Mar 13th, 2008
Those text fields are in another class. You can't just access private variables in another class. Matchlist shouldn't be setting those values directly anyway. The interface should call methods on MatchList to get results and then set the text in it's text fields as needed.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 12
Reputation: rickilambert is an unknown quantity at this point 
Solved Threads: 0
rickilambert rickilambert is offline Offline
Newbie Poster

Re: using the setText() method - getting error cannot find symbol

 
0
  #3
Mar 13th, 2008
well i have chnaged the txtb boxes to public and still the same problem, what do i need to change?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: using the setText() method - getting error cannot find symbol

 
0
  #4
Mar 13th, 2008
You still have no reference to that instance, so whether they are public or private makes no difference. You can't call methods on objects you don't have a reference to.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 12
Reputation: rickilambert is an unknown quantity at this point 
Solved Threads: 0
rickilambert rickilambert is offline Offline
Newbie Poster

Re: using the setText() method - getting error cannot find symbol

 
0
  #5
Mar 13th, 2008
ao in my matchlist class i need

public MyPanel mp = new MyPanel();
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: using the setText() method - getting error cannot find symbol

 
0
  #6
Mar 13th, 2008
No, actually your matchlist class has nothing at all to do with the interface. If you are going to separate them, make sure you know why and what each of them is supposed to do.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC