27.04.2013 Views

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Graphics, AWT, Swing I part<br />

It isn't fully correctly if we are speaking about containers on which they can draw.<br />

Swing is still based on AWT, and even Swing components must have at least one<br />

heavyweight container. In other words, JFrame, JApplet are *not* lightweight.<br />

I need to put in a JtextField characters like cyrilic ...<br />

How can I do this?<br />

Answer: You use the unicode string \u???? corresponding to your character.<br />

A table of codes can be found at www.unicode.org/charts/<br />

by Charles Megnin<br />

Is there any way to accept password from a java application. As it is a password,<br />

IT SHOULD NOT BE SHOWN(ECHOED) WHILE IT IS ENTERED.<br />

Answer: If you are using swing, you can use JPasswordField, and set your<br />

echo character.<br />

by myparu<br />

How can I change the default icon on application window (java cup) to my own?<br />

Answer:<br />

window.setIconImage(Toolkit.getDefaultToolkit().getImage("image.gif"));<br />

Q: How can I read a Tab delimited text file into a JList?<br />

All I need is the first item in each record. I import each line with a<br />

BufferedReader.Readline() and then look at each char with record.substring(n,n+1).<br />

How can I check if the next char is a Tab?<br />

Answer: StringTokenizer st = new StringTokenizer(record, "\t");<br />

while (st.hasMoreTokens()) {<br />

String token = st.nextToken();<br />

// ... do something with the token<br />

}<br />

How do I generate mouse click event but without a real click?<br />

Could you tell me how I can generate an event (like a mouse click) from a <strong>Java</strong><br />

application? (I want generate a mouse click event but without a real click on the<br />

mouse).<br />

Answer: See "simulate keyboard pressing" below: You can use java.awt.Robot"<br />

since java1.3<br />

Q: Why would anyone use AWT and not Swing today?<br />

Answer: There are several handheld devices that do not have a lot of memory or<br />

CPU power available, AWT is more suitable for them (Smaller footprint).<br />

file:///F|/350_t/350_tips/graphics-I.htm (4 of 6) [2002-02-27 21:18:07]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!