Java bufferedImage to JavaFX Image

Hi,
is there any easy way how to convert awt bufferedImage to JavaFX Image? I am using sun's pdf-renderer which output can be AWT image which I would like to display in a JavaFX scene as a image node.

Yes. This has already been discussed here: Image conversion between AWT and FX

Similar Messages

  • BufferedImage convert to Image

    Is there anyway to convert a BufferedImage into an Image. I've seen the other way around but not this way.
    Any help would be greatly appreciated.

    thank you.
    See, I've got this method (below), that actually creates this image for me.
    private static BufferedImage loadImage(final URL url) throws Exception{ //IOException {
         BufferedImage image;
             // Load the image through Image I/O
         image = ImageIO.read(url);
         //image = imageIO.read(url);
            // Check that the image was loaded and that we can get a GC
             if (image != null && !GraphicsEnvironment.isHeadless()) {
                final GraphicsConfiguration gc = GraphicsEnvironment
                        .getLocalGraphicsEnvironment()
                        .getDefaultScreenDevice()
                        .getDefaultConfiguration();
                // This probably can't be null if it's not headless
                // Not sure though so check anyway
                if (gc != null) {
                    // Attempt to create compatible image with same transparency
                    final BufferedImage img = gc.createCompatibleImage(
                            image.getWidth(), image.getHeight(),
                            image.getTransparency());
                    // Check that img was created and isn't the same type
                    // If it's the same type we don't need to convert obviously
                    if (img != null && image.getType() != img.getType()) {
                        // Use ColorConvertOp to convert the rasters from one
                        // color space to the other
                        // This is faster than using Graphics to draw on the new
                        // image in many cases, sometimes 100x faster
                        ColorConvertOp op = new ColorConvertOp(
                                image.getColorModel().getColorSpace(),
                                img.getColorModel().getColorSpace(), null);
                        op.filter(image, img);
                        image = img;
             return image;
         }But, I need to call this from within the same class:
    URL base;     
                   try{
                   base = new URL ("http://home.cogeco.ca/~someplace/folder");
                   catch(Exception n)
                        System.out.println("Can't construct URL, first time around.");
                   try{
                   ll = loadImage(base); // right exception after calling method???
                   catch(Exception n)
                        System.out.println("problems");
                   }For some reason, I can't figure out if I'm handling the exception properly. Any ideas why I'm getting the following error?
    load: tetrisapp.PictureData.class can't be instantiated.
    java.lang.InstantiationException: tetrisapp.PictureData
         at java.lang.Class.newInstance0(Class.java:340)
         at java.lang.Class.newInstance(Class.java:308)
         at sun.applet.AppletPanel.createApplet(AppletPanel.java:778)
         at sun.applet.AppletPanel.runLoader(AppletPanel.java:707)
         at sun.applet.AppletPanel.run(AppletPanel.java:361)
         at java.lang.Thread.run(Thread.java:619)Tell me if you need more code. I'm guessing that the error is coming from the improper handling of the exception.
    Message was edited by:
    ManRed
    Message was edited by:
    ManRed

  • Loading javafx images concurrently

    Hello,
    So I been working on downloading images asynchronously and concurrently. I was planning on using the async javafx package. I made a big assumption before reading the details of how the async package works. I thought I was going to be able to easily run concurrent javafx code. But after reading http://blogs.oracle.com/clarkeman/entry/javafx_async_task I see that the async package was made for running java code.
    Is there a way to asynchronously and concurrently load javafx images, e.g. load on separate thread with the ability of main thread to access those images?
    thanks a lot!
    jose

    Hello,
    So I been working on downloading images asynchronously and concurrently. I was planning on using the async javafx package. I made a big assumption before reading the details of how the async package works. I thought I was going to be able to easily run concurrent javafx code. But after reading http://blogs.oracle.com/clarkeman/entry/javafx_async_task I see that the async package was made for running java code.
    Is there a way to asynchronously and concurrently load javafx images, e.g. load on separate thread with the ability of main thread to access those images?
    thanks a lot!
    jose

  • How to pass Objects from Java App to JavaFX Application

    Hello,
    New to the JavaFX. I have a Java Swing Application. I am trying to use the TreeViewer in JavaFX since it seems to be a bit better to use and less confusing.
    Any help is appreciated.
    Thanks
    I have my Java app calling my treeviewer JavaFX as
    -- Java Application --
    public class EPMFrame extends JFrame {
    Customer _custObj
    private void categoryAction(ActionEvent e)   // method called by Toolbar
            ocsCategoryViewer ocsFX;    //javaFX treeviewer
            ocsFX = new ocsCategoryViewer();    // need to pass in the Customer Object to this Not seeing how to do it.
                                                  // tried ocsFX = new ocsCategoryViewer(_custObj) ;    nothing happened even when set this as a string with a value
    public class ocsCategoryViewer extends Application {
    String _customer;
    @Override
        public void start(Stage primaryStage) {
         TreeView <String> ocsTree;
         TreeItem <String> root , subcat;
      TreeItem <String> root = new TreeItem <String> ("/");
            root.setExpanded(true);
             ocsTree = new TreeView <String> (root);
             buildTree();     // this uses the Customer Object.
            StackPane stkp_root = new StackPane();
            stkp_root.getChildren().add(btn);
            stkp_root.getChildren().add(ocsTree);
            Scene scene = new Scene(stkp_root, 300, 250);
            primaryStage.setTitle("Tree Category Viewer");
            primaryStage.setScene(scene);
            primaryStage.show();
        public static void main(String[] args) {
            _customer = args[0];      // temporarily trying to pass in string.
            launch(args);

    JavaFX and Swing integration is documented by Oracle - make sure you understand that before doing further development.
    What are you really trying to do?  The answer to your question depends on the approach you are taking (which I can't really work out from your question).  You will be doing one of:
    1. Run your Swing application and your JavaFX application as different processes and communicate between them.
    This is the case if you have both a Swing application with a main which you launch (e.g. java MySwingApp) and JavaFX application which extends application which you launch independently (e.g. java MyJavaFXApp).
    You will need to do something like open a client/server network socket between the applications and send the data between them.
    2. Run a Swing application with embedded JavaFX components.
    So you just run java MySwingApp.
    You use a JFXPanel, which is "a component to embed JavaFX content into Swing applications."
    3. Run a Java application with embedded Swing components.
    So you just run java MyJavaFXApp.
    You use a SwingNode, which is "used to embed a Swing content into a JavaFX application".
    My recommendation is:
    a. Don't use approach number one and have separate apps written in Swing and Java - that would be pretty complicated and unwarranted for almost all applications.
    b. Don't mix the two toolkits unless you really need to.  An example of a real need is that you have a huge swing app based upon the NetBeans platform and you want to embed a couple of JavaFX graphs in there.  But if your application is only pretty small (e.g., it took less than a month to write), just choose one toolkit or the other and implement your application entirely in that toolkit.  If your entire application is in Swing and you are just using JavaFX because you think its TreeView is easier to program, don't do that; either learn how to use Swing's tree control and use that or rewrite your entire application in JavaFX.  Reasons for my suggestion are listed here: JavaFX Tip 9: Do Not Mix Swing / JavaFX
    c. If you do need to mix the two toolkits, the answer of which approach to use will be obvious.  If you have a huge Swing app and want to embed one or two JavaFX components in it, then use JFXPanel.  If you have a huge JavaFX app and want to embed one or two Swing components in it, use a SwingNode.  Once you do start mixing the two toolkits be very careful about thread processing, which you are almost certain screw up at least during development, no matter how an experienced a developer you are.  Also sharing the data between the Swing and JavaFX components will be trivial as you are now running everything in the same application within the virtual machine and it is all just Java so you can just pass data around as parameters to constructors and method calls, the same way you usually do in a Java program, you can even use static classes and data references to share data but usually a dependency injection framework is better if you are going to do that - personally I'd just stick to simply passing data through method calls.

  • Creating javaFX Image with InputStream

    Hi,
    I have dataset(Medical Image data), i want to build a javaFX Image,
    Can some one help me how can i construct the image from this.
    is there any way creating a image other than using url?
    Thanks....

    Try this:
    var stream = A.class.getResourceAsStream( "lion1.png");
    Stage {
        title: "Image from stream"
        width: 250
        height: 280
        scene: Scene {
            content: [
                ImageView {
                    image: Image {
                        impl_source: stream
    }

  • Problem with Java-Packages in JavaFX-Scripts

    Hello!
    What I'm trying to do is using a class I've built in my project in a JavaFX-Script, my problem is that the compiler keeps telling me my package wouldn't exist.
    My filestructure is basically the following:
    src
    |-com.foo.java
    |-- MyClass.java
    |-com.foo.javafx
    |-- MyFXScript.fx
    I've tried importing the package or just writing the fully qualified classname when trying to create an instance, the messages didn't differ. I'm not at home right now so I don't remember the exact compiler-message, but it was something like "Package does not exist: com.foo.java".
    Any ideas? :-)
    Kind regards,
    Joshua
    Edited by: gnrx on Jan 12, 2009 5:55 AM

    It works on my system.
    MyClass.java
    package com.foo.java;
    public class MyClass {
        @Override
        public String toString() {
            return "My Class";
    MyFXScript.fx
    package com.foo.javafx;
    import com.foo.java.*;
    var myClass = new MyClass();
    println(myClass);standard-run:
    My Class
    browser-run:
    jws-run:
    midp-run:
    run:
    BUILD SUCCESSFUL (total time: 3 seconds)

  • How to implement a java class in javafx?

    public interface WarningEvent {
        public void warningHandler ();
    function test ():Void {
            var warningEvent:WarningEvent = new WarningEvent() {
                public void warnHandler(){
        }I am trying to implement java method inside javafx, but without luck. I also tried override with javafx syntax, but still cannot get it. Any one could help on this?
    Thanks.

    1) Get rid of the keyword new
    2) Get rid of braces ()
    3) For the function declaration, use the JavaFX syntax, not the Java syntax!
    function test ():Void {
            var warningEvent:WarningEvent = WarningEvent {
                override public warnHandler():Void {
    }Your class need to have a default constructor (the one without any argument) to be able to do this (and in this case it works because you have an interface instead).

  • How to call a java program in javafx class(Urgent) and even vice versa

    Hi all,
    Here I have two questions:
    1)
    Please let me know how to call a javafx in java program...
    I tried with the following code but it is not working..
    The below is the java program in which I made a call to the Fx program.
    FxMainLauncher.java
    import net.java.javafx.FXShell;
    public class FxMainLauncher {
    public static void main(String[] args) throws Exception {
    FXShell.main(new String[] {"HelloWorld.fx"});
    2) How to call a java program in javafx class
    Here is my javafx program
    import check.*;
    import javafx.ui.*
    var instance = new MyJava();
    //visible:true
    System.out.println("Number is: {instance}");
    Here is my java program
    public class MyJava {
    public static void main(String args[])
    System.out.println("JAVAFX TO JAVA");
    Even this is not working please let me know ASAP
    Thanks in advance,
    V.Srilakshmi

    GOT IT !!!
    I had to change the name of the method in .h file generated by javah command. On doing
    javac -d ../../classes HelloWorld.java
    go to the ../../classes directory (where you have the class file) and do
    javah HelloWorld
    I got a HelloWorld.h file in which I had
    JNIEXPORT void JNICALL Java_HelloWorld_display(JNIEnv *, jobject);
    I added the package name too:
    JNIEXPORT void JNICALL Java_GUI_HelloWorld_display(JNIEnv *, jobject);
    The HelloWorldImp.c file should have the same name (ie with package) and be in the same directory(ie ../../classes)
    compile and build the shared library to get "libhello.so" file
    gcc -c -fPIC -I/usr/lib/j2sdk1.3/include -I/usr/lib/j2sdk1.3/include/linux HelloWorldImp.c
    gives .o file
    gcc -shared -o libhello.so HelloWorldImp.o
    gives .so file
    then run java with the command in my first message. It works.
    Thanks for the reply "thedracle".

  • Java API of javafx?

    Hi,
    Is there some kind of Java API of javafx? I don't want to learn javafx's scripting language, and although I understand Sun's decision to give a scripting interface, I don't want to learn it b/c it will make me violently vomit. Unfortunately javafx apps look gorgeous and integrate well with 3rd party graphics design apps.
    All javafx code gets compiled into a .class file anyway, so the API should be available, right? Where can I find it? Or is it still under active development and not yet released?
    Thanks,
    Mark

    You can call Java code directly from JavaFX if you really want to subvert it, however as others have stated you will certainly have to learn the new syntax to take full advantage of it. As a personal aside, I've found that much of what JavaFX offers isn't readily available in Java. Granted, certain libraries exist that are analogous to what JavaFX is trying to accomplish (like http://processing.org/) but I've found JavaFX to be much easier to get the hang of. Having said all that, I agree that they should have maintained similarities between Java and JavaFX like the use of && instead of AND and the way loops are iterated but really there are only a handful of new syntax. Don't forget, JavaFX is not procedural and Java is (generally) and much of the new syntax reflects that, while also paying tribute to some other popular technologies like actionScript and JavaScript.
    All things considered, I think they choose well and produced something that seamlessly works with Java but is appealing to developers from Java and non-Java backgrounds alike. Personally, I picked up Java and JavaFX at the same time and despite the differences I haven't had any real syntax confusion.

  • How to add javafx image project in my jsp page ?

    how to add javafx image project in my jsp page ?

    Create your JavaFX application as an Applet... then embed the applet object inside your html. I'm sure if you create a javafx netbeans project and hit build... you get a html file that shows you how to load the built binary output into the page.

  • Handling/passing Java exceptions to JavaFX

    My Java class has a try/catch statement indicating a communication error to MySQL server. I want to add a user-friendly dialog box in my JavaFX application in the event my java class cannot access the database.
    What's the best way of handling Java exceptions within JavaFX?
    Cheers!

    Rethrow an exception and catch it in the call in JavaFX code?

  • New to JavaFX--Calling Java objects from JavaFX

    Hello,
    I am a Java developer who is new to JavaFX. I am having no luck in finding a tutorial that exhibits more than just fun effects. I need to be able to call existing classes from a JavaFX GUI. Can anyone offer any assistance on this? It's very frustrating because this should be a simple task. If we are faced with having to rewrite existing code, we will probably be forced to abandon JavaFX. I hope this is not the case.
    Thanks!

    The answer is yes. The impementation is -
    If you have classes that you keep as library classes that you intend for use irrespective of the platform, then I suspect that you have already written them with no view content. For those, including them in your JavaFX is not really different to using them in Java. I am just learning JavaFX too and the most important lesson for us to learn is that 'JavaFX is Java with FX on the end of it'. I know the strickly come dancing set will say 'oh but what about types'. Well I have found no trouble at all with types, basic or my own, we are in object world so long as the compiler has the class object and we have all stuck to the rules then it has all it needs to act on your objects.
    So your non-View classes can be used as you always use them -
    import mylib'
    var somethingFromMyLibOfClasses = new mylib.ClassThatDoesSomethingVeryClever();
    It is then just a matter of arranging a FX trigger of some kind (trigger/event/timer/bind) to call the function in your library.
    Which triggers and when are the part I am still finding difficult. The basic GUI events are fine (onMouseClick etc), it is 'bind' that is troublesome.
    Binding something in your code to a 'property' of the display element is easy enough, but binding where you have no external variable that relates to 'Property' value is less clear. For example you may have to change a form contents due to a trigger sent from a remote database.
    You have some in the forum talking of 'resize your window a few pixels to force a redraw so that your code can be retriggered'. Others are using timers at high tick frequency to for an update. such as changing a property that you can't see.
    That is utter nonsense, if you look up the proper description of bind then it becomes obvious. Bind can be a two way thing, you can change a value in your element from outside, but you can also change a value outside of your element from within your element.
    Equally that trigger can be your own code. There is no need of trickery to update Scenes, the writters of JavaFX already have it sussed.
    The Sun web site has some great tutirials, but as a personal favourite that cleared up som of the junk about JavaFX that was building up in my mind I reccommend you spend a bit of time here [JavaFX Refference|http://openjfx.java.sun.com/current-build/doc/reference/JavaFXReference.html]
    Not the best layout you will ever see, but it is the best source I have found, then if you use that along side [Master Index|http://java.sun.com/javafx/1.2/docs/api/javafx.stage/javafx.stage.Stage.html] hopefully you will find, as I did, that you do not have to think differently to make use of the FX on the end of Java.

  • Difference between Java applet and JavaFX

    Hello, all!
    I am studying javaFX in general. As far as I understand there is no main difference between java applet and javafx, except javafx has different syntax and library simple to use. Is it right?

    Basically, yes. But as you point out, it is supposed to be faster to develop in JavaFX...
    For example, Processing allows to export to applet, and is strong on doing graphics, but to see if user has clicked on a circle, you have to check the mouse coordinates against the circle coordinates, or create your own Circle class: it is at a much lower level.
    Likewise, you can use gaming frameworks like Slick2D or PulpCore, but they might be lacking on GUI (but perhaps faster). Or use Apache's Pivot, strong on GUI, but perhaps lacking a bit on graphics and animation.
    It depends on your needs, if you prefer to stick to Java, etc.

  • Converting a BufferedImage to an Image

    I have a program with some BufferedImages that the user needs to be able to drag around the screen.
    1) The dragging process is very sluggish when I use BufferedImages, but not when I use normal Images. Is this normal, or is something wrong with my program?
    2) If using Images is the only way to fix this problem, how do I draw my BufferedImages into Images or convert them to Images? They have to start out as BufferedImages so that they can undergo a one-time rescaling operation.

    Where can I find out what a profiler is and how to use one?
    Here is an abbreviated version of the code. A non-buffered Image is available for dragging here, and it too drags sluggishly unless you eliminate the line of code that draws the BufferedImages to the screen. There is probably something else wrong with this program, because at one point dragging the BufferedImages did work well. When the problem appeared I tore my code apart trying to find out what I had messed up, but after reversing all the recent changes I had not eliminated the problem and was left mystified.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.lang.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    public class Hanoi2 extends JFrame implements MouseListener, MouseMotionListener, ActionListener{
         private GraphicsDevice device;
         Landscape panel=new Landscape();
         JMenuBar bar=new JMenuBar();
         JMenu menu1=new JMenu("Game");
         JMenuItem m11=new JMenuItem("New Game");
         JMenuItem m12=new JMenuItem("Save Game");
         JMenuItem m13=new JMenuItem("Load Game");
         JMenuItem m14=new JMenuItem("Exit");
         JMenu menu2=new JMenu("Options");
         JMenu m21=new JMenu("Disk Number");
         JRadioButtonMenuItem sm11=new JRadioButtonMenuItem("4");
         JRadioButtonMenuItem sm12=new JRadioButtonMenuItem("5");
         JRadioButtonMenuItem sm13=new JRadioButtonMenuItem("6");
         JRadioButtonMenuItem sm14=new JRadioButtonMenuItem("7");
         JRadioButtonMenuItem sm15=new JRadioButtonMenuItem("8");
         JRadioButtonMenuItem sm16=new JRadioButtonMenuItem("9");
         JRadioButtonMenuItem sm17=new JRadioButtonMenuItem("10");
         JMenu m22=new JMenu("Disk Set");
         JRadioButtonMenuItem sm21=new JRadioButtonMenuItem("Stone");
         JRadioButtonMenuItem sm22=new JRadioButtonMenuItem("Glass");
         JRadioButtonMenuItem sm23=new JRadioButtonMenuItem("Pattern");
         JMenu m23=new JMenu("Backdrop");
         JRadioButtonMenuItem sm31=new JRadioButtonMenuItem("Spirals");
         JRadioButtonMenuItem sm32=new JRadioButtonMenuItem("Stars");
         JRadioButtonMenuItem sm33=new JRadioButtonMenuItem("Dots and Flowers");
         JRadioButtonMenuItem sm34=new JRadioButtonMenuItem("Psychedelic");
         JRadioButtonMenuItem sm35=new JRadioButtonMenuItem("Smart Sky");
         JMenu menu3=new JMenu("Help");
         JMenuItem m31=new JMenuItem("Instructions");
         JMenuItem m32=new JMenuItem("About");
         int numberdisks=4;
         int numberdisksthisgame=0;
         int diskset=0;
         int backdrop=0;
         boolean isgame=false;
         int[] diskstack={-1,-1,-1};
         int[][] poledisks=new int[3][10];
         Image[] backs=new Image[5];
         Image[][] disks=new Image[3][10];
         Image[] poles=new Image[3];
         Image cloth;
         Image company;
         Image title;
         MediaTracker tracker=new MediaTracker(this);
         int[][] diskspot=new int[2][10];
         BufferedImage[][] disksr=new BufferedImage[3][10];
         Graphics2D[][] disksg=new Graphics2D[3][10];
         BufferedImage[] polesr=new BufferedImage[3];
         Graphics2D[] polesg=new Graphics2D[3];
         boolean goer=false;
         public Hanoi2(GraphicsDevice device){
         super(device.getDefaultConfiguration());
         this.device=device;
         setTitle("Tower of Hanoi");
         setDefaultCloseOperation(EXIT_ON_CLOSE);
         title=Toolkit.getDefaultToolkit().getImage("Hanoi/Title.gif");
         company=Toolkit.getDefaultToolkit().getImage("Hanoi/Company.gif");
         cloth=Toolkit.getDefaultToolkit().getImage("Hanoi/clothspread2.gif");
         poles[0]=Toolkit.getDefaultToolkit().getImage("Hanoi/woodpole1.gif");
         poles[1]=Toolkit.getDefaultToolkit().getImage("Hanoi/woodpole2.gif");
         poles[2]=Toolkit.getDefaultToolkit().getImage("Hanoi/woodpole3.gif");
         backs[0]=Toolkit.getDefaultToolkit().getImage("Hanoi/background1.gif");
         backs[1]=Toolkit.getDefaultToolkit().getImage("Hanoi/background2.gif");
         backs[2]=Toolkit.getDefaultToolkit().getImage("Hanoi/background3.gif");
         backs[3]=Toolkit.getDefaultToolkit().getImage("Hanoi/background4.gif");
         backs[4]=Toolkit.getDefaultToolkit().getImage("Hanoi/background5.gif");
         disks[0][0]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone1.gif");
         disks[0][1]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone2.gif");
         disks[0][2]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone3.gif");
         disks[0][3]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone4.gif");
         disks[0][4]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone5.gif");
         disks[0][5]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone6.gif");
         disks[0][6]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone7.gif");
         disks[0][7]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone8.gif");
         disks[0][8]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone9.gif");
         disks[0][9]=Toolkit.getDefaultToolkit().getImage("Hanoi/stone10.gif");
         disks[1][0]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass1.gif");
         disks[1][1]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass2.gif");
         disks[1][2]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass3.gif");
         disks[1][3]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass4.gif");
         disks[1][4]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass5.gif");
         disks[1][5]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass6.gif");
         disks[1][6]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass7.gif");
         disks[1][7]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass8.gif");
         disks[1][8]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass9.gif");
         disks[1][9]=Toolkit.getDefaultToolkit().getImage("Hanoi/glass10.gif");
         disks[2][0]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve1.gif");
         disks[2][1]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve2.gif");
         disks[2][2]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve3.gif");
         disks[2][3]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve4.gif");
         disks[2][4]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve5.gif");
         disks[2][5]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve6.gif");
         disks[2][6]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve7.gif");
         disks[2][7]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve8.gif");
         disks[2][8]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve9.gif");
         disks[2][9]=Toolkit.getDefaultToolkit().getImage("Hanoi/carve10.gif");
         for(int i=0; i<10; i++){
         tracker.addImage(disks[0], 0);
         tracker.addImage(disks[1][i], 0);
         tracker.addImage(disks[2][i], 0);}
         tracker.addImage(poles[0], 0);
         tracker.addImage(poles[2], 0);
         tracker.addImage(poles[1], 0);
         try{
         tracker.waitForID(0);
         }catch(Exception e){}
         tracker.addImage(title, 0);
         tracker.addImage(company, 0);
         tracker.addImage(backs[0], 0);
         tracker.addImage(backs[1], 0);
         tracker.addImage(backs[2], 0);
         tracker.addImage(backs[3], 0);
         tracker.addImage(backs[4], 0);
         tracker.addImage(cloth, 0);
         for(int i=0; i<3; i++){
         polesr[i]=new BufferedImage(11,350,BufferedImage.TYPE_INT_RGB);
         polesg[i]=polesr[i].createGraphics();}
         for(int v=0; v<3; v++){
         for(int i=0; i<10; i++){
         disksr[v][i]=new BufferedImage(65+i*15,35,BufferedImage.TYPE_INT_RGB);
         disksg[v][i]=disksr[v][i].createGraphics();
         int y=0;
         int z=-75;
         int q=0;
         for(int x=0; x<65+i*15+2; x+=2){
         if(65+i*15<81) q=7;
         if((65+i*15>80)&&(65+i*15<111)) q=6;
         if((65+i*15>110)&&(65+i*15<141)) q=4;
         if((65+i*15>140)&&(65+i*15<186)) q=3;
         if(65+i*15>185) q=2;
         if((x<(65+i*15)/8)||(x>(65+i*15)-((65+i*15)/8))) {q=q+3;}
         else if((x<(65+i*15)/4)||(x>(65+i*15)-((65+i*15)/4))) {q=q+2;}
         else if((x<(65+i*15)/3)||(x>(65+i*15)-((65+i*15)/3))) {q=q+1;}
         if(x<(65+i*15)/4) z+=q;
         if(x>=(65+i*15)/4) z-=q;
         BufferedImage bi=new BufferedImage(65+i*15,35,BufferedImage.TYPE_INT_RGB);
         BufferedImage bi2=new BufferedImage(65+i*15,35,BufferedImage.TYPE_INT_RGB);
         Graphics2D big;
         big=bi.createGraphics();
         big.drawImage(disks[v][i],0,0,this);
         RescaleOp rop = new RescaleOp(1.1f,(float)(z), null);
    rop.filter(bi,bi2);
         Rectangle2D.Double rect=new Rectangle2D.Double(65+i*15-x,0,4,35);
         disksg[v][i].setClip(rect);
         disksg[v][i].drawImage(bi2,0,0,this);}
         if((v==2)&&(i==9))
         goer=true;}}
         setJMenuBar(bar);
         bar.add(menu1);
         bar.add(menu2);
         bar.add(menu3);
         menu1.add(m11);
         menu1.add(m12);
         menu1.add(m13);
         menu1.add(m14);
         menu2.add(m21);
         menu2.add(m22);
         menu2.add(m23);
         m11.addActionListener(this);
         m12.addActionListener(this);
         m13.addActionListener(this);
         m14.addActionListener(this);
         ButtonGroup group1 = new ButtonGroup();
         m21.add(sm11);
         m21.add(sm12);
         m21.add(sm13);
         m21.add(sm14);
         m21.add(sm15);
         m21.add(sm16);
         m21.add(sm17);
         group1.add(sm11);
         group1.add(sm12);
         group1.add(sm13);
         group1.add(sm14);
         group1.add(sm15);
         group1.add(sm16);
         group1.add(sm17);
         sm11.addActionListener(this);
         sm12.addActionListener(this);
         sm13.addActionListener(this);
         sm14.addActionListener(this);
         sm15.addActionListener(this);
         sm16.addActionListener(this);
         sm17.addActionListener(this);
         ButtonGroup group2 = new ButtonGroup();
         m22.add(sm21);
         m22.add(sm22);
         m22.add(sm23);
         group2.add(sm21);
         group2.add(sm22);
         group2.add(sm23);
         sm21.addActionListener(this);
         sm22.addActionListener(this);
         sm23.addActionListener(this);
         ButtonGroup group3 = new ButtonGroup();
         m23.add(sm31);
         m23.add(sm32);
         m23.add(sm33);
         m23.add(sm34);
         m23.add(sm35);
         group3.add(sm31);
         group3.add(sm32);
         group3.add(sm33);
         group3.add(sm34);
         group3.add(sm35);
         sm31.addActionListener(this);
         sm32.addActionListener(this);
         sm33.addActionListener(this);
         sm34.addActionListener(this);
         sm35.addActionListener(this);
         menu3.add(m31);
         menu3.add(m32);
         m31.addActionListener(this);
         m32.addActionListener(this);}
         int placex=0;
         int placey=0;
         class Landscape extends JPanel{
         public void paintComponent(Graphics g){
         super.paintComponent(g);
         Graphics2D g2 = (Graphics2D) g;
         try{
         tracker.waitForAll();
         }catch (InterruptedException exc){}
         if((tracker.checkAll())&&(goer==true)){
         if(isgame==false){
         g.drawImage(title,68,75,this);
         g.drawImage(company,77,250,this);}
         if(isgame==true){
         g.drawImage(backs[backdrop],0,0,this);
         g.drawImage(cloth,0,462,this);
         g.drawImage(disks[0][0],placex,placey,this);
         for(int i=0; i<10; i++){
         g2.drawImage(disksr[diskset][i],diskspot[0][i],diskspot[1][i],this);}}}}}
         public static void main(String[] args){
         try {
    UIManager.setLookAndFeel(
    UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) { }
         GraphicsEnvironment env = GraphicsEnvironment.
    getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = env.getScreenDevices();
    for (int i = 0; i < 1 /* devices.length */; i++) {
    Hanoi2 box = new Hanoi2(devices[i]);
    box.initComponents(box.getContentPane());
    box.begin();}}
         private void initComponents(Container c) {
         panel.setBackground(new java.awt.Color(201%256, 27%256, 27%256));
         panel.setPreferredSize(new Dimension(696,500));
         setContentPane(panel);}
         public void setVisible(boolean isVis) {
    super.setVisible(isVis);}
         public void begin() {
         addMouseListener(this);
         addMouseMotionListener(this);
         pack();
         setVisible(true);
         setLocationRelativeTo(null);}
         public void actionPerformed(ActionEvent e) {
         if(e.getSource()==m11){
         isgame=true;
         numberdisksthisgame=numberdisks;
         for(int i=0; i<10; i++){
         diskspot[0][i]=25+(9-i)*7;
         diskspot[1][i]=462-numberdisks*35+i*35;}
         repaint();}
    if(e.getSource()==m14){
         System.exit(0);}}
         boolean[] dragdisk={false,false,false,false,false,false,false,false,false,false};
         boolean[] istop={true,false,false,false,false,false,false,false,false,false};
         int xcheck=0;
         int ycheck=0;
         boolean dragother=false;
         int currentpole=0;
         public void mousePressed(MouseEvent e){
         int y=e.getY()-60;
         if(isgame==true){
         if((e.getX()>placex)&&(e.getX()<placex+65)&&(y>placey)&&(y<placey+35)){
         dragother=true;}
         for(int i=0; i<numberdisksthisgame; i++){
         if((e.getX()>diskspot[0][i])&&(e.getX()<diskspot[0][i]+(65+i*15))&&(y>diskspot[1][i])&&
         (y<diskspot[1][i]+35)){
         dragdisk[i]=true;
         xcheck=e.getX()-diskspot[0][i];
         ycheck=y-diskspot[1][i];}}}}
         boolean down=true;
         public void mouseDragged(MouseEvent e){
         int y=e.getY()-60;
         if(dragother==true){
         placex=e.getX();
         placey=y;
         repaint();}
         for(int i=0; i<numberdisksthisgame; i++){
         if((isgame==true)&&(dragdisk[i]==true)){
         diskspot[1][i]=y-ycheck;
         diskspot[0][i]=e.getX()-xcheck;
         repaint();}}}
         int currentpole2=0;
         int[] diskloca={25,250,475};
         public void mouseReleased(MouseEvent e){
         for(int i=0; i<numberdisksthisgame; i++){
         if(dragdisk[i]==true){
         dragdisk[i]=false;}}}
         public void mouseMoved(MouseEvent e){}
         public void mouseEntered(MouseEvent e){}
         public void mouseExited(MouseEvent e){}
         public void mouseClicked(MouseEvent e){}}

  • From BufferedImage to faster Image...

    Hello all.
    I have to use JAI, Java2D, & ImageIO to read a TIFF and convert it into a transparent PNG. It results in a BufferedImage, of course. However, I noticed that the BufferedImage does not perform as quickly as the Image that can be created by the Toolkit (or obtained from the ImageIcon). This is true at least for Windows. For example, on Windows, the image is an instance of sun.awt.windows.WImage. However I have to save the image and reload it in order to get this other image
    My question is this: Is there any way to directly convert a BufferedImage to type WImage, or to whatever native Image type exists on a particular platform. Does Java provide such a mechanism? Does anyone know of a way to do this (w/o having to write and re-read the image)?
    Thank you in advance for your input.

    GraphicsConfiguration.getCompatibleImage() gives you this kind of image. Use something like
    Image originalImage = // load your image here
    BufferedImage bI = GraphicsConfiguration.getCompatibleImage();
    Graphics g = bI.getGraphics();
    g.draw(0,0,originalImage,null); // draw old image into new bI
    not sure about the exact method signatures, just what I remember.

Maybe you are looking for

  • I want to download music purchases made on my iphone onto itunes on my pc and can't argghhh

    iTunes has been running great, now I have bought a new laptop and want to use iTunes on it instead.  In the meantime I have made a few purchases on my iPhone.  I have iTunes up and running on the new laptop but seem unable to get the new purchases fr

  • Using rich text editor in new asset type input form

    Hey everyone, I'm currently trying to create assets based on a newly created asset type (which I of course, created). However, the STORAGE property I declared in the asset definition file is to support formatted text, which would normally be pasted f

  • PB will only start in target disc mode, please help

    On normal start up, I get the "You need to restart your computer......" message with start symbol behind the writing. every time I try to restart the same thing happens. I've tried all the keys on start up tricks and the only ones that work are optio

  • Invisible audio tracks in timeline

    I've been working on a music video, so I've got multiple video clips in my timeline, but I've unlinked them from their original audio files and subsequently deleted the audio tracks they were assigned to. The only audio track I've kept is the origina

  • Multiple instances of EIGRP or static routes

    I'm building a network which needs to have All but one of it's private networks pass through a DMVPN, all the routes are advertised through EIGRP, that part works great! I have a private VLAN that only has access onto the internet, the address is Nat