Substitute of java.awt.ToolKit.getDefaultToolKit.beep()

Hello everybody. I am designing a Swing Application and there I am using java.awt.ToolKit.getDefaultToolKit.beep() method to generate sound in various operations. I want to know is it possible to generate own sound as a substitute of this method? I think it is possible. How can I do this? Thank you.

Thank you for giving reply.
As I wish to play .mp3 file I had downloaded an API from Javalobby . I tried it, here is my code :
package player;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
* @author Tanmoy
* @Super Scientific Calculator
* @version 1.2010
public class Player {
     private File audioFile;
     public Player(String path) {
          this.audioFile = new File(path);
     public void play() {
          AudioInputStream din = null;
          try {
               AudioInputStream in = AudioSystem.getAudioInputStream(audioFile);
               AudioFormat baseFormat = in.getFormat();
               AudioFormat decodedFormat = new AudioFormat(
                    AudioFormat.Encoding.PCM_SIGNED,
                    baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
                    baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
                    false);
               din = AudioSystem.getAudioInputStream(decodedFormat, in);
               DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
               SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
               if (line != null) {
                    line.open(decodedFormat);
                    byte[] data = new byte[4096];
                    line.start();
                    int nBytesRead;
                    while ((nBytesRead = din.read(data, 0, data.length)) != -1) {
                         line.write(data, 0, nBytesRead);
                    line.drain();
                    line.stop();
                    line.close();
                    din.close();
          } catch (Exception e) {
          } finally {
               if (din != null) {
                    try {
                         din.close();
                    } catch (IOException e) {
}And the calling, piece of code is :
try {
                              Parser parser = new Parser(parsingString, displayPanel.getCurrentBase(),
                                   displayPanel.getCurrentBase(), displayPanel.getTrigoMode(),
                                   displayPanel.getScale());
                              String output = parser.solve();
                              displayPanel.outputTextField.setText(output);
                              displayPanel.outputTextField.setCaretPosition(displayPanel.outputTextField.getText().length());
                              displayPanel.charLabel.setText((Integer.toString(output.length())));
                              if (message == null) {
                                   message = "No Exception";
                         } catch (InvalidSyntaxException invalidSyntaxException) {
                              message = invalidSyntaxException.getMessage();
                              JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE);
                              new Player("/resources/what_the_hell.mp3").play();
                              displayPanel.outputTextField.setText("0");
                              displayPanel.charLabel.setText("0");
                         }But I can not able to here the sound.
What to do now?
Thank you.

Similar Messages

  • Toolkit.getDefaultToolkit().beep() does not beep!

    Hi,everyone:
    I met a problem when I used Toolkit.getDefaultToolkit().beep() .
    When running, no beep can be heard!
    My Environment is as follows:
    Hardware: Dell dimension 2400
    OS : Windows 2003 Enterprise Edition
    JDK : J2SDK1.4.2
    Code :
    Toolkit.getDefaultToolkit().beep();
    (In java application)
    Does My enviornment not support this operation? Can anyone tell me?
    Thank you.

    Yes, its a bit buggy. Does this work for you?
    ** Will you please tell me where to find evidence that this is a bit buggy?
    Thank you.
    System.out.print ( "\007" );In my java application, System.out.print ( "\007" ) works.
    ** But when I write it in my applet, no beep can be heard!
    import java.applet.*;
    import java.awt.*;
    public class MyBeepApplet extends Applet
        int cx = 50;
        int cy = 50;
        String msg="";
        public boolean mouseDown(Event e, int x, int y)
            msg = " Beep?";
            cx = x;
            cy = y;   
            for(int i=0; i<260;i++){
                System.out.print("\007");
                System.out.flush();
            repaint();      
            return true;
        public void paint(Graphics g)
            g.drawString(msg, cx,cy);
    }

  • Java.awt.Toolkit - Coldfusion - HELP

    Greetings.
    I am having a hard time with the following code:
    <cfobject action="create" type="java" class="java.awt.Toolkit" name="fileObj">
    <cfscript>
    img = fileObj.getDefaultToolkit().getImage("images/products/39321.jpg");
    width = img.getwidth();
    height = img.getheight();
    </cfscript>
    <cfoutput>#height#</cfoutput>
    I keep getting the following error:
    java.lang.NoClassDefFoundError
    My version of Java is 1.4.2. I'm running Redhat Linux 4.0. Coldfusion MX 6.1.
    I know this isn't a Coldfusion forum, but I really need some help here.
    I'm new to Java technologies, so any help will be greatly appreciated.

    can ColdFusion load Java objects?
    Presuming that it can, then ColdFusion probably needs some configuration to tell it the Java directory or where the class files are (JavaHome/jre/lib/rt.jar)

  • Deprecation warning for getFontMetrics(java.awt.Font) in java.awt.Toolkit

    Hi all,
    When I use the following code
    JComponent c;
    FontMetrics metrics = getToolkit().getFontMetrics(c.getFont());
    I get this following warning during compilation:-
    warning: getFontMetrics(java.awt.Font) in java.awt.Toolkit has been deprecated
    JDK suggests to use getLineMetrics() of the Font class.
    But there's an issue with that: if I use getLineMetrics(), there is no API method that I can use to get the width of a string as opposed to FontMetrics which provides stringWidth(String str) method for that purpose. In fact all the methods in FontMetrics are not mapped into LineMetrics.
    Could anyone please help or provide me at least some pointers on how to tackle this issue so that I can get rid of the deprecated method along with the existing methods mapped to equivalent APIs? The bottomline is that I should be able to maintain the existing functinality of my application for those part of code that uses getToolkit().getFontMetrics().
    Thank you for your help in advance.
    -Sanjoy Das

    Use Graphics.getFontMetrics(font) instead.
    After creation your frame and calling frame.show();
    You can access it like that
    frame.show();
    frame.getGraphics().getFontMetrics(new Font("Arial",0,10));
    before showing graphics is null.
    Or just create a BufferedImage and ask it for graphics.
    BufferedImage img=new BufferedImage(...);
    img.getGraphics().getFontMetrics(font);
    regards
    Stas

  • Quality of Cursors created with java.awt.Toolkit(createCutsomCursor)

    Hi -
    I encountered a small problem while creating my own cursors for my Java application , I used the java.awt.Toolkit Objects createCustomCursor method to use a .GIF image as a cursor ... it worked but the quality of that cursor is horrible, the outline is rough ... I tried the same with a transparent PNG file afterwards unfortunately the same result , does anyone know why the quality is that bad or may this just be a problem of the choosen color pool ?
    Help would be very appreciated since I have no clue how to use .cur files ... seems like a non supported format , in case someone knows how to import those it would help a lot if you would drop some lines of code.
    I am currently using Java 2 SDK 1.4.0_01 , newest version.
    Thanks for you time and thanks in advance for possible answers
    -- Harald Scheckenbacher

    I noticed this problem too. It looks like the routine is generating cursors which are scaled to to the maximum size of the system. On my win XP system,
    Dimension dim = toolkit.getBestCursorSize(256, 256);
    int maxColors = toolkit.getMaximumCursorColors();
    return 32,32 and 256 respectively
    If I provide a 16x16, all the pixels have been pixel doubled. If I specify a 32x32 image, then the cursor looks perfect. This looks like a bug for the java folks. Not sure why someone would ever want a cursor image to be pixel scaled.
              

  • Java.awt.Toolkit.getScreenSize()

    Hello again world.
    I'm a little confused here. I have these two lines in a program:
    Toolkit tKit = Toolkit.getDefaultToolkit();
    Dimension size = tKit.getScreenSize();
    Reading the API, I notice that "getScreenSize()" is declared abstract.
    I was under the impression that abstract methods need to be overridden and have no actual code.
    if (that's correct)
       return "What's up with that second line?";
    else
       return "What's the deal with abstract methods?";Thank you one and all.
    Ciao for now.

    I don't understand.
    How does that tell me the "getScreenSize()" is
    defined?
    Do I just trust that the abstract method has been
    overridden in that implementation?Abstract methods can only exist in abstract classes and interfaces. A non-abstract class, commonly referred to as a concrete classes, cannot have abstract methods. Only concrete classes can be instanciated, therefore, if you have an instance of some abstract class, then you know that it is an instance of some concrete subclass of the abstract class. This tells you that all abstract methods have been implemented. So, just the simple fact that you actually have an instance of the object tell you that all the abstract methods are implemented.
    Where are these classes anyhow?Doesn't matter. Like someone said earlier, that is the beauty of polymorphism and inheritance.

  • How to prevent the Toolkit.getDefaultToolkit().beep() in JTextField

    Hi,
    I use the JTextField in my application.
    when the user type value in the field e.g. "123456"
    if you press the backspace 5 times the value will be "1" , pressing it again results with ""
    now.....
    pressing it again results a system beep.
    I want to prevent this beep how can I do it??
    thanks

    textField.getDocument().addDocuemntListener(docListener);
    Then implement the removeUpdate(DocumentEvent evt)
    Hope this helps
    Sai Pullabhotla

  • GetDefaultToolkit().beep();

    java.awt.Toolkit.getDefaultToolkit().beep();
    I,ve looked in the api but not very clear(dohhhhhhhhhhh).
    can,t make it work,any help appreciated.
    basic question to you guys but do i need to import the package or is this part of awt anyway.code to show me it working appreciated
    very very new to java
    Thanks again
    cheers

    java.awt.Toolkit.getDefaultToolkit().beep();This should work without imports as you are giving the full class name.
    I would check that the computer you are running on is capable of beeping.
    On a PC this would come out of the crappy built in speaker and not the audio outputs.

  • Java.lang.NoClassDefFoundError Toolkit.getDefaultToolkit

    hi all
    i got this error in a servlet.
    i wrote it on my computer with no errors but, when i moved and executed it on a linux machine it doesn't work:
    java.lang.NoClassDefFoundError at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:703)
    at counter.count.createCounter(count.java:245)
    the code is
    images=Toolkit.getDefaultToolkit().getImage(imageSrc);
    i think that the jdk version is the same on both the computers (1.4.0 or higher), and the code is the same!
    why have i this problem
    thanx
    sandro

    hi rajesh
    you don't know how i'm happy to see your answers!
    i'm so desperate with this problem!
    as you asked to me, this is the full stack trace that tomcat prints when i call my servlet:
    javax.servlet.ServletException: Servlet execution threw an exception
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
         at java.lang.Thread.run(Thread.java:536)
    root cause
    java.lang.NoClassDefFoundError
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:130)
         at java.awt.Toolkit$2.run(Toolkit.java:712)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:703)
         at counter.count.createCounter(count.java:231)
         at counter.count.processRequest(count.java:176)
         at counter.count.doGet(count.java:187)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
         at java.lang.Thread.run(Thread.java:536)
    i don't know if there is some environment variable set up in a different way from my system (w2k) to the real server system (linux), also because i installed the jdk (1.4.0 on windows) without setting anything
    if can help i'll post you soon the version of tomcat/jdk used by linux
    thanx a lot
    sandro

  • Eexception in java.awt.AWTError

    Hi all,
    I am starting with java in my Ubuntu box, and am faced with a problem.
    Consider a simple program
    import javax.swing.*;
    import java.awt.*;
    class helloSwing{
         public static void main(String[] args)
              JFrame myWindow;
              myWindow = new JFrame();
              myWindow.setSize(300,200);
              myWindow.setTitle("My First Swing Application");
              myWindow.setVisible(true);
              System.exit(0);
    }when I run this program
    neo@tathagata:~/Java Progs$ java helloSwingThis is the error I am getting
    Exception in thread "main" java.awt.AWTError: Cannot load AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit
       at java.awt.Toolkit.getDefaultToolkit() (/usr/lib/libgcj.so.6.0.0)
       at java.awt.EventQueue.invokeLater(java.lang.Runnable) (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.SwingUtilities.invokeLater(java.lang.Runnable) (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.RepaintManager.addInvalidComponent(javax.swing.JComponent) (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JComponent.revalidate() (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JComponent.setOpaque(boolean) (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JPanel.JPanel(java.awt.LayoutManager, boolean) (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JPanel.JPanel() (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JRootPane.createGlassPane() (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JRootPane.getGlassPane() (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JRootPane.JRootPane() (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JFrame.createRootPane() (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JFrame.getRootPane() (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JFrame.frameInit() (/usr/lib/libgcj.so.6.0.0)
       at javax.swing.JFrame.JFrame() (/usr/lib/libgcj.so.6.0.0)
       at helloSwing.main(java.lang.String[]) (Unknown Source)
       at gnu.java.lang.MainThread.call_main() (/usr/lib/libgcj.so.6.0.0)
       at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)
    Caused by: java.lang.ClassNotFoundException: gnu.java.awt.peer.gtk.GtkToolkit not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./,file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
       at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
       at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.6.0.0)
       at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
       at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.6.0.0)
       at java.lang.Class.forName(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
       at java.awt.Toolkit.getDefaultToolkit() (/usr/lib/libgcj.so.6.0.0)
       ...17 moreIt appears whenever I'm importing some packages it is creating a problem.
    With whatever little knowledge of Java I have, I suspect I have messed up in the enviornment variables somewhere.
    So here are my
    PATH=/usr/local/qt-x11-opensource-src-4.1.0/bin:/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11:/usr/games:/home/neo/jdk1.3.1_17/bin/:/usr/sbin:/usr/java/jdk1.3.1_17/bin
    JAVA_HOME=/usr/java/jdk1.3.1_17Can anybody suggest me an easy link where classpath is explained?
    I'm am helpless, coz if this is not getting fixed I need to go back to Windoz ..
    leaving Ubuntu, which would be really painful.
    Please help. Thanks in Advance.

    Cool, I glad it's working. And thanks for the kind words (although
    your link sent me some sort of Introduction page, I eventually found
    "Tatha's blog").
    Now all I have to do is get my setup correct. Also 1.5, also Ubuntu.
    I screwed something up when I installed Netbeans, and couldn't
    understand how the Debian people have set things up. I just type the
    executable's path at the command line (easy with *nix) or let Eclipse
    just do the right thing.
    Cheers,
    Peter

  • Problems with awt.Toolkit on Tomcat

    Hello! I'm trying to get the Default Toolkit (java.awt.Toolkit.getDefaultToolkit() ) to determine the scrren size of the client, and Tomcat keeps throwing an Exception - now it's the website's Tomcat and the one on my localhost - there it worked.. Is there another way to determine the client's screen size in JSP (not JavaScript!)?? Thanx!

    first, the previous poster was right - learn how these protocols are interacting before you try something like you want to do - and they're right, you can't use the AWT toolkit to find out ANYTHING about the client.
    HTTP is stateless. so it's like this:
    browser request -> your code on server, jsp completely exeutes, generates html -> html PLAIN old html goes to the browser. in that order. no exceptions. ergo, all your code has executed once the browser starts getting data (buffers on the server not withstanding).
    As to why you're getting the exception, the server you are trying to run it on is most likely running in a mode called "headless", that is, there is no windowing api available to the JVM, so any awt calls will fail anyway. It works on your box because you are probably running a full windowing os, such as windows or Linux with gnome or kde. it just happens to return the correct screen size because that's the screen size of your screen, not the screen of the browser that it's outputting to. (try running your code locally and making your browser window small, you'll be dismayed that the rendered HTML is not the "right" size - because the screen size call was based on your resolution, NOT the size of the requesting browser window.
    if the last 2 sentences don't make sense, re-read them until they do.
    best of luck, sorry you're learing these frustrating lessons this way.

  • Java.awt.Dialog in Java 1.6 has a memory leak

    When a modal Dialog opens a modal sub-dialog, the Dialog stays in memory after both the sub-dialog and the Dialog itself is disposed.
    The field that contains the leaked object is Dialog.modalDialogs (static). The methods which causes the leak are Dialog.modalHide and Dialog.modalShow.
    Whenever a modal Dialog is opened, Dialog.modalShow is called, and adds itself to Dialog.modalDialogs.
    When it closes, Dialog.modalHide is called and removes one copy of itself from Dialog.modalDialogs. Then Dialog.modalShow is called on all previously blocked modal dialogs. When the sub-dialog is opened and closed, Dialog.modalDialogs contains two references to the main Dialog, and only one of them is removed when Dialog.modalHide for that Dialog is called.
    To detect the leak, just put a break point in Dialog.modalHide, after modalDialogs.remove(this);. When opening a Dialog and closing it without opening a sub-dialog, the Dialog.modalDialogs field should be empty. When a sub-dialog was opened and closed before the main Dialog is closed, the Dialog.modalDialogs field contains a reference to the disposed main Dialog.
    This leak does not exist in 1.5.0_10 (no Dialog.modalDialogs field). I have searched the bug database, but I have not found this bug there. Could anyone confirm this?
    A simple code to reproduce the leak:
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    public class Test {
       public static void main(String[] args) {
          final JFrame frame = new JFrame() {
             protected void processWindowEvent(WindowEvent e) {
                super.processWindowEvent(e);
                if (e.getID() == WindowEvent.WINDOW_CLOSING) {
                   System.exit(0);
          JButton button = new JButton("Dialog");
          button.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent aE) {
                JButton subButton = new JButton("SubDialog");
                subButton.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent aE) {
                      JOptionPane.showMessageDialog(frame, "SubDialog");
                JOptionPane.showMessageDialog(frame, subButton);
          frame.getContentPane().add(button);
          frame.pack();
          // Center the window
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          Dimension frameSize = frame.getSize();
          if (frameSize.height > screenSize.height) {
             frameSize.height = screenSize.height;
          if (frameSize.width > screenSize.width) {
             frameSize.width = screenSize.width;
          frame.setLocation((screenSize.width - frameSize.width) / 2,
                (screenSize.height - frameSize.height) / 2);
          frame.setVisible(true);
    }

    Sorry, I just found the bug in the bugdatabase (with google of course,):
    [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6497929]

  • Can I draw *.bmp, *.png in java.awt.canvas ?

    In paint method of my program, I get image from Toolkit like this:
    public class CanCanvas extends Canvas{
    //In loadImage method
    Toolkit.getDefaultToolkit().getImage(
                        getClass().getClassLoader().getResource(
                                  resource.getString("bg.jpg")));
    //.... In paint method
    if (image != null && image.size() > 0) {
                   for (int j = 0; j < image.size(); j++) {
                        Image image1 = (Image) image.elementAt(j);
                        Rectangle rectangle = (Rectangle) imgLocation.elementAt(j);
                        g.drawImage(image1, rectangle.x, offset + rectangle.y,
                                  rectangle.width, rectangle.height, null);
                        i = i <= rectangle.y + rectangle.height + 7 ? rectangle.y
                                  + rectangle.height + 7 : i;But there is something very strange, if my image is *.jpg or *.gif, it runs ok, otherwise -*.bmp, *.png-, it can't draw the image.
    Would anyone tell me why ? Is the reason java.awt.canvas ?
    Thanks in advance ^ ^

    If you'd bother to read the documentation of the methods you're using, you'd know:
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)
    Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG.

  • Toolkit.getDefaultToolkit() in Java service never returns on Windows

    I'm stumped by this problem. It appears to be specific to a single machine as I can reproduce it reliably there but not on other machines. I'm hoping someone has some thoughts on what could be going on.
    Here's the scenario:
    I have Tomcat 5 running as a service on a new installed Windows 2000 Server with up to date service packs and j2sdk1.4.2_06. The service is configure to run headless.
    I have a webapp that performs simple image transformations using AWT and Java2D. Any invocation of Toolkit.getDefaultToolkit() never returns. The thread just sits there consuming no CPU and does not throw an exception. I've narrowed it further to a call to new sun.awt.windows.WToolkit() in getToolKit(). sun.awt.windows.WToolkit is the value of the system property awt.toolkit.
    I can reproduce this exact behavior in a different scenario: the server is running sshd on cygwin. If I ssh to the server and run the following class, it also hangs at new sun.awt.windows.WToolkit().
    public class ToolkitTester
      public static void main(String[] args)
        System.out.println("awt.toolkit = " + System.getProperty("awt.toolkit"));
        System.out.print("Invoking: new sun.awt.windows.WToolkit()... ");
        new sun.awt.windows.WToolkit();
        System.out.println("done.");
    }Running this same class from a shell on the server works just fine.
    I have tried j2sdk1.4.2_03 and jdk1.5 with the same results. I've replicated this second scenario (logging in over ssh) on another Windows 2000 server and do not see this behavior.
    Any thoughts?
    Alon

    Okay. Here's the fix...
    The 'no video card' comment was actually pretty close. The issue appears to be with DirectDraw support. We found this by watching regmon as the testing code ran. Installing a new video driver may have addressed this but so does disabling using DirectDraw as described here:
    http://java.sun.com/products/java-media/2D/forDevelopers/java2dfaq.html#dither
    java -Dsun.java2d.noddraw=true
    Wow. Weird one.
    Alon

  • Java.awt availability in CDC Toolkit ?

    Hi guys and girls,
    I've just tried out the Sun Java Toolkit for CDC 1.0 .. I tried making a simple app which uses awt components, such as Frame, Label, Button .. but the Label and Button just wont compile. I always thought that CDC has all the lib for the j2se's java.awt.
    Quoted from CDC FAQ :
    CDC currently supports three profiles. Foundation Profile provides basic application support APIs without any additional support for GUIs. Personal Basis Profile includes all of the APIs contained in Foundation Profile and adds support for lightweight AWT GUI components and the xlet application model. Personal Profile includes all of the APIs contained in Personal Basis Profile and adds support for full AWT compatibility and the applet application model.
    Do i miss something .. ? Please help pointing out for me ..
    I understand that there's swing from the AGui. So i tried making a new project with a simple class containing a simple JFrame, containing a JPanel which contains a button, which can be clicked to trigger a message type JOptionPane. But when the JOptionPane appears, it fills up the entire screen, i dont quite understand what is wrong.
    Here's the code :
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class HelloWorld {
          * @param args
         public static void main(String[] args) {
              final JFrame frame = new JFrame("Ahiak");
              final JPanel panel = new JPanel(new FlowLayout());
              JButton but = new JButton("Click Me !");
              panel.add(but);
              frame.getContentPane().add(panel);
              but.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        JOptionPane.showMessageDialog(panel, "hahah !");
              frame.setVisible(true);
    }Please show some compassion and click the reply button, lol -_-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I don't know about swing, but you can try using AWT and compile it with J2SE (set compliance to 1.4). The jar file should work on your mobile device with Personal Profile.

Maybe you are looking for