Results 1 to 11 of 11
  1. #1
    cc11rocks is offline Member
    Join Date
    Jan 2011
    Posts
    49
    Rep Power
    0

    Default 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:
    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();
    }
    }
    RiskApp.java:
    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 errors I am getting are:
    Java Code:
    Risk.java:19: cannot find symbol
    symbol: variable nucker
    location: class Risk
    JTextField sucker = new JText Field(nucker);
    the carrot (i'm using Cmd Promp) is pointed to the "n" in "nucker"
    Another error:
    Java Code:
    Risk.java:24: cannot find symbol
    symbol: yucker
    location: class Risk
    JTextField lucker = new JText Field(yucker);
    the carrot is pointed to the "y" in "yucker"
    Another error:
    Java Code:
    Risk.java:31: cannot find symbol
    symbol : variable yucker
    location: class Risk
    yucker = NumberFormat.getNumberInstance();
    The carrot is pointed to the "y" in "yucker"
    And finally:
    Java Code:
    Risk.java:32: cannot find symbol
    symbol : variable nucker
    location: class Risk
    nucker = NumberFormat.getNumberInstance();
    With the Carrot pointed to the "n" in "nucker"
    If you know how to fix these errors please show and/or tell me how.
    Thank you very much,
    cc11rocks

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Perhaps I am missing it but I do not see where you declared nucker and yucker, I only see you assigning them.

  3. #3
    cc11rocks is offline Member
    Join Date
    Jan 2011
    Posts
    49
    Rep Power
    0

    Default What do I declare them to be?

    What do I declare them to be?
    Thanks,
    cc11rocks

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Im not quite sure, what do you intend for them to be?

  5. #5
    cc11rocks is offline Member
    Join Date
    Jan 2011
    Posts
    49
    Rep Power
    0

    Default Answer to question

    private void setUpFormats() {
    yucker = NumberFormat.getNumberInstance();
    nucker = NumberFormat.getNumberInstance();
    }
    }

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    NumberFormat (Java 2 Platform SE v1.4.2)

    Looks like you want
    Java Code:
    NumberFormat yucker = NumberFormat.getNumberInstance();

  7. #7
    cc11rocks is offline Member
    Join Date
    Jan 2011
    Posts
    49
    Rep Power
    0

    Default Those errors fixed, two more created

    Here is the new risk with the new errors:
    Risk.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;
    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);
    	
        }
    }
    New errors created (old ones fixed):
    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);
    the carrot is pointed towards the "n" in "new"
    Thanks for your help,
    cc11rock
    Last edited by cc11rocks; 02-06-2011 at 02:41 AM.

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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
    Java Code:
    public NumberFormat sucker;
    public NumberFormat lucker;
    Then in the constructor you say
    Java Code:
    JTextField sucker = new JTextField(nucker);
    JTextField lucker = new JTextField(yucker);
    Last edited by sunde887; 02-06-2011 at 02:43 AM.

  9. #9
    cc11rocks is offline Member
    Join Date
    Jan 2011
    Posts
    49
    Rep Power
    0

    Default

    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:
    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);
    	
        }
    }
    RiskApp.java is the same.
    I get the same errors when i try to add the number 2 to :
    Java Code:
    JFormattedTextField yummy = new JFormattedTextField(yucker);
    so it would look like:
    Java Code:
    JFormattedTextField yummy = new JFormattedTextField(yucker, 2);
    and it'll display those 2 errors i had earlier.
    Could you please help me with these?
    Thanks,
    cc11rocks
    Last edited by cc11rocks; 02-06-2011 at 03:29 AM.

  10. #10
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    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.

  11. #11
    cc11rocks is offline Member
    Join Date
    Jan 2011
    Posts
    49
    Rep Power
    0

    Default 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
    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);
    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);
    	
        }
    }
    and here is RiskApp.java
    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();
                }
            });
        }
    }
    Now I have to work on the "enter" button and everything. Expect to see me in the Swing/AWT forum to figure out that.
    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,
    cc11rocks
    Last edited by cc11rocks; 02-06-2011 at 04:24 AM.

Similar Threads

  1. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  2. how do you actually define a method?
    By edelric666 in forum New To Java
    Replies: 3
    Last Post: 10-30-2010, 11:26 PM
  3. define a variable
    By jperson in forum New To Java
    Replies: 2
    Last Post: 01-29-2010, 03:33 AM
  4. Define this error.
    By jaicea in forum New To Java
    Replies: 3
    Last Post: 12-02-2009, 02:07 AM
  5. Replies: 3
    Last Post: 03-08-2009, 02:51 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
  •