Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: No classes available

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default No classes available

    Hey, I had to edit this short code for a class I'm taking and add a few things. I already added my changes, but even before I did, when I clicked "run" it would pop up with a menu asking me to choose the class I'd like to use, but there are no options to choose from. Why can't it load my class? Thanks in advance for your help!

    package etchasketchjacob;
     
    import java.awt.*;
    import java.awt.event.KeyEvent;
    import javax.swing.JFrame;
     
    public class EtchASketch extends Canvas
    {
    	int x, y;
    	Color cur;
     
    	public static void main( String[] args )
    	{
    		JFrame win = new JFrame("Use the arrow keys!");
    		win.setSize(1024,768);
    		win.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    		win.add( new EtchASketch() );
    		win.setVisible(true);
    	}
     
    	public EtchASketch()
    	{
    		enableEvents(java.awt.AWTEvent.KEY_EVENT_MASK);
    		requestFocus();
    		x = 500;
    		y = 400;
    		cur = Color.black;
    	}
     
    	public void paint( Graphics g )
    	{
    		g.setColor(cur);
    		g.fillOval(x, y, 30, 30);
    	}
     
    	public void update( Graphics g )
    	{
    		paint(g);
    	}
     
    	public void processKeyEvent(KeyEvent e)
    	{
    		// this method automatically gets called with they press a key
    		if ( e.getID() == KeyEvent.KEY_PRESSED )
    		{
    			if ( e.getKeyCode() == KeyEvent.VK_UP )
    				y -= 10;
    			if ( e.getKeyCode() == KeyEvent.VK_DOWN )
    				y += 10;
                            if ( e.getKeyCode() == KeyEvent.VK_LEFT )
    				x -= 10;
                            if ( e.getKeyCode() == KeyEvent.VK_RIGHT )
    				y += 10;
                            //My Macbook does not have F1, F2, or anything like that,
                            //so I had to use different buttons. Hope that's okay.
                            if ( e.getKeyCode() == KeyEvent.VK_Q )
                                    cur = Color.RED;
                            if ( e.getKeyCode() == KeyEvent.VK_W )
                                    cur = Color.GREEN;
                            if ( e.getKeyCode() == KeyEvent.VK_E )
                                    cur = Color.BLUE;
                            if ( e.getKeyCode() == KeyEvent.VK_R )
                                    cur = Color.BLACK;
     
    			// and we manually call paint() again to redraw
    			repaint();
    		}
    	}
     
    	public boolean isFocusable()
    	{
    		return true;
    	}
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,554
    Thanks
    52
    Thanked 2,317 Times in 2,273 Posts

    Default Re: No classes available

    when I clicked "run" i
    What program/IDE are you using?

    Have you tried using the javac command in a command prompt to compile the code?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2018
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: No classes available

    Quote Originally Posted by Norm View Post
    What program/IDE are you using?

    Have you tried using the javac command in a command prompt to compile the code?
    I'm using Netbeans. And no I haven't tried that, not sure how but I can look it up I suppose. Would that give me an error message or what's the reasoning for doing it?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,554
    Thanks
    52
    Thanked 2,317 Times in 2,273 Posts

    Default Re: No classes available

    Try using the javac command to compile the code and the java command to execute it.

    I don't know anything about Netbeans.

    Take a look at the tutorial: https://docs.oracle.com/javase/tutor...ted/index.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: July 11th, 2014, 04:02 AM
  2. Replies: 1
    Last Post: July 11th, 2014, 03:01 AM
  3. Are there classes in c++?
    By fahman_khan75@yahoo.com in forum Other Programming Languages
    Replies: 2
    Last Post: February 5th, 2014, 02:35 AM
  4. Classes of classes? [Very beginner asking a question] [w/ Codes]
    By UhKindaAwkward in forum Object Oriented Programming
    Replies: 6
    Last Post: December 24th, 2013, 03:05 AM
  5. Help with creating classes and sub classes
    By Anotherspicybean in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 13th, 2013, 11:42 PM