Repaint in Java application (not Applet)

Hi,
I have server application with GUI containing TextArea. On any connection request from client, the application creates a thread which deals with the client request. Once the client request finishes, I want to show the detail of the client which connected to the server in the TextArea. Now I have extended the main server class for the thread class, which deals with the client, and have a method in the main server class which appends string on the textarea. BUT, when thread call that function nothing appears in the TextArea. I have checked that the thread is calling the method correctly, I think I need to repaint the TextArea. How? I am looking for your help. I have tried repaint, it does not work. Appreciate any help in this regard,
Here is the code.
Server side.......
public synchronized void displayMessage( String thismessage) {
     System.out.println("-----> " + thismessage);
     editPan.setEditable(true);
     editPan.append(thismessage + "\n");
public void run() {
while(true) {
try {
server = new ServerSocket( 5000, 100 );
while(listening) {
connection = server.accept();
if(connection != null) {
alertDialog cThread = new alertDialog(connection, errorNumber);
(new Thread(cThread)).start();
errorNumber++;
connection = null;
catch( IOException e ) {
System.out.println("Exception : " + e.toString() );
Client Attender Thread class (alertDialog) which extends server class......
public void run() {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String inputLine = in.readLine();
System.out.println(" " + dateString + " " + inputLine );
// super.editPan.append(" Test from alert.. \n");
     super.displayMessage(" " + dateString + " " + inputLine);
JOptionPane.showMessageDialog(null, inputLine, "Alert....", JOptionPane.ERROR_MESSAGE);
in.close();
} catch (IOException e) {

Be careful when calling Swing methods from outside the EventDispatch thread. If you call a swing method from a thread, you should use SwingUtilities.invokeAndWait() or SwingUtilities.invokeLater().
See http://java.sun.com/docs/books/tutorial/uiswing/mini/threads.html for more details.

Similar Messages

  • How to add images into a java application (not applet)

    Hello,
    I am new in java programming. I would like to know how to add images into a java application (not an applet). If i could get an standard example about how to add a image to a java application, I would apreciated it. Any help will be greatly apreciated.
    Thank you,
    Oscar

    Your' better off looking in the java 2d forum.
    package images;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.FileInputStream;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    /** * LogoImage is a class that is used to load images into the program */
    public class LogoImage extends JPanel {
         private BufferedImage image;
         private int factor = 1; /** Creates a new instance of ImagePanel */
         public LogoImage() {
              this(new Dimension(600, 50));
         public LogoImage(Dimension sz) {
              //setBackground(Color.green);      
              setPreferredSize(sz);
         public void setImage(BufferedImage im) {
              image = im;
              if (im != null) {
                   setPreferredSize(
                        new Dimension(image.getWidth(), image.getHeight()));
              } else {
                   setPreferredSize(new Dimension(200, 200));
         public void setImageSizeFactor(int factor) {
              this.factor = factor;
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              //paint background 
              Graphics2D g2D = (Graphics2D) g;
              //Draw image at its natural size first. 
              if (image != null) {
                   g2D.drawImage(image, null, 0, 0);
         public static LogoImage createImage(String filename) { /* Stream the logo gif file into an image object */
              LogoImage logoImage = new LogoImage();
              BufferedImage image;
              try {
                   FileInputStream fileInput =
                        new FileInputStream("images/" + filename);
                   image = ImageIO.read(fileInput);
                   logoImage =
                        new LogoImage(
                             new Dimension(image.getWidth(), image.getHeight()));
                   fileInput.close();
                   logoImage.setImage(image);
              } catch (Exception e) {
                   System.err.println(e);
              return logoImage;
         public static void main(String[] args) {
              JFrame jf = new JFrame("testImage");
              Container cp = jf.getContentPane();
              cp.add(LogoImage.createImage("logo.gif"), BorderLayout.CENTER);
              jf.setVisible(true);
              jf.pack();
    }Now you can use this class anywhere in your pgram to add a JPanel

  • Help on moving of image across screen(java application,not applet)

    I've searched the entire internet and everything I've found is on java applets and I'm an alien to the differences between an applet and an application.
    This is actually for a java game I'm creating using Eclipse's visual editor and I'm failing miserably.
    What I'm trying to do is to find some java source code that enables me to start an image automatically moving across the screen that only stops when I click on it. I did find some applet codes but when I tried converting it to application code a load of errors popped out.
    Thanks for the help if there's any! I'm getting desperate here because the game's due this friday and I'm stuck at this stage for who knows how long.

    Here is one of the codes I found ,it's not mine but I'm trying to edit it into a java application instead of an applet...Sort of like: ' public class MovingLabels extends JFrame ' or some code that I can copy and paste into another java program.
    * Swing version.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MovingLabels extends JApplet
    implements ActionListener {
    int frameNumber = -1;
    Timer timer;
    boolean frozen = false;
    JLayeredPane layeredPane;
    JLabel bgLabel, fgLabel;
    int fgHeight, fgWidth;
    int bgHeight, bgWidth;
    static String fgFile = "wow.gif";
    static String bgFile = "Spring.jpg";
    //Invoked only when run as an applet.
    public void init() {
    Image bgImage = getImage(getCodeBase(), bgFile);
    Image fgImage = getImage(getCodeBase(), fgFile);
    buildUI(getContentPane(), bgImage, fgImage);
    void buildUI(Container container, Image bgImage, Image fgImage) {
    final ImageIcon bgIcon = new ImageIcon(bgImage);
    final ImageIcon fgIcon = new ImageIcon(fgImage);
    bgWidth = bgIcon.getIconWidth();
    bgHeight = bgIcon.getIconHeight();
    fgWidth = fgIcon.getIconWidth();
    fgHeight = fgIcon.getIconHeight();
    //Set up a timer that calls this object's action handler
    timer = new Timer(100, this); //delay = 100 ms
    timer.setInitialDelay(0);
    timer.setCoalesce(true);
    //Create a label to display the background image.
    bgLabel = new JLabel(bgIcon);
    bgLabel.setOpaque(true);
    bgLabel.setBounds(0, 0, bgWidth, bgHeight);
    //Create a label to display the foreground image.
    fgLabel = new JLabel(fgIcon);
    fgLabel.setBounds(-fgWidth, -fgHeight, fgWidth, fgHeight);
    //Create the layered pane to hold the labels.
    layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(
    new Dimension(bgWidth, bgHeight));
    layeredPane.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (frozen) {
    frozen = false;
    startAnimation();
    } else {
    frozen = true;
    stopAnimation();
    layeredPane.add(bgLabel, new Integer(0)); //low layer
    layeredPane.add(fgLabel, new Integer(1)); //high layer
    container.add(layeredPane, BorderLayout.CENTER);
    //Invoked by the applet browser only.
    public void start() {
    startAnimation();
    //Invoked by the applet browser only.
    public void stop() {
    stopAnimation();
    public synchronized void startAnimation() {
    if (frozen) {
    //Do nothing. The user has requested that we
    //stop changing the image.
    } else {
    //Start animating!
    if (!timer.isRunning()) {
    timer.start();
    public synchronized void stopAnimation() {
    //Stop the animating thread.
    if (timer.isRunning()) {
    timer.stop();
    public void actionPerformed(ActionEvent e) {
    //Advance animation frame.
    frameNumber++;
    //Display it.
    fgLabel.setLocation(
    ((frameNumber*5)
    % (fgWidth + bgWidth))
    - fgWidth,
    (bgHeight - fgHeight)/2);
    //Invoked only when run as an application.
    public static void main(String[] args) {
    Image bgImage = Toolkit.getDefaultToolkit().getImage(
    MovingLabels.bgFile);
    Image fgImage = Toolkit.getDefaultToolkit().getImage(
    MovingLabels.fgFile);
    final MovingLabels movingLabels = new MovingLabels();
    JFrame f = new JFrame("MovingLabels");
    f.addWindowListener(new WindowAdapter() {
    public void windowIconified(WindowEvent e) {
    movingLabels.stopAnimation();
    public void windowDeiconified(WindowEvent e) {
    movingLabels.startAnimation();
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    movingLabels.buildUI(f.getContentPane(), bgImage, fgImage);
    f.setSize(500, 125);
    f.setVisible(true);
    movingLabels.startAnimation();
    }

  • How to change heap memory size for general java applications (not applets)

    Hi. I made a java class which manipulates images and I sometimes get an out of memory error when the files are large. In these cases I can run it successfully from the command line using:
    java -Xms32m -Xmx128m myappbut as I run this class from a firefox extension, I can't use this technique.
    Could some one tell me how to set this globally? I've found a lot of info on setting it for applets in the control panel but that's it. I also tried editing my deployment.properties file by adding:
    deployment.javapi.jre.1.6.0_11-b03.args=-Xmx128mbut none of these options seem to work.
    Thanks for any help.

    Also you can use use [JAVA_TOOL_OPTIONS|http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html#tooloptions], with more documentation here. JAVA_TOOLS_OPTIONS is available since 1.5. There is no direct documentation on [_JAVA_OPTIONS|http://java.sun.com/j2se/1.5.0/docs/guide/2d/flags.html] but was made available since at least 1.3.
    The recent existing forum thread [Java Programming - How to change the default memory limits for java.|http://forums.sun.com/thread.jspa?threadID=5368323&messageID=10615245&start=36] has a long discussion on the issue.
    You specified you are not using applets, but if you do, I would also suggest you use the next Generation Plug-in (since 1.6.0_10) that allows you specify the max memory in the applet without having to instruct the user how to make the change. See [JAVA_ARGUMENTS|https://jdk6.dev.java.net/plugin2/#JAVA_ARGUMENTS] for applets. Java Webstart uses resources.

  • Why does Java Application not working with Macromedia Flash 5 or MX?

    Why does Java Application not working with Macromedia Flash 5 or MX?

    Who says they don't?
    Although I don't know much about those I'd think they should be able to talk to Java Aps using Sockets or request Servlets ...
    Spieler

  • Java "Application not found"

    Hi,
    I wonder of you can help me please, I'm new here and looking for an answer to a problem with my Java files.
    Perhaps I should start a new thread for the new question? Please advise me...
    'Problem' is:
    When I try to open the 'Java' icon on the 'controll panel' page, it says 'Application not found' !? :(
    I have tried re-installing Java but it still says 'Application not found'.
    (There is a plain box on the control panel, where the Java sign should be, but nothing else.)
    Also, when I try to use the BT speed tester, it tells me that 'Java is not installed/enabled on your P.C.'
    I am pretty sure I have ticked the right boxes on 'internet options', (under 'Tools',) but this doesn't work and even when I restart it says: 'restart required'.

    Thank you for your answer,
    I have, as you suggest, already tried removing all Java programmes and then uploading the latest version, that's probably why I'm in such a mess now.
    After I thought I had removed all version that were in my programme files, I attempted to upload the latest version, switching off the fire-wall first.
    But when I checked if it was working OK, it wasn't and I have been going round in a circle for hours re-loading etc.
    Plus I got the same message every time from the BT speedtester, which said 'you do not have java applets or they are not enabled' or something similar, but I did tick the 'enable' box in 'Internet Options' and ticked ''enable scripting' in the Internet Options / Security tag. But, try as I might, could not get the latest JRE files to load up and work right.
    Java script does seem to be working, although the Registry file is missing, but I had to download an earlier version to get it to work, (J2SE Runtime Environment 5.0 update 7. I think maybe one of the 'problems' is not being able to remove one Java programme which was on the computer since June, (Java(TM) 6 update 21.)
    I have tried to remove it several times but can't. ( I do have the 'administrator' rights.)
    I tried removing Java(TM) 6 update 21 again but i will not uninstall, although J2SE RE 5 update 7 has been removed now, I still can't get Java working and it's NOT showing in my programmes list at all, although Java(TM) 6 update 21 is showing in Control Panel programmes list!
    I usually get help from one of my Son's who are both in I.T. but both really busy. I have spent nearly two days now, trying to get Java working properly without much success.
    I am in a 'pickle', I don't know how to reinstate the Java Registry file for starters :( HELP!

  • AS Java applications not starting after patching from 2004s SPS10 to SPS11

    Hi folks,
    after patching our NetWeaver 2004s from SPS10 to SPS11 and the Kernel from 7.00.83.0 to 7.00.95.0, the applications on the AS Java do not start up automatically any more.
    Under the following URLs, the same error is shown:
    http://<fully qualified host name>:51000/
    http://<fully qualified host name>:51000/nwa
    http://<fully qualified host name>:51000/sap/monitoring/SystemInfo
    http://<fully qualified host name>:51000/useradmin/
    http://<fully qualified host name>:51000/wsnavigator
    http://<fully qualified host name>:51000/uddiclient
    503   Service Unavailable
    SAP J2EE Engine/7.00
    Application stopped.
    Details: You have requested an application that is currently stopped
    http://<fully qualified host name>:51000/webdynpro/welcome/Welcome.jsp
    itself works, the two links Content Administrator and Web Dynpro Console both lead to the same 503 error described above
    On http://<fully qualified host name>:51000/irj, the error message is different:
    com.sap.engine.services.deploy.container.ApplicationInManualStartUpException:
    Application sap.com/com.sap.portal.fpn.accessservice cannot be started because is in MANUAL start-up mode..
    Exception id: 09:33_09/05/07_0003_102709250
    See the details for the exception ID in the log file
    In std_server0.out we have the following entries, right after the list of all services that were started:
    ServiceManager started for 39904 ms.
    Framework started for 46720 ms.
    SAP J2EE Engine Version 7.00   PatchLevel is running!
    PatchLevel January 31, 2007 18:37 GMT
    May 9, 2007 9:40:19 AM  com.sap.portal.prt.sapj2ee.error [SAPEngine_Application_Thread[impl:3]_3] Fatal:
    The last line with com.sap.portal.prt.sapj2ee.error is listed another 131 times, and there is also the following message:
    ### Excluding compile:  com.sapportals.portal.prt.jndisupport.util.AbstractHierarchicalContext::lookup
    We can connect to the system using Visual Administrator. Under Server->Services->Deploy, most applications are not running. It is possible to start a few applications manually, others however do not start showing different exceptions.
    We have AS ABAP and AS Java installed, as well as BI, DI, EP and EPC. AS ABAP seems to be running fine.
    We have also noticed the following deviations in JSPM:
    BC_FES_IGS is Release 7.00 SP Level 7.0
    EP_BUILDT is Release 7.00 SP Level 10.0
    SAP_BUILDT is Release 7.00 SP Level 0.0
    All other components except for the Kernel are Release 7.00 SP Level 11.0 or 11.2
    What could be wrong, and what can we do to solve it?
    Best regards,
    Robert Schulte

    Thanks for your response, usha rani
    1. We already tried that, unfortunately, it does not help
    2. We checked the kernel version thoroughly after you suggested it, everything seems to be fine. We had a Unicode kernel before, and we still have one.
    3. safemode is already set to NO
    4. J2EE's default.trace is full of exceptions, but none of them is pointing me into a helpful direction.
    Perhaps the exceptions mean more to someone else:
    java.lang.Exception: Exception loading and instanciating sub-manager:
    com.sap.caf.km.repositorymanager.CAFSecurityManager
    (java.lang.ClassNotFoundException: com.sap.caf.km.repositorymanager.CAFSecurityManager)
    com.sapportals.wcm.repository.runtime.CmConfigurationProvider#
    sap.com/irj#com.sapportals.wcm.repository.runtime.CmConfigurationProvider.Component
    <SetRoomIdForDiscussionObjects> will not be available.
    Failed to load class
    <com.sap.netweaver.coll.room.impl.filter.DiscussionSetRoomIdPropertyFilterManager>
    #J2EE_GUEST#0####1e820b50fe4111db8e780013724175b4#SAPEngine_Application_Thread[impl:3]_22
    ##0#0#Error##Plain###
    java.lang.ClassNotFoundException:
    com.sap.netweaver.coll.room.impl.filter.DiscussionSetRoomIdPropertyFilterManager
    com.sap.portal.prt.runtime.broker#sap.com/irj#
    com.sap.portal.prt.runtime.broker#J2EE_GUEST#0####
    1e820b50fe4111db8e780013724175b4#SAPEngine_Application_Thread[impl:3]_22##0#0#
    Error#1#/System/Server#Java###
    [PortalServiceItem.startServices] service initialisation failed:
    tc.eu.odi.conn.uwl|OdiBridgeService
    [EXCEPTION]
    {0}#1#com.sapportals.portal.prt.core.broker.PortalServiceInstantiationException:
    Could not instantiate implementation class com.sap.tc.eu.odi.conn.uwl.OdiBridgeService
    of Portal Service tc.eu.odi.conn.uwl|OdiBridgeService because: could not load the service
    com.sap.engine.services.deploy.container.ApplicationInManualStartUpException:
    Application sap.com/com.sap.portal.fpn.accessservice cannot be started
    because is in MANUAL start-up mode.
    There are many more entries in default.trace.

  • Java Application not rocognized 3110c

    I downloaded a dictionary from the internet with jar extension.
    upon trying to run it, message appeared saying " Application not recognized"
    could you please elaborate the different types of java platforms and which one is supported o my phone Nokia 3110c, and how to identify the supported one ...
    Thanks in Advance

    http://www.forum.nokia.com/devices/3110_classic
    MIDP 2.0
    CLDC 1.1
    JSR 135 Mobile Media API
    JSR 172 Web Services API
    JSR 177 Security and Trust Services API
    JSR 184 Mobile 3D Graphics API
    JSR 185 JTWI
    JSR 205 Wireless Messaging API
    JSR 226 Scalable 2D Vector Graphics API
    JSR 75 FileConnection and PIM API
    JSR 82 Bluetooth API
    Nokia UI API

  • Java application not working

    Running Win98. I somehow removed the Java application from my computer, and am unable to open any java appelets or javascript. Where can I download the JVM for Win98. Currently all I have is JVM 1.5.0_05 (which is for Win98SE), and doesn't work. I went back to the MSJVM which doesn't work either. Any help would be greatly appreciated.

    Don't know, but I uninstalled it. I'm trying to get 1.4.2_07 back.

  • JAVA SOUND APPLICATION not applet.....help needed.....cheers

    hey there people heres the deal I need to complete this before 5 today but im completely stumped...we have to make a sound file player with a swing interface I have it playing(kind of!) but where now...I would be forever in your debt as my masters degree hangs in the balance! de de duhhhh! cheers
    iT WORKS ALRIGHT JUST NEED STOP PAUSE BUTTON FUNCTION..........
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.event.*;
    import java.io.File;
    import java.io.IOException;
    import javax.sound.sampled.*;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.Clip;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineEvent;
    import javax.sound.sampled.LineListener;
    import javax.sound.sampled.LineUnavailableException;
    public class AudioPlayer extends JFrame implements ActionListener, ChangeListener{
    boolean playing;
    boolean looping;
    String filename = File.separator+"tmp";
    File selFile;
    Clip clip;
    JFileChooser fc = new JFileChooser();
    JButton btnOpen = new JButton("Open");
    JButton btnPlay = new JButton("Play");
    JButton btnStop = new JButton("Stop");
    JButton btnPause = new JButton("Pause");
    JButton btnLoop = new JButton("Loop");
    JSlider volume = new JSlider(SwingConstants.HORIZONTAL,0,100,0);
    JSlider panning = new JSlider(SwingConstants.HORIZONTAL,0,100,0);
    public AudioPlayer(){
    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(btnOpen);btnPlay.addActionListener(this);
    contentPane.add(btnPlay);btnPlay.addActionListener(this);
    contentPane.add(btnStop);btnStop.addActionListener(this);
    contentPane.add(btnPause);btnPause.addActionListener(this);
    contentPane.add(btnLoop);btnLoop.addActionListener(this);
    // Show open dialog; this method does not return until the dialog is closed
    fc.showOpenDialog(this);
    selFile = fc.getSelectedFile();
    volume.addChangeListener(this);
    panning.addChangeListener(this);
    volume.putClientProperty("JSlider.isFilled", Boolean.TRUE);
    volume.setPaintTicks(true);volume.setPaintLabels(true);
    volume.setMajorTickSpacing(20);volume.setMinorTickSpacing(10);
    contentPane.add(volume);
    panning.putClientProperty("JSlider.isFilled", Boolean.TRUE);
    panning.setPaintTicks(true);panning.setPaintLabels(true);
    panning.setMajorTickSpacing(20);panning.setMinorTickSpacing(10);
    contentPane.add(panning);
    addWindowListener(
    new WindowAdapter () {
    public void windowClosing(WindowEvent e){
    setVisible(false);
    public void actionPerformed(ActionEvent e){
    int returnVal = JFileChooser.APPROVE_OPTION;
    //Handle open file action.
    if (e.getSource() == btnOpen)
    System.out.println("FA1");
    returnVal = fc.showOpenDialog(AudioPlayer.this);
    if (returnVal == JFileChooser.APPROVE_OPTION)
    { selFile = fc.getSelectedFile();
    //This is where a real application would open the file.
    else
    if(e.getSource() == btnPlay)
    playAudio();
    public void stateChanged(ChangeEvent e)
    public static void main(String[] args)
    AudioPlayer audioPlayer = new AudioPlayer();
    audioPlayer.setSize(400,400);
    audioPlayer.show();
    public void playAudio ()
    playing = true;
    AudioInputStream audiosource = null;
    try
    audiosource = AudioSystem.getAudioInputStream(selFile);
    System.out.println("here");
    //System.out.println(audiosource.getFormat());
    DataLine.Info dataLineInfo = new DataLine.Info(Clip.class,audiosource.getFormat());
    clip = (Clip)AudioSystem.getLine(dataLineInfo);
    clip.open(audiosource);
    catch (UnsupportedAudioFileException e)
    catch (LineUnavailableException e)
    catch (IOException e)
    //catch (Exception e) {}
    if (looping)
    clip.loop(clip.LOOP_CONTINUOUSLY);
    else
    clip.loop(0);
    playing = false;
    }

    You have not added the actionListener to all the button D'oh
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.event.*;
    import javax.sound.sampled.*;
    * Description of the Class
    *@author rsmazara
    *@created 28 February 2003
    public class AudioPlayer extends JFrame implements ActionListener, ChangeListener {
    File selFile;
    JFileChooser fc = new JFileChooser();
    JButton btnOpen = new JButton( "Open" );
    JButton btnPlay = new JButton( "Play >" );
    JButton btnStop = new JButton( "Stop" );
    JButton btnPause = new JButton( "Pause ||" );
    JCheckBox btnLoop = new JCheckBox( "Loop" );
    JSlider volume = new JSlider( SwingConstants.HORIZONTAL, 0, 100, 0 );
    JSlider panning = new JSlider( SwingConstants.HORIZONTAL, 0, 100, 0 );
    JLabel label = new JLabel( " " );
    public AudioPlayer() {
    Container contentPane = getContentPane();
    contentPane.setLayout( new FlowLayout() );
    btnOpen.addActionListener( this );
    contentPane.add( btnOpen );
    btnPlay.addActionListener( this );
    contentPane.add( btnPlay );
    btnPlay.addActionListener( this );
    contentPane.add( btnStop );
    btnStop.addActionListener( this );
    contentPane.add( btnPause );
    btnPause.addActionListener( this );
    contentPane.add( btnLoop );
    btnLoop.addActionListener( this );
    btnPlay.setEnabled( false );
    btnStop.setEnabled( false );
    btnPause.setEnabled( false );
    // Show open dialog; this method does not return until the dialog is closed
    // fc.showOpenDialog( this );
    // selFile = fc.getSelectedFile();
    volume.addChangeListener( this );
    panning.addChangeListener( this );
    volume.putClientProperty( "JSlider.isFilled", Boolean.TRUE );
    volume.setPaintTicks( true );
    volume.setPaintLabels( true );
    volume.setMajorTickSpacing( 20 );
    volume.setMinorTickSpacing( 10 );
    contentPane.add( volume );
    panning.putClientProperty( "JSlider.isFilled", Boolean.TRUE );
    panning.setPaintTicks( true );
    panning.setPaintLabels( true );
    panning.setMajorTickSpacing( 20 );
    panning.setMinorTickSpacing( 10 );
    contentPane.add( panning );
    contentPane.add( label );
    addWindowListener(
    new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
    setVisible( false );
    System.exit( -100 );
    public void actionPerformed( ActionEvent e ) {
    int returnVal = JFileChooser.APPROVE_OPTION;
    //Handle open file action.
    System.out.println( e.getActionCommand() );
    ///open
    if ( e.getSource() == btnOpen ) {
    System.out.println( "FA1" );
    returnVal = fc.showOpenDialog( AudioPlayer.this );
    if ( returnVal == JFileChooser.APPROVE_OPTION ) {
    selFile = fc.getSelectedFile();
    player = new Player( selFile );
    label.setText( "File loaded : " + selFile.getAbsolutePath() );
    btnPlay.setEnabled( true );
    btnStop.setEnabled( false );
    btnPause.setEnabled( false );
    //This is where a real application would open the file.
    } else {
    //play
    if ( e.getSource() == btnPlay ) {
    player.go( btnLoop.isSelected() );
    btnPlay.setEnabled( false );
    btnStop.setEnabled( true );
    btnPause.setEnabled( true );
    // playAudio();
    // pause
    if ( e.getSource() == btnPause ) {
    player.pause();
    btnPlay.setEnabled( true );
    btnStop.setEnabled( true );
    btnPause.setEnabled( false );
    if ( e.getSource() == btnStop ) {
    player.finish();
    btnPlay.setEnabled( true );
    btnStop.setEnabled( false );
    btnPause.setEnabled( false );
    public void stateChanged( ChangeEvent e ) {
    private Player player = null;
    public static void main( String[] args ) {
    AudioPlayer audioPlayer = new AudioPlayer();
    audioPlayer.setSize( 400, 400 );
    audioPlayer.show();
    * Description of the Class
    *@author rsmazara
    *@created 28 February 2003
    class Player {
    Clip clip;
    private java.io.File selectedFile = null;
    private boolean looping = false;
    public Player( File file ) {
    selectedFile = file;
    AudioInputStream audiosource = null;
    try {
    audiosource = AudioSystem.getAudioInputStream( selectedFile );
    System.out.println( "here" );
    //System.out.println(audiosource.getFormat());
    DataLine.Info dataLineInfo = new DataLine.Info( Clip.class, audiosource.getFormat() );
    clip = ( Clip ) AudioSystem.getLine( dataLineInfo );
    clip.open( audiosource );
    } catch ( UnsupportedAudioFileException e1 ) {
    e1.printStackTrace();
    } catch ( LineUnavailableException e2 ) {
    e2.printStackTrace();
    } catch ( IOException e3 ) {
    e3.printStackTrace();
    private boolean work = false;
    public void go( boolean loop ) {
    looping = loop;
    playAudio();
    public void finish() {
    clip.stop();
    public boolean isWorking() {
    return clip.isRunning();
    long pausePosition = ( long ) 0;
    public void pause() {
    pausePosition = clip.getMicrosecondPosition();
    clip.stop();
    public void restart() {
    clip.setMicrosecondPosition( pausePosition );
    playAudio();
    public void loop( boolean loop ) {
    looping = loop;
    private void playAudio() {
    if ( looping ) {
    clip.loop( clip.LOOP_CONTINUOUSLY );
    } else {
    clip.loop( 0 );

  • Works in application, not applet, why

    connection = new Socket(
    InetAddress.getByName("mailbox.oneonta.edu"), 25);
    this line works in my application but i get a java.security.AccessControlException when i try to use the code in an applet. can anyone help?

    I think there is more then enough great documentation on this very site to help you out. Explaining things like how to sign an applet, or a jar, that are docuemented so your little sister can do it is a waste of time. I'm not being rude at all, I'm trying to get you to use the resources of this site. The java tutorials is a great place to start.

  • Opening a file from a java app (not applet)

    My program can't find the text file I'm trying to open in my stand-alone java app. I am specifying it like this:
    File filename = new File("myfile.txt");
    FileReader = new FileReader(filename);
    It is in the same directly as the class files. It won't find it when it's in a jar file either. I had a similar problem with an applet a lont time ago, but that turned out to be a security issue, which I assume normal apps don't have.
    So, what's up with this?

    If system become larger, there are duplicated files
    can be found in different directories.
    Using classpath may cause problem, if there are
    duplicated file name.
    If you are coding, you should know exact location of
    the file to be opened.
    "system become larger" - huh? You control the classpath on a per-app basis, not one huge monolithic classpath containing all jars/folders for all apps.
    It's common, well-designed practice to use the classpath. It's bad practice to hard-code directory names and expect all deployments of the app to follow the same directory naming convention. I wouldn't want you to dictate to me where to put the file on my hard drive. I should be able to install it anywhere I want, and let it find it (via the classpath, in this instance).

  • Java application not release memory

    I have java 1.3 or 1.4, my application start correctly.
    I have set heap a 4Mb but process java begin consume ram, initialy start with 7MB after 12-15 hour the process have above 60% system mem (128Mb).
    After 16-18 hour kernel kill process.
    I have Ubuntu distribution
    Thanks

    it is difficult to address this question without having a knowledge of the application. Here are some suggestions:
    (1) run the application from within Java Studio in debug mode. This will give you an idea of what is absorbing the memory. The idea here is to be able to watch your data structures grow. Any tool that allows you to do this will help. See http://developers.sun.com/prodtech/javatools/jsenterprise/index.html
    for Java Studio Enterprise.
    (2) the chances are very good that your application is creating some sort of Collection (Set, Hashtable, Vector, ...) and slowly adding to it. This is very common and a common cause of "memory leak".
    (3) The garbage collector in Java frees memory as objects go out of scope. If the objects never go out of scope, they are never garbage collected.
    (4) If you have these such objects or collections that must always be accessable, consider adding some caching mechanism (putting the data to disk) whereby keeping your datastructures smaller.
    (5)Also, when you say "set the heap" I am assuming you used the -Xmx and -Xms command line options. If not, look into these.

  • Java Applications and Applets

    Are local Java programs only command line runnable? How can I create exe like programs? I already know about how Java doesn't use compilation, but bytecode interpretation.
    Can applets run locally or only browserly.

    Are local Java programs only command line runnable?Several programs set up batch files to invoke it with java.
    How can I create exe like programs?You can make an executable jar, and the java interpreter is invoked normally.
    I already know about how Java doesn't use compilationIt does use compilation. Java code compiles to java bytecode. This is run on the java interpreter. It doesn't compile down to native machine code, but it IS compiled.
    Can applets run locally or only browserly. Applets can run locally in using applet runner.

  • Please help. Start a client application (not applet) from a web page.

    Hi,
    It may be very simple, but I can not find it quickly.
    Anyone can give me an example page that can start an application by click something.
    Thanks very much.

    Hi,
    This works on my PC (of course it's not portable to all clients)
    <HTML>
    <BODY>
    Click here to start notepad
    </BODY>
    </HTML>

Maybe you are looking for