Official Nodeka Board  

Go Back   Official Nodeka Board > Nodeka > Scripting > UMC

Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2009, 10:12 AM
Bellum Bellum is offline
Novice
 
Join Date: Sep 2009
Posts: 25
Default 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.

Last edited by Bellum; 10-10-2009 at 10:19 AM.
Reply With Quote
  #2  
Old 10-10-2009, 11:36 PM
uda uda is offline
Wanderer
 
Join Date: Oct 2009
Posts: 8
Default

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()

Last edited by uda; 10-11-2009 at 01:45 AM.
Reply With Quote
  #3  
Old 10-11-2009, 01:17 AM
Bellum Bellum is offline
Novice
 
Join Date: Sep 2009
Posts: 25
Default

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!
Attached Files
File Type: txt window.txt (419 Bytes, 1 views)

Last edited by Bellum; 10-11-2009 at 01:50 AM.
Reply With Quote
  #4  
Old 10-11-2009, 01:43 AM
uda uda is offline
Wanderer
 
Join Date: Oct 2009
Posts: 8
Default

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.

Last edited by uda; 10-11-2009 at 01:46 AM. Reason: Fixed the message source with the example.
Reply With Quote
  #5  
Old 10-11-2009, 01:52 AM
Bellum Bellum is offline
Novice
 
Join Date: Sep 2009
Posts: 25
Default

Quote:
Originally Posted by uda View Post
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.
Reply With Quote
  #6  
Old 10-11-2009, 02:01 AM
uda uda is offline
Wanderer
 
Join Date: Oct 2009
Posts: 8
Default

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.
Reply With Quote
  #7  
Old 10-11-2009, 02:09 AM
Bellum Bellum is offline
Novice
 
Join Date: Sep 2009
Posts: 25
Default

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

http://ils.unc.edu/courses/2009_summ...3_15_Swing.pdf
Reply With Quote
  #8  
Old 10-11-2009, 11:59 PM
grimm's Avatar
grimm grimm is offline
Apprentice
 
Join Date: Nov 2008
Posts: 78
Default

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

Last edited by grimm; 03-10-2011 at 02:53 AM.
Reply With Quote
  #9  
Old 10-13-2009, 09:00 PM
Bellum Bellum is offline
Novice
 
Join Date: Sep 2009
Posts: 25
Default

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.
Reply With Quote
  #10  
Old 10-14-2009, 01:19 AM
grimm's Avatar
grimm grimm is offline
Apprentice
 
Join Date: Nov 2008
Posts: 78
Default

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

Last edited by grimm; 03-10-2011 at 02:53 AM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:22 AM.


Design By: Miner Skinz.com
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.