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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-13-2010, 11:21 PM
|
#1
|
|
Member
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Fedora, Ubuntu
Posts: 305
Rep:
|
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
|
|
|
|
03-14-2010, 10:35 AM
|
#2
|
|
Member
Registered: Feb 2009
Distribution: Debian
Posts: 243
Rep:
|
could you provide the output screen
|
|
|
|
03-14-2010, 05:03 PM
|
#4
|
|
Member
Registered: Feb 2009
Distribution: Debian
Posts: 243
Rep:
|
is this line correct
or do u mean
|
|
|
|
03-14-2010, 05:10 PM
|
#5
|
|
Member
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Fedora, Ubuntu
Posts: 305
Original Poster
Rep:
|
Quote:
Originally Posted by khodeir
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
|
|
|
|
03-15-2010, 03:17 AM
|
#6
|
|
Member
Registered: Feb 2009
Distribution: Debian
Posts: 243
Rep:
|
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.
|
03-15-2010, 10:38 AM
|
#7
|
|
Senior Member
Registered: Nov 2005
Distribution: Debian
Posts: 2,056
|
Quote:
Originally Posted by khodeir
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.
|
|
|
|
03-15-2010, 11:44 AM
|
#8
|
|
Member
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Fedora, Ubuntu
Posts: 305
Original Poster
Rep:
|
Quote:
Originally Posted by khodeir
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
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
|
|
|
|
03-15-2010, 06:06 PM
|
#9
|
|
Member
Registered: Jun 2000
Location: Buffalo, New York
Distribution: Fedora, Ubuntu
Posts: 305
Original Poster
Rep:
|
Quote:
Originally Posted by ntubski
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:53 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|