Engineeringserver.com

A community for computer science students & developers about software development, game development, game design, games, anime preview & reviews and more!

Archive for the ‘Java’


Get the contents of the clipboard using java

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...
365 views

So, i was looking for a way to grab content from a clipboard and googled a bit about it. After reading a page on the Devx site i rewrote the code a bit and the result can be seen below. This version only grabs text but i'll write another demo that grabs text and images as well when i have the time for it.

JAVA:
  1. /*--------------------------------------------------------------------------
  2. ClipboardV2 class
  3. *****************
  4. By: HappyFace   http://www.engineeringserver.com
  5. Contact:        info [@] engineeringserver.com
  6. Version:        01/August/2008
  7. Last updated:   27/September/2008
  8. "*****************
  9. Note: Adapted from http://www.devx.com/Java/Article/22326 (original source)
  10. //----------------------------------------------------------------------*/
  11. import java.awt.Toolkit;
  12. import java.awt.datatransfer.Clipboard;
  13. import java.awt.datatransfer.DataFlavor;
  14. import java.awt.datatransfer.Transferable;
  15. import java.awt.datatransfer.UnsupportedFlavorException;
  16. import java.io.IOException;
  17.  
  18. public class ClipboardV2 implements Runnable{
  19. boolean newGrab = false;
  20. String oldGrab = "";
  21. public static void main(String[] args){
  22. ClipboardV2 CV2 = new ClipboardV2();
  23. while(true){
  24. CV2.run();
  25. }
  26. }
  27.  
  28. public static String getClipboard() {
  29. Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  30. Transferable clipboardContents =systemClipboard.getContents(null);
  31.  
  32. if (clipboardContents == null) {
  33. return ("Clipboard is empty.");
  34. }
  35. else{
  36. try {
  37. if (clipboardContents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
  38. String returnText = (String) clipboardContents.getTransferData(DataFlavor.stringFlavor);
  39. return returnText;
  40. }
  41. ufe.printStackTrace();
  42. } catch (IOException ioe) {
  43. ioe.printStackTrace();
  44. }
  45. return null;
  46. }
  47. }
  48.  
  49. public void run() {
  50. try {
  51. Thread.sleep(100);
  52. String grabbed = getClipboard();
  53. String newGrabbed = grabbed;
  54. if(!oldGrab.equals(newGrabbed)){
  55. oldGrab = newGrabbed;
  56. System.out.println("Grabbed: " + grabbed);
  57. }
  58. } catch (InterruptedException e) {
  59. e.printStackTrace();
  60. }
  61. }
  62. }

Bookmark this page: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • De.lirio.us
  • Slashdot
  • StumbleUpon
  • Technorati
  • Reddit
  • Digg

Your Ad Here

Online Java compiler W.I.P.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...
1,656 views

I've been working on my Java online compiler earlier today and while the software is far from finished it does work as intended (it tries to compiles the java file and will show the appropiate message(s)) . One of the thing that does't work however is that when the file is compiled succesfully the generated class file wil not run for some reason but it does work when i test my compiler class seperately in another project with Eclipse. Wierd? It sure is, but maybe there is a nasty bugger somewhere in the code that i've overlooked. Stay tuned!

Want to take a look at the code? Go to our svn server -> project -> OnlineCompiler

Here's an example output when a user uploads a *.java file to the webserver or local directory where the folder watcher is running.
(more...)

Bookmark this page: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • De.lirio.us
  • Slashdot
  • StumbleUpon
  • Technorati
  • Reddit
  • Digg

Your Ad Here

Divine pk v5.0, Built upon RSCD / Demonik v.7

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...
1,200 views

We got this "Divine pk v5.0" source from some guy called Chris Wilson and although he was being an ass on msn messenger (because I told him I didn't had the time to help him with this) , we (me and a few developers on our forum) decided to enhance this build with custom features and to spend some time developing this in our spare time. The current build is already online and can be downloaded/played on our server. The server is currently fully working and ready to accept new players!

The original source as well as our source can be download from the server for those that want to host their own game.

PS: We do not need any more developers to work on this but we sure need (gameplay) testers to give us feedback! Oh and btw, here's the readme based on Divine pk v5.0

Well, im releasing this for the sake of rsc devlopment.
all i want in return, is my name mentioned.
this readme contains small info & a noob friendly guide.
its a project server i coded, and im working on a new now so...enjoy this one! :)

------------------------------------------------------------------
Built upon RSCD / Demonik v.7 (all credits for the source go here)
------------------------------------------------------------------
(i know.. demonik source "sucks" but hear me out)

-----------------------------------
Touch-ups made.
-----------------------------------
Fully working skills (except for god spells) easy add, use v2 source.
good economy.
about all dupes/buggs fixed.
stable (no crashes)
Server is made to help, instead of making problems :)
shops, npcs, teleport lady, pk pool and hell of alot more.
full pk & duel (attack timer is messed up tho, easy fix)
Maxstat 115 & fast xp.
tons of npcs to train on.
well, alot more.. run it and see for your self.

i dont feel like edit anything for the release, thats up to you.
(noob admins fucked some things up, like the attack timer and more)
but with this you will have a good, stable server wich is pretty close to flawless.
when Divine pk was up, it had 200-300 players daily without a problem.

-
ps, this is not the lastest Divine pk Source, but its pretty new.
-

This release is made by Dummis and is released public upon my request.
feel free to modify it, change name, put in trash can, do whatever you want,
as long as i get my name mentioned somewhere :)

-------------------------------------------------------------------
Included in packet for beginners
-------------------------------------------------------------------
. Server Source (of course)
. Website / Register
. MySql Database
. Client

(more...)

Bookmark this page: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • De.lirio.us
  • Slashdot
  • StumbleUpon
  • Technorati
  • Reddit
  • Digg

Your Ad Here

Java online quiz applet

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.5 out of 5)
Loading ... Loading ...
1,312 views

I got a request from someone that asked me to create an applet that can be used as a quiz, well since I had a bit of time today I went ahead and coded it for him. The questions will be randomized every time you run the applet but as of now I've only made 5 questions so the application picks the first 5 questions available. I'll see if I can upload a demo somewhere to show you how it works but the applet needs a java.policy file that doesn't run in a browser so i'll see if i can manage to create a self signed java applet.

/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
/* DO NOT EDIT */

grant {
permission java.security.AllPermission;
};

Screenshot(s):


What do you think about it? Comments/suggestions are welcome!
(more...)

Bookmark this page: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • De.lirio.us
  • Slashdot
  • StumbleUpon
  • Technorati
  • Reddit
  • Digg

Your Ad Here

Read a textfile into an ArrayList

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...
514 views
JAVA:
  1. /*--------------------------------------------------------------------------
  2. ScanToArrayDemo class
  3. *****************
  4. By: HappyFace   http://www.engineeringserver.com
  5. Contact:        info [@] engineeringserver.com
  6. Version:        10/September/2008
  7. "*****************
  8. Note: Read a textfile into an ArrayList
  9. //----------------------------------------------------------------------*/
  10. import java.io.File;
  11. import java.io.FileNotFoundException;
  12. import java.io.IOException;
  13. import java.util.ArrayList;
  14. import java.util.Scanner;
  15.  
  16. public class ScanToArrayDemo {
  17. public static void main(String[] args){
  18. File fInput     = new File("c:\\input.txt");
  19. ArrayList textHolder = new ArrayList();
  20. String tmp = "";
  21. try {
  22. Scanner scInput = new Scanner(fInput);
  23. while (scInput.hasNextLine()){
  24. tmp = scInput.nextLine();
  25. textHolder.add(tmp);
  26. }
  27. }
  28. e.printStackTrace();
  29. }
  30. catch (IOException e) {
  31. e.printStackTrace();
  32. }
  33. //display the content of the array
  34. System.out.println(textHolder.get(3));
  35. }
  36. }

Bookmark this page: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • De.lirio.us
  • Slashdot
  • StumbleUpon
  • Technorati
  • Reddit
  • Digg

Your Ad Here

Java compiler API, compiling made easy

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.33 out of 5)
Loading ... Loading ...
1,889 views

Before Java 1.6 was released to the public I used the Runtime class (found in java.lang) to call the java compiler (javac.exe) directly to compile a Java file from another Java application, the line of code that i used looks like this

JAVA:
  1. Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\cmd.exe /c start javac " +  userDir + "\\test\\"+className + ".java");

But luckily for me Java 1.6 introduced a handy utility that makes it possible to compile a Java application within a Java application without making direct calls to an external application. To demonstrate that I wrote a HelloWorld Java file and a CompilerConsoleDemo class that compiles the HelloWorld java file.

JAVA:
  1. public class HelloWorld {
  2. public static void main(String[] args){
  3. System.out.println("Hello World");
  4. }
  5. }

(more...)

Bookmark this page: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • De.lirio.us
  • Slashdot
  • StumbleUpon
  • Technorati
  • Reddit
  • Digg

Your Ad Here

Creating a Simple Servlet Using IRAD

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...
322 views

This free, multimedia tutorial shows you how to use IBM's Rational Application Developer (IRAD) to create a J2EE project, a Servlet, and a WebSphere Test Server on which you can proudly run your newly birthed Servlet.

If you found something helpful here, please do your part and help support the site. Link to us, buy some books, support our sponsors, tell your developer friends about us, and remember: Happy Java!


(more...)

Bookmark this page: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • De.lirio.us
  • Slashdot
  • StumbleUpon
  • Technorati
  • Reddit
  • Digg