Official Nodeka Board

Official Nodeka Board (http://www.nodeka411.net/forum/index.php)
-   UMC (http://www.nodeka411.net/forum/forumdisplay.php?f=10)
-   -   Creating a Frame (http://www.nodeka411.net/forum/showthread.php?t=452)

Bellum 10-10-2009 10:12 AM

Creating a Frame
 
I'm trying to figure out how to create a frame in UMC. I found this code on the web, but when I set up a .js file type "#JSREAD window" and I get the error.

missing ; before statement (window.js#2)

http://java.sun.com/docs/books/tutor...nts/frame.html

this is where I'm getting my commands from, for some reason I don't think umc likes the way I have it setup for some reason.

Code:

//1. Create the frame.

JFrame frame = new JFrame("FrameDemo");

//2. Optional: What happens when the frame closes?

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//3. Create components and put them in the frame.
//...create emptyLabel...
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

//4. Size the frame.
frame.pack();

//5. Show it.
frame.setVisible(true);

Thanks in advance.

uda 10-10-2009 11:36 PM

That would be because you are reading a Java tutorial and not Javascript. They are different languages. That said you can access Java classes via Javascript; Javascript was originally created as a way to control Java applets within a web browser. In other words to "script" Java applets -> Javascript...

Anyways if you want to use actual Java you need to build it as a plugin. If you want to use Javascript (which #jsread is for) you can build it similar to the following example.

Note: The biggest difference is in Javascript you have to use to complete class name including package when referencing Java classes. Ex, javax.swing.JFrame where as in Java you would use an import statement.

Here's a javascript function to create a frame based on your tutorial source.

function createFrame() {
var myFrame = javax.swing.JFrame("Example Frame");
var myLabel = javax.swing.JLabel("Hello, world.");
// Do not use EXIT_ON_CLOSE unless you want UMC to exit completely!
myFrame.setDefaultCloseOperation( javax.swing.WindowConstants.DISPOSE_ON_CLOSE );
myFrame.getContentPane().add(myLabel, java.awt.BorderLayout.CENTER);
myFrame.pack();
myFrame.setVisible(true);
}

After loading that using #jsread you can then call the Javascript function using #script createFrame()

Bellum 10-11-2009 01:17 AM

1 Attachment(s)
First, thanks alot for the help and example and explanation. That will be a great help in building in the future.

Second, Are there any good links that you know of that have syntax and java script and/or java basic's.

Thrid, When #JSREAD on the file I get this error

Code:

missing ) after argument list (window.js#9)"
I looked over it a quite a few times and I can't seem to find where you fail to close a (). I attached the file exactly as I load it in UMC.

In my UMC root folder I have it saved as window.js but the forum will not let me upload that file so I switched it to a txt just for uploading purposes.



EDIT

I actually found the bug, was in the line:

Code:

myFrame.setDefaultCloseOperation(javax.swing.Windo wConstants.DISPOSE_ON_CLOSE);
needs to be:

Code:

myFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
Thanks again for the help Uda!

uda 10-11-2009 01:43 AM

I'm not sure why the forum is doing it. I checked the message source and it's fine, but look at the setDefaultCloseOperation function the forum shows a space in the WindowConstant class name. There of course should be no space there.

I would suggest getting an IDE which supports Javascript so you can easily see any syntax errors. Netbeans and Eclipse (eclipse uses a plugin) both support Javascript. There are probably some more lightweight editors however that would do the job as well.

Note: I fixed the above example by putting spaces between around the function argument.

Bellum 10-11-2009 01:52 AM

Quote:

Originally Posted by uda (Post 1383)
I'm not sure why the forum is doing it. I checked the message source and it's fine, but look at the setDefaultCloseOperation function the forum shows a space in the WindowConstant class name. There of course should be no space there.

I would suggest getting an IDE which supports Javascript so you can easily see any syntax errors. Netbeans and Eclipse (eclipse uses a plugin) both support Javascript. There are probably some more lightweight editors however that would do the job as well.

Note: I fixed the above example by putting spaces between around the function argument.


I think we posted at the same time, not to beat a dead horse but do you know of any good places to learn javascript? I know there are hundreds on the web but some seem to be lacking.

uda 10-11-2009 02:01 AM

Not really; I would just end up using google. Although what could be useful is http://www.mozilla.org/rhino/ScriptingJava.html (Rhino is the Javascript engine UMC uses). The JavaImporter class would be helpful if you dont want to type out full class names.

Bellum 10-11-2009 02:09 AM

Thanks, grabbing net beans too. I found this really nice also.

http://ils.unc.edu/courses/2009_summ...3_15_Swing.pdf

grimm 10-11-2009 11:59 PM

Awesome stuff and reply. This will definately help me in my own bot project.

Another question how do i get the plugin to be in the menu bar as how the salvage window you've created?

Plugins > Salvage?
________
ROOR BONG PICTURES

Bellum 10-13-2009 09:00 PM

I would guess you would have to access the core code of UMC to add an item to the menu bar.

My goal is to just make a simple plugin or javascript that enables me to have a window with customisable buttons that I can add text and make them enable tintin actions and aliases. So its simple click to play.

grimm 10-14-2009 01:19 AM

I think its possible to code without getting into the core of UMC. as the salvage plugin provided by Uda didn't need to change any UMC files. it just added an addition jar?

i could be wrong.
But if Uda could shed some light on how we can do this . It'll be most appreciated.
________
Honda Siel Cars India


All times are GMT. The time now is 07:24 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.