Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    41
    Rep Power
    10

    "'.class' expected" - Says BlueJ


    I'm new to java and I am trying to make a program that adds the number 9 to the end of the textbox every second. I copied the code from various places and pasted it together. I think the majority is okay. I get a "'.class' expected" error on line seventeen. I am using BlueJ and java Tiger to compile. Anyway here is the code...

    Code:
    import java.awt.*;
    import javax.swing.*;
    public class GUI {
        public static void main(String[] Args){
            JFrame frame = new JFrame("Nine");
            frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
            frame.setResizable(false);
            frame.setBounds(265, 100, 535, 291);
            JPanel panel = new JPanel();
            JTextArea Nine = new JTextArea("999999999", 15, 47);
            Nine.setLineWrap(true);
            Nine.setWrapStyleWord(false);
            Nine.setEditable(false);
            JScrollPane ScrollNine = new JScrollPane(Nine);
            panel.add(ScrollNine);
            frame.setContentPane(panel);
            javax.swing.Timer TimerNine = new javax.swing.Timer(int 1000, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Nine.append(9);
                }
            });
            frame.setVisible(true);
            TimerNine.start();
        }
    }
    I am not sure if I need to import more things or what. Any help would be appreciated, thanks.
    Last edited by sound7; May 13th, 2005 at 10:44 AM. Reason: adding code tags
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,575
    Rep Power
    1906
    to use ActionListener you have to use
    Code:
    import java.awt.event.*
    when you append 9, it should be as a string
    Code:
    Nine.append("9");
  4. #3
  5. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5053
    When you post code, please post it between [code] and [/code] tags (you can use the "code" button on the message posting screen). It makes your code much easier to read and prevents accidental markup from the forum software.

    Also, please follow the standard Code Conventions for the Java Programming Language.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    41
    Rep Power
    10
    Here is it in code tags now, I added the things, but I still get the same error. "'.class' expected" I get it on this line.

    Code:
            javax.swing.Timer TimerNine = new javax.swing.Timer(int 1000, new ActionListener() {
    Here is the code surrounding it.

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Gui {
        public static void main(String[] Args){
            JFrame frame = new JFrame("Nine");
            frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
            frame.setResizable(false);
            frame.setBounds(265, 100, 535, 291);
            JPanel panel = new JPanel();
            
            JTextArea Nine = new JTextArea("999999999", 15, 47);
            Nine.setLineWrap(true);
            Nine.setWrapStyleWord(false);
            Nine.setEditable(false);
            
            JScrollPane ScrollNine = new JScrollPane(Nine);
            panel.add(ScrollNine);
            frame.setContentPane(panel);
            
            javax.swing.Timer TimerNine = new javax.swing.Timer(int 1000, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Nine.append("9");
                }
            });
            
            frame.setVisible(true);
            
            TimerNine.start();
        }
    }
  8. #5
  9. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5053
    Don't declare the int.
    PHP Code:
    javax.swing.Timer TimerNine = new javax.swing.Timer(1000, new ActionListener() {
    //... 
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    41
    Rep Power
    10
    Compiling is taking a really long time. Does the timer need its own class? If the code is all right then is there an easier way to make a timer?
  12. #7
  13. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5053
    Compiling shouldn't take a long time simply because of the Timer class. Check your system and IDE settings.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    41
    Rep Power
    10
    I restarted the IDE and it worked. But when It compiled it found an error with

    Code:
                    Nine.append("9");
    The message was really long so I took a screenshot of the error box. It's attached.
    Attached Images
  16. #9
  17. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5053
    Don't panic when you get an error message. It's trying to tell you something. Listen to it.

    You can't access non-final local variables from anonymous inner classes. The error message you posted tells you exactly what's wrong and what you need to do to correct it.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    41
    Rep Power
    10
    How do I declare it final?
  20. #11
  21. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5053
    How do I declare it final?
    With the "final" keyword.

    Example:
    PHP Code:
    final Object somethingOrOther = new Object(); 
    The Java Tutorial - A practical guide for programmers
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    41
    Rep Power
    10
    Sorry to bother you again. Anyways now it says "cannot find symbol - method append(java.lang.String)" What does that mean?

    Code:
                    Nine.append("9");
  24. #13
  25. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5053
    It means the compiler does not recognize the method you have written as a valid method. You've written something incorrectly.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  26. #14
  27. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5053
    The following code is a direct modification of your code, changing only what was necessary to get it to a compileable state:
    PHP Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class 
    Gui {
        public static 
    void main(String[] Args){
            
    JFrame frame = new JFrame("Nine");
            
    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
            
    frame.setResizable(false);
            
    frame.setBounds(265100535291);
            
    JPanel panel = new JPanel();
            
            final 
    JTextArea Nine = new JTextArea("999999999"1547);
            
    Nine.setLineWrap(true);
            
    Nine.setWrapStyleWord(false);
            
    Nine.setEditable(false);
            
            
    JScrollPane ScrollNine = new JScrollPane(Nine);
            
    panel.add(ScrollNine);
            
    frame.setContentPane(panel);
            
            
    javax.swing.Timer TimerNine = new javax.swing.Timer(1000, new ActionListener() {
                public 
    void actionPerformed(ActionEvent e) {
                    
    Nine.append("9");
                }
            });
            
            
    frame.setVisible(true);
            
            
    TimerNine.start();
        }

    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    22
    Rep Power
    0
    Hi everyone, I'm having a similar problem.

    Code:
    /**
     * Time class
     * 
     * <INSERT DESCRIPTION HERE>
     * 
     * @author: Kevin O'Connor
     * @version: 1
     */
    public class Time
    {
    	// Variables (1.2)
    	private int hours;
    	private int minutes;
    
    	// Constructors (1.3)	 
    	public Time()
    	{
    		hours = 0;
    		minutes = 0;
    	}
    	
    	// Method: setHour (1.4)
    	
    	private void setHour(int timeHour)
    	{
    	    if((timeHour <= 23) && (timeHour >= 0)){
    	        hours = hours + timeHour;
    	    }
    	}
    	
    	// Method: setMinute (1.5)
    	private void setMinute(int timeMinute)
    	{
    	    if((timeMinute <= 59) && (timeMinute >= 0)){
    	        minutes = minutes + timeMinute;
    	    }
    	}
    	
    	// Method: setTime (1.6)
    	public void setTime(int timeHour, int timeMinute)
    	{
    	    setHour(int timeHour);
                setMinute(int timeMinute);
    	}
    }
    The line highlighted in bold is where I'm getting the "'.class' expected" message. I'm trying to make a method call so I don't have to repeat the code. I would assume I have the same problem with the line after it.

    Any help is appreciated.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo