LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2010, 11:21 PM   #1
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Rep: Reputation: 40
Java Applet and Displaying text


I’m having various problems with the graphic printing features for applets.

In this immediate applet, when I print and update the previous line bleeds through the next line. I tried printing a series of spaces to clear the first text, but it doesn’t work.

Can someone provide some tips on resolving this issue?

Code:
import java.awt.Graphics;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.net.InetAddress;

public class checkconnect extends JApplet{
    @Override
    public void paint(Graphics g)
    {
        String status1 = "Checking...";
        boolean status = false;
        g.drawString(status1,1,10);
        // g.drawString{"test",1,10};
        try {
           
            String host = "127.0.0.1";
            int timeOut = 1450;
            status = InetAddress.getByName(host).isReachable(timeOut);
        } catch (IOException ex) {
            Logger.getLogger(checkconnect.class.getName()).log(Level.SEVERE, null, ex);
        }
        if ( status ){
        status1 = "Success";
        }
        g.drawString("          ",1.10); //an attempt to cleanup the previous text.
        g.drawString(status1,1,10);       
    }
}
Thanks!

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
Old 03-14-2010, 10:35 AM   #2
khodeir
Member
 
Registered: Feb 2009
Distribution: Debian
Posts: 243

Rep: Reputation: 33
could you provide the output screen
 
Old 03-14-2010, 12:27 PM   #3
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by khodeir View Post
could you provide the output screen
The white space on the blue is the applet's output:

http://image.apollo3.com/image/gen/1...playOutput.jpg

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
Old 03-14-2010, 05:03 PM   #4
khodeir
Member
 
Registered: Feb 2009
Distribution: Debian
Posts: 243

Rep: Reputation: 33
is this line correct
Quote:
g.drawString(" ",1.10);
or do u mean
Quote:
g.drawString(" ",1,10);
 
Old 03-14-2010, 05:10 PM   #5
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by khodeir View Post
is this line correct

or do u mean
The one with the "," (the correct one) is the one that was compiled. It seems that I made a mistake when extracting the example for the message.

I have since tested the message sample. It's running with the "," in the picture I outputted to you. It won't compile without the proper syntax.

The image I linked is the one with the comma... the proper syntax.

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
Old 03-15-2010, 03:17 AM   #6
khodeir
Member
 
Registered: Feb 2009
Distribution: Debian
Posts: 243

Rep: Reputation: 33
I am very busy but I will tell u a little hint
spaces did not remove the words
why don't u search a character that looks like a white box??
search in the asci characters for that
 
0 members found this post helpful.
Old 03-15-2010, 10:38 AM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Quote:
Originally Posted by khodeir View Post
why don't u search a character that looks like a white box??
No, don't do that, use clearRect instead.

Another problem with the code is that paint() is the wrong place for the ip checking code: paint() is called by the system whenever the screen needs to be drawn, so just covering and uncovering the window would cause the ip to checked again.
 
Old 03-15-2010, 11:44 AM   #8
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by khodeir View Post
I am very busy but I will tell u a little hint
spaces did not remove the words
why don't u search a character that looks like a white box??
search in the asci characters for that
Thanks. This I could tell from the output. I believe I had been on a good track. With a lot of experimenting, I found that I could draw a box that would clear the previous text:

Code:
g.clearRect(1, 1, 100, 20);
It wasn't working before because it wasn't wide enough.

I'll look for a character that will do what you say and compare which would be more efficient.

I searched hard to find examples of reprinting but couldn't.

By the way, it's not very clean to have to have all my code embeded in the "public void paint(Graphics g)" block just to print. At present I'm very restricted become of of my could will error when trying to contain it in that box.

I'm still trying to figure out a clean way to work outside that "public void paint(Graphics g)" block, but have to do with this workaround for now.

I tried:

Code:
import java.awt.*;
import javax.swing.*;

public class quicktest extends java.applet.Applet {

    Graphics g;

    class doSomeWork {
        // work with mysql database and other tools

        doSomeWork() {
            // print results from work done.
            g.drawString("Out Put from work done", 100, 100);
        }
    }
}
In that example the "g.drawString", while it compiles, it doesn't output anything. I realize it's because the "Graphics g" is outside the "paint()" container. But I can't figure out how to provide the "paint()" container to all the other blocks that follows.

Quote:
Originally Posted by ntubski View Post
No, don't do that, use clearRect instead.

Another problem with the code is that paint() is the wrong place for the ip checking code: paint() is called by the system whenever the screen needs to be drawn, so just covering and uncovering the window would cause the ip to checked again.
Thanks for the input, Ntubski. I can't believe it, but I had already replied to the message this morning but clicked Preview instead of submit.

You're right. The clearRect does better.

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
Old 03-15-2010, 06:06 PM   #9
Larry James
Member
 
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Ubuntu, Raspbian
Posts: 381

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by ntubski View Post
No, don't do that, use clearRect instead.

Another problem with the code is that paint() is the wrong place for the ip checking code: paint() is called by the system whenever the screen needs to be drawn, so just covering and uncovering the window would cause the ip to checked again.
You are so right about the paint(). I'm going to try to figure out how to replace that and the g.drawString() with something else.

The problem is very apparent when you look at http://faq.apollo3.com/ljames/fsinn/...testservers.pl .

I'm trying to use some variation of the "HelloWorld" and the "theApplet" examples you gave in the thread about output. However, they are so dependent on the other classes that are included in the codes that they fail to work without including the other classes.

Dissecting the other classes and retaining functionality is one of my immediate projects.

-- L. James

--
L. D. James
ljames@apollo3.com
www.apollo3.com/~ljames
 
  


Reply



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

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java plugin installed correctly for Firefox but not able to view any java applet tvn Linux - Software 10 04-15-2010 02:13 AM
Need a Java Applet to utilize Java Script Functions circuit_girl Programming 3 04-11-2009 09:55 PM
JAVA JRE installation to view java applet through browser dipenchaudhary Linux - Software 1 01-23-2006 09:20 AM
Java applet error: "Applet Failed" nro Programming 1 08-28-2004 05:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration