ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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);
}
}
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
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.