Results 1 to 11 of 11
- 02-06-2011, 12:30 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 49
- Rep Power
- 0
4 errors, probably need to import or define something
I am making a GUI. I just have four simple errors (that i probably need to import something for). I am using two files, "Risk.java" and "RiskApp.java".
Risk.java:
RiskApp.java:Java Code:import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.text.*; import java.text.NumberFormat; public class Risk extends JPanel { int leftNumber = 0; int rightNumber = 0; public JButton enter; public JTextField stupid, yummy; public JLabel smart, dumb; public NumberFormat sucker; public NumberFormat lucker; public Risk() { JLabel smart = new JLabel("First Number:"); add(smart); JTextField sucker = new JTextField(nucker); add(sucker); boolean isDigit; JLabel dumb = new JLabel("Second Number:"); add(dumb); JTextField lucker = new JTextField(yucker); add(lucker); enter = new JButton("Enter"); add(enter); } private void setUpFormats() { yucker = NumberFormat.getNumberInstance(); nucker = NumberFormat.getNumberInstance(); } }
The errors I am getting are:Java Code:import javax.swing.*; public class RiskApp { private static void createAndShowGUI() { JFrame frame = new JFrame("Risk"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Risk riskPanel = new Risk(); frame.getContentPane().add(riskPanel); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
the carrot (i'm using Cmd Promp) is pointed to the "n" in "nucker"Java Code:Risk.java:19: cannot find symbol symbol: variable nucker location: class Risk JTextField sucker = new JText Field(nucker);
Another error:
the carrot is pointed to the "y" in "yucker"Java Code:Risk.java:24: cannot find symbol symbol: yucker location: class Risk JTextField lucker = new JText Field(yucker);
Another error:
The carrot is pointed to the "y" in "yucker"Java Code:Risk.java:31: cannot find symbol symbol : variable yucker location: class Risk yucker = NumberFormat.getNumberInstance();
And finally:
With the Carrot pointed to the "n" in "nucker"Java Code:Risk.java:32: cannot find symbol symbol : variable nucker location: class Risk nucker = NumberFormat.getNumberInstance();
If you know how to fix these errors please show and/or tell me how.
Thank you very much,
cc11rocks
- 02-06-2011, 01:11 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Perhaps I am missing it but I do not see where you declared nucker and yucker, I only see you assigning them.
- 02-06-2011, 01:15 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 49
- Rep Power
- 0
What do I declare them to be?
What do I declare them to be?
Thanks,
cc11rocks
- 02-06-2011, 01:16 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Im not quite sure, what do you intend for them to be?
- 02-06-2011, 01:19 AM #5
Member
- Join Date
- Jan 2011
- Posts
- 49
- Rep Power
- 0
Answer to question
private void setUpFormats() {
yucker = NumberFormat.getNumberInstance();
nucker = NumberFormat.getNumberInstance();
}
}
- 02-06-2011, 01:23 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
NumberFormat (Java 2 Platform SE v1.4.2)
Looks like you want
Java Code:NumberFormat yucker = NumberFormat.getNumberInstance();
- 02-06-2011, 01:31 AM #7
Member
- Join Date
- Jan 2011
- Posts
- 49
- Rep Power
- 0
Those errors fixed, two more created
Here is the new risk with the new errors:
Risk.java:
New errors created (old ones fixed):Java Code:import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.text.*; import java.text.NumberFormat; public class Risk extends JPanel { int leftNumber = 0; int rightNumber = 0; public JButton enter; public JTextField stupid, yummy; public JLabel smart, dumb; NumberFormat yucker = NumberFormat.getNumberInstance(); NumberFormat nucker = NumberFormat.getNumberInstance(); public Risk() { JLabel smart = new JLabel("First Number:"); add(smart); JTextField sucker = new JTextField(nucker); add(sucker); boolean isDigit; JLabel dumb = new JLabel("Second Number:"); add(dumb); JTextField lucker = new JTextField(yucker); add(lucker); enter = new JButton("Enter"); add(enter); } }
the carrot is pointed towards the "n" in "new"Java Code:Risk.java:19: cannot find symbol symbol : constructer JTextField(java.text.NumberFormat) location: class javax.swing.JTextField JTextField sucker = new JTextField(nucker);
the carrot is pointed towards the "n" in "new"Java Code:Risk.java:24: cannot find symbol symbol : constructor JTextField(java.text.NumberFormat) location: class javax.swing.JTextField JTextField lucker = new JTextField(yucker);
Thanks for your help,
cc11rockLast edited by cc11rocks; 02-06-2011 at 01:41 AM.
- 02-06-2011, 01:40 AM #8
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Why are you setting the number formats up in a private method but not calling it? What is the point of this method? Also, not to be rude, but, are you trying to figure this out yourself before posting? Take some time and think about the error. If after 30-40 minutes you can't figure it out, come here. You won't learn if we tell you what to fix. There are some other weird things in this code that you should take a minute to think about
in the beginning you declare
Then in the constructor you sayJava Code:public NumberFormat sucker; public NumberFormat lucker;
Java Code:JTextField sucker = new JTextField(nucker); JTextField lucker = new JTextField(yucker);
Last edited by sunde887; 02-06-2011 at 01:43 AM.
- 02-06-2011, 02:22 AM #9
Member
- Join Date
- Jan 2011
- Posts
- 49
- Rep Power
- 0
I'm onto something. I got it to run, but I need to make the JFormattedTextField to have multiple columns, not 0. Here is the working code that I suspect works, but I can't test it until I have multiple columns. i tried to add columns, but it return the errors when i try to.
Risk.java:
RiskApp.java is the same.Java Code:import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JFormattedTextField; import javax.swing.JLabel; import java.text.NumberFormat; public class Risk extends JPanel { public JButton enter; public JFormattedTextField stupid, yummy; public JLabel smart, dumb; public NumberFormat yucker = NumberFormat.getNumberInstance(); public NumberFormat nucker = NumberFormat.getNumberInstance(); public Risk() { JLabel smart = new JLabel("First Number:"); add(smart); JFormattedTextField stupid = new JFormattedTextField(yucker); add(stupid); boolean isDigit; JLabel dumb = new JLabel("Second Number:"); add(dumb); JFormattedTextField yummy = new JFormattedTextField(nucker); add(yummy); enter = new JButton("Enter"); add(enter); } }
I get the same errors when i try to add the number 2 to :
so it would look like:Java Code:JFormattedTextField yummy = new JFormattedTextField(yucker);
and it'll display those 2 errors i had earlier.Java Code:JFormattedTextField yummy = new JFormattedTextField(yucker, 2);
Could you please help me with these?
Thanks,
cc11rocksLast edited by cc11rocks; 02-06-2011 at 02:29 AM.
- 02-06-2011, 03:00 AM #10
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
JFormattedTextField inherits the setColumns() method of JTextField. Try that.
Keep the API docs open in your browser because you can't guess at what a method or constructor will do.
- 02-06-2011, 03:21 AM #11
Member
- Join Date
- Jan 2011
- Posts
- 49
- Rep Power
- 0
Thank you and working code.
Thank you so much. It works perfectly now. For anyone who wants to see my working code, here it is:
Risk.java
and here is RiskApp.javaJava Code:import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JFormattedTextField; import javax.swing.JLabel; import java.text.NumberFormat; public class Risk extends JPanel { public JButton enter; public JFormattedTextField stupid, yummy; public JLabel smart, dumb; public NumberFormat yucker = NumberFormat.getNumberInstance(); public NumberFormat nucker = NumberFormat.getNumberInstance(); public Risk() { JLabel smart = new JLabel("First Number:"); add(smart); JFormattedTextField stupid = new JFormattedTextField(yucker); stupid.setColumns(3); add(stupid); boolean isDigit; JLabel dumb = new JLabel("Second Number:"); add(dumb); JFormattedTextField yummy = new JFormattedTextField(nucker); yummy.setColumns(3); add(yummy); enter = new JButton("Enter"); add(enter); } }
Now I have to work on the "enter" button and everything. Expect to see me in the Swing/AWT forum to figure out that.Java Code:import javax.swing.*; import java.text.NumberFormat; public class RiskApp { private static void createAndShowGUI() { JFrame frame = new JFrame("Risk"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Risk riskPanel = new Risk(); frame.getContentPane().add(riskPanel); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
Thanks to everyone who helped. I really appreshiate it. I do have one question. What API book thing were you talking about? I know what the API is, but I don't have an API book so what do I do?
Thanks to everyone,
cc11rocksLast edited by cc11rocks; 02-06-2011 at 03:24 AM.
Similar Threads
-
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
how do you actually define a method?
By edelric666 in forum New To JavaReplies: 3Last Post: 10-30-2010, 10:26 PM -
define a variable
By jperson in forum New To JavaReplies: 2Last Post: 01-29-2010, 02:33 AM -
Define this error.
By jaicea in forum New To JavaReplies: 3Last Post: 12-02-2009, 01:07 AM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks