Hey all!

I am in college doing a speech on programming and one of my topics is to explain the difference between Java, C, and Objective C. I have been programming with Java for 3 years now and just started with C last month, but I don't know the differences between the three. I want to be able to explain what each is used for and such to people who don't program. I have seen the site where it compares the languages to family members, but that is still a little confusing. If you could explain or point me to a site, that would be great!

Note: I may use your exact words, but I will obviously site it (had some close plagrism calls in recent years)

Thanks!

There is more code than this, but this is the method I am using.

private class thehandler2 implements KeyListener {

        @Override
        public void keyTyped(KeyEvent ke) {
        }

        @Override
        public void keyPressed(KeyEvent ke) {

            int k = ke.getKeyCode();
            if (k == 37) {
                System.out.println("left");
                    k = ke.getKeyCode();
                if (k == 38) {
                    System.out.println("up");
                }
            }  
            else if (k == 39) {
                kx = kx + kspeed;
                System.out.println("right");
            } 
            else if (k == 40) {
                ky = ky + kspeed;
                System.out.println("down");
            }    
        }

        @Override
        public void keyReleased(KeyEvent ke) {
        }
    }

My error is happening in this code:

            int k = ke.getKeyCode();
                if (k == 37) {
                    System.out.println("left");
                        k = ke.getKeyCode();
                    if (k == 38) {
                        System.out.println("up");
                    }
                }

I want up to print if it is immediately followed by left. This code doesn't even print up.

I figured it out. For anyone who reads this wondering how to do it, this is what I have...
Desktop d = Desktop.getDesktop();
File f = new File("/Applications/TextEdit.app");
d.open(f);

Hi,

I am making a program to open the application TextEdit on a mac (not a specific file, just open the program). I have been researching it, but have not come across much help. I have seen that I should use Runtime or Desktop classes, but i'm not sure which to use (if those are even correct). I have OS X 10.6.8 and I would ultimatly like to use something like /Applcations/TextEdit.app. Is this possible?

Thanks in advance!

Hey,

I am trying to use a for loop inside a recusive method, but everytime the method runs recursively, the integer in the for loop resets to zero because of the initialization. Is there anyway to keep the integer counting up, and not resetting to zero?

Thanks in advanced!

Hi,

I've used keylisteners multiple times, but I am having trouble with this situation. I want the keylistener to recognize a series of characters. For example, if 'e' is typed, I want the program to listen for 'l', then 'e', etc. (spelling "elephant", if you wanted to know). It recognizes the first 'e', but does not recognize the 'l' or any different letter afterwards. I'm stumped...

Any help is greatly appreciated. I've searched the internet for an answer, but I haven't found an answer (hense why I'm here). If you find an answer, feel free to just post the link to the site.

Thanks in advanced!

Hey. I am trying to make a "virus" that will not let the user exit the program even with pressing Command+Q (oh, ya, I have an Apple). Here is what I have so far:

if (keylistener.getKeyCode()==81){
System.out.println("Works");
}
I have the println just to see if it works (which it does), but is there a way to "kill" the request or have the computer not recognize the command key if pressed?

Thanks in advance!

Good suggestions, but they did not help. I have to wipe my computer soon so maybe it will work when i re-intall netbeans.

Hey,

I am having trouble compiling in netbeans. When I go to compile, I usually go to Run>Clean and Build Main Project (or shift F11). When it compilies, it says

Copying 1 file to /Users/me/NetBeansProjects/JavaApplication11/build
Nothing to copy.

And when I go to run the .jar file, it doesn't open and says "The Java JAR file "JavaApplication11.jar" could not be launched."

I set it as the main project and the program does have a package. Any ideas? I've never had this problem before. (I'm on a MacBook if that helps)

Thanks in advance!

I actually found one online and modified it. Turns out to be keycode 157. Thanks for helping!

Good idea with the VK_WINDOWS key, but it did not work :( I was trying to avoid that, but I think it is the only way. Would you have any idea how to get started?

Hey,

I am now programming in a MacBook Pro and for the KeyCodes in the Robot Class, there is no set key for Command. Can I set a KeyCode to do the actions of the Command key?

Thanks

Oh, wow, ya, not the prettiest code out there but i'll try it. Thanks!

Hey,

Is there a way to get the keycode from a char? I tried using KeyEvent.getKeyCode() but the KeyEvent class didn't have a constructor so it was freaking out. I've been searching for 2+ hours already and nothing. My goal is to have a char, convert it to keycode, and then use the keycode in the robot class's KeyPress([keycode]) method.

Hello,

I am confused between the differences between a key logger and key listener in Java....i looked online but I couldn't find a straight-up answer.

Thanks in advance!

Nah, no beep

Hey,

Is there a way to play a system beep on mac os x in Java? I usually use the beep function in Toolkit class for my PC but I tried the beep function in Toolkit but it doesn't work on my mac. Any help?

Thanks in advance!

[QUOTE=rubberman;1646750]Design it first, then code it to your design. There are a number of database type tools for java that will allow you to store and search the data on disc in a number of ways, but first you need to write out in detail how you want it to work, how it is to be presented to the user, what options the user will have with regard what columns are sorted or in what order, etc.[/QUOTE]
I have it all planned out and such. Which database tools do you prefer or what is the easiest to get the hang of the fastest?

Hey,

I've had this question for a while now and forgot to post a thread asking it. I'm really interested in databases and i've been wanting to create a program that recalls information from a database. I've done one that reads a text file but that just seemed...boring to me. If possible, i'd like to make the program, put it on a USB stick/memory drive/jump drive thingy and open the program on another computer and all my data is there from the last time i ran the program. Umm...almost like a phonebook program that i can edit the contacts anywhere and it saves it. Can anyone point me in the right direction or give me some information to get started?

Thanks in advance!

-Yohan

Maybe I did not phrase the question right. I am wondering how to use the robot class with a mac computer because I need to use keys such as function, command, and option. Is there a way to have the computer type those keys for me?

Hello,

I got a MacBook Pro for college and i'm trying to program on it. It's all good except when i use the robot class, i don't see any key codes or key events for keys such as function, option, and command. Can i use those keys when using the robot class?

Thanks in advance!

-Nick

Hey,
Is there any code that will hide the icons on my desktop?
Thanks in advance

Hi,

I'm trying to set a background image of a JFrame. I researched on google but i haven't gotten anything to work. My idea is to make monopoly with the board in the background and have the pieces move around on top of the board.

Thanks in advance

[QUOTE=caswimmer2011;1498105]Hello,

I have this code that sorts strings but it does not sort them at all. I've been working on it for 2 hours already. Any help will be appreciated.

Thanks in advance :)[/QUOTE]
What exactly does the code do?

Hello,

I have this code that sorts strings but it does not sort them at all. I've been working on it for 2 hours already. Any help will be appreciated.

Thanks in advance :)[code]public void SelectionSort() {
for (int i = 0; i < myList.length - 1; i++) {
int smallist = getSmallest(i, myList.length-2);
swap(i, smallist);
}

}

private int getSmallest(int a, int b) {
    int small = a;
    for (int i = a+1; i < myList.length; i++) {
        if (myList[i].compareTo(myList[a]) > 0) {
            myList[a] = myList[i];
        }
    }
    return small;
}[/code]

It is showing me an error with the second word "File". It says "cannot find symbol" symbol: constructor File(java.net.URL) Location java.io.File.

Hi,

I have a program that uses JButtons (under ActionEvent e) and the user clicks a button and it brings up the appropriate text file associated with that name. I have the files on a flash drive but every time i transfer the files to different computer and want to run the program on the computer, i need to change the file pathway. They are all loaded into my source package. Is there a way or code that I can have Java go into the source package to retrieve the files or to search for the files and set that pathway as a temporary string? If needed, i'll provide more code.

Thanks for your help![code]JButton temp = (JButton) e.getSource();
File f = new File("J:\AP Comp Sci\Bible 2\src\bible2\Books\"

  • temp.getText() + ".txt");

    Desktop desktop = Desktop.getDesktop();
    try {
        desktop.open(f);
    } catch (Exception e1) {
        System.out.println("error");

    }[/code]

Hello,

I am doing my first JFrame. I want it to have a button where the user clicks it and music plays. I already made the button (called b1) but i can't seem to find code for the music to be imported and played. I have tried a whole bunch of websites but none of them work. Anyone here have a good code to play music in a JFrame?

Hello,
I am trying to add audio files to my program. I am using a desktop application and not an applet. All the code that i have found online is for an applet. Is there a way for me to add audio code to a desktop application and not an applet?

-Thanks

The code works perfectly. Thanks for your help.