| how to combine paintComponent with add(component)? |
|
 |
Index ‹ java-programmer
|
- Previous
- 2
- MIDP JVM for Palm and Pocket PCStephan Erlank wrote:
> I've heard of J9 that comes with Visual Age Micro Edition, but I don't have
> time to download 122mb over a 56k dial-up connection.
VAME is discontinued and has been replaced by WebSphere Studio Device
Developer.
http://www-3.ibm.com/software/wireless/wsdd/
But maybe that's what you meant.
--
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty
- 3
- java.io.Exception: Too many open files on sun OS 5.6I'm operating on sun OS 5.6
I ping a host every 10 seconds to get knowlegde wheather it is running
or not. After about one and a half hour I get this Exception:
java.io.IOException: Too many open files
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:54)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:546)
at java.lang.Runtime.exec(Runtime.java:413)
at java.lang.Runtime.exec(Runtime.java:356)
at java.lang.Runtime.exec(Runtime.java:320)
at de.optimare.VRX8100.MainControl.pingRecorder(MainControl.java:226)
... and so on.
I set rlim_fd_max = 1024 in /etc/system
I tried to set the ulimit -n 1024 in my script
but it had no effect.
Here is my code: The pingRecorder is called every 10 seconds from a
swing.Timer.
runtime is the Runtime.getRuntime().
// used on unix system
private void pingRecorder() {
logDate = new Date();
try {
ping = runtime.exec(pingPath);
ping.waitFor();
exitValue = ping.exitValue();
switch (exitValue) {
case 0:
// stop the ping timer
if (pingTimer != null) {
pingTimer.stop();
}
if (! processIsInitialized) {
System.out.println(logDate.toString() + " Recorder alive. Now
wait " + initialWaitTime/1000 + " seconds to initialize");
//wait for recorder is booting
Thread.sleep(initialWaitTime);
// now init the VRX8100 process!
initProcess();
}
break;
case 1:
System.out.println(logDate.toString() + " Recorder off.
Memory: " + runtime.totalMemory());
break;
default:
System.out.println(logDate.toString() + " Recorder off.
Memory: " + runtime.totalMemory());
break;
}
} catch (IOException io) {
io.printStackTrace();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
I would be very happy if anyone knows about anything due to this
problem.
Is it a specific sun problem? Is it possible to control the number of
open files by Java?
Many thanks for any help
Gert
- 5
- URL Class Loader & file deletionHello,
The following code always displays "File cannot be deleted".
Any idea on the way to allow a file to be deleted when it has been used
by a URL class loader to load code ?
public class ClassLoaderTester {
public static void main( String[] args ) {
try {
String s = "c:\\zob.jar";
URLClassLoader oCL = new URLClassLoader(
new URL[] {
new File(s).toURL()
} );
Class c = oCL.loadClass("com.mysql.jdbc.Driver");
Object o = c.newInstance();
o = null;
c = null;
oCL = null;
System.gc();
System.runFinalization();
File oFile = new File(s);
if ( !oFile.delete() ) {
System.err.println("File cannot be deleted");
}
}
catch ( Exception e ) {
e.printStackTrace();
}
}
}
Thank's in advance.
- 5
- Design question about data conversion class.I'm looking for a name for my class that reflects what it does. Its a
class with functions that converts data.
For example, my current class is called ArticleValueObjectCreator. It
has a method that converts resultsets to an article value object bean.
I now need to create a method which converts an article related
resultset to xml. In the future I may need one that converts a value
object "bean" to xml.
I'm thinking of refactoring the class now that I need to grow it.
What is the best way of acomplishing good design here?
Would renaming the class to something like ArticleDataCovertor, or
ArticleAdaptor tie in with good programming practice, or would it be
better to split these methods up into different classes ( thus making
each class dependent on a fine range particular technologies ) eg, one
which is xml and jdbc only, another that is xml only.
Are there any design patterns like this that emphasise clean
seperation between technologies. Or am I over-engineering?
Thanks
Ben
- 6
- Authentication in different tiersHi
How can I access authentication information in different tiers of a
project? We are working on a multi tier J2EE project, and we want to
authenticate user (we are not sure whether using JAAS or not). Is
there any simple way to have access to authentication information in
all tiers including Service Facade, Business Doman, and Data Access
tiers?
If it was just a web tier we could save authentication information in
user session, but it is not good to couple business tier, data access
tier and ... to web specification (including HttpSession).
A solution is passing authentication object using method parameters
but it is not a very good, solution, and all the inter-tier method
calls should contain authentication information.
Note: we are working on a multi-tier and potentialy distributed
project, so I think attaching authentication info to Thread is not a
good solution.
Amir Pashazadeh
- 7
- eclipse and CDT errorHi,
Somebody got CDT working in eclipse ? What do you have to download ?
I use mingw g++. When I install CDT I get a Java null pointer exception
error
any idea ?
Johan
- 9
- pattern matching help on logical ORI'm using Java 1.4.2_05 and need some help getting a logical OR to work
within my pattern matcher.
I'm trying to get both string A and B to be recognized by one pattern?
String strA = "04/14:03,blahblahblah\u007F";
String strB = "04/14:03,blahblahblah";
So I'm trying to match:
Two numerals followed by slash followed by 2 numerals followed by a
colon followed by 2 numerals followed by a comma followed by anything
followed by a one or 0 delete character OR the end of the line/string.
Here is the regex:
Pattern.compile("[0-9]{2}[\u002F][0-9]{2}[\u003A][0-9]{2}[\u002C].+[\u007F?]|[$]",
Pattern.DOTALL);
The logical OR doesn't work though. And I've tried the OR a few other
ways as well.
... [\u007F|$]
... [\u007F?|$]
... [\u007f]?|[$]
These don't work either.
I'd appreciate any suggestions.
Thanks,
Shawna
- 9
- decoding utf8I've got a J2ME application that is doing a writeUTF() of a byte array
that I need to decode and store in a flat file (it's a jpeg) from my
perl socket application. I can't seem to find a way to have Perl
decode it into it's byte representation.
As a test I put a byte array of just control-A's on the wire using
writeUTF. The length of the scalar I get in Perl is exactly twice (128)
as I sent (64). I've tried doing: $decoded =
Encode::decode_utf8($netbuf) and it doesn't convert the data at all.
Obviously, I must be missing how Perl handles a scalar that contains
UTF-8 data.
Can someone point me in a direction? Thanks.
- 9
- Clipped image when g.drawImage(img, -3, -4, this)Hello,
I've created a class (full source code at the bottom)
which extends java.awt.Component and is supposed to
represent a playing card. If the card is being dragged,
I'd like to draw a shadow underneath it. And the card
itself should be drawn a little bit displaced - to make
the impression that it has been lifted:
public void paint(Graphics g) {
if (this == dragged) {
g.drawImage(shadow, 0, 0, this);
g.drawImage(cardImg, -3, -4, this);
} else {
g.drawImage(cardImg, 0, 0, this);
}
}
My problem is however that the cardImg is being
clipped. Does anybody please have an idea how
to workaround this?
Thank you
Alex
PS: Here is the full source code:
// $Id: Card.java,v 1.2 2007/07/18 10:10:33 afarber Exp $
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
class Card extends Component implements MouseListener,
MouseMotionListener
{
public static final int WIDTH = 70;
public static final int HEIGHT = 100;
public static final int SPADE = 0;
public static final int CLUB = 1;
public static final int DIAMOND = 2;
public static final int HEART = 3;
public static final int NOTRUMP = 4;
private static Card dragged;
private static Image[][] faces;
private static Image back;
private static Image shadow;
public byte rank, suit;
public boolean opened;
public int whose;
public Card(int rank, int suit) {
setSize(WIDTH, HEIGHT);
addMouseListener(this);
addMouseMotionListener(this);
this.rank = (byte) rank;
this.suit = (byte) suit;
}
public Card(char ch) {
setSize(WIDTH, HEIGHT);
addMouseListener(this);
addMouseMotionListener(this);
rank = (byte) (ch >> 8);
suit = (byte) ch;
}
public boolean equals(Card card) {
return (rank == card.rank && suit == card.suit);
}
public char toChar() {
return (char) ((rank << 8) | suit);
}
public void paint(Graphics g) {
if (this == dragged) {
g.drawImage(shadow, 0, 0, this);
// XXX the image below is clipped :-(
g.drawImage(opened ? faces[rank][suit] : back,
-3, -4, this);
} else {
g.drawImage(opened ? faces[rank][suit] : back,
0, 0, this);
}
}
public static void prepImages(Image big) {
ImageProducer source = big.getSource();
// create 32 card images
faces = new Image[8][4];
for (int rank = 0; rank < 8; rank++)
for (int suit = SPADE; suit <= HEART; suit++) {
ImageFilter filter =
new CropImageFilter(rank * WIDTH,
suit * HEIGHT, WIDTH, HEIGHT);
ImageProducer producer = new
FilteredImageSource(source, filter);
faces[rank][suit] = Toolkit.getDefaultToolkit()
.createImage(producer);
}
// create the image of a card's back
ImageFilter filter =
new CropImageFilter(560, 0, WIDTH, HEIGHT);
ImageProducer producer =
new FilteredImageSource(source, filter);
back = Toolkit.getDefaultToolkit().createImage(producer);
// use a card shape to create shadow
int[] pixels = new int[WIDTH * HEIGHT];
PixelGrabber grabber = new PixelGrabber(big, 0, 0,
WIDTH, HEIGHT, pixels, 0, WIDTH);
try {
grabber.grabPixels();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
// turn non-transparent pixels to shadow
for (int i = 0; i < pixels.length; i++)
if (0 != (pixels[i] & 0xFF000000))
pixels[i] = 0x60000000;
shadow = Toolkit.getDefaultToolkit().createImage(
new MemoryImageSource(WIDTH, HEIGHT, pixels, 0, WIDTH));
}
public void mouseExited(MouseEvent event) {
System.out.println("mouseExited:" + event);
dragged = null;
getParent().repaint();
}
public void mouseReleased(MouseEvent event) {
System.out.println("mouseReleased" + event);
dragged = null;
getParent().repaint();
}
public void mousePressed(MouseEvent event) {
System.out.println("mousePressed" + event);
dragged = this;
getParent().repaint();
}
public void mouseEntered(MouseEvent event) {
System.out.println("mouseEntered" + event);
}
public void mouseClicked(MouseEvent event) {
System.out.println("mouseClicked" + event);
}
public void mouseMoved(MouseEvent event) {
System.out.println("mouseMoved" + event);
}
public void mouseDragged(MouseEvent event) {
System.out.println("mouseDragged" + event);
}
public static int randomRank() {
return (int) Math.floor(8.0 * Math.random());
}
public static int randomSuit() {
return (int) Math.floor(4.0 * Math.random());
}
public static void main(String args[]) {
Frame frame = new Frame("Card Test");
frame.setForeground(Color.white);
frame.setBackground(Color.gray);
frame.setLayout(null);
final String PATH = "media/cards.gif";
Image big = Toolkit.getDefaultToolkit().getImage(PATH);
MediaTracker tracker = new MediaTracker(frame);
tracker.addImage(big, 0);
try {
tracker.waitForAll();
} catch (Exception ex) {
ex.printStackTrace();
}
if (tracker.isErrorAny()) {
System.err.println("Image " + PATH + " not found");
return;
}
Card.prepImages(big);
Card card = new Card(randomRank(), randomSuit());
card.opened = true;
frame.add(card);
frame.validate();
card.setLocation(200, 100);
frame.setSize(400, 300);
frame.setVisible(true);
}
}
- 10
- Alioth CVS Read-Only (was: Re: svn repository)-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Maybe we should ask to lock the Alioth's CVS repository of pkg-java
project, so we'll be sure everybody use the svn!
I Cc'd debian-admin but I'm not sure this is the right place. I already
send a mail about the wiki there but never got a response. And I'm not
sure they manage Alioth... If someone can Cc to a better location...
Thanks
Charles Fry wrote:
>>+1, keep only the RELEASE_<VERSION> tags.
>>
>>The directory layout seems ok to me. If there is a problem, we can svn mv.
>>
>>Many thanks for your work Charles,
>
> In that case I'll plan to make the migration on Monday. I'lll send out
> email 15 minutes prior to starting the move, then upon starting and
> finally upon completing the migration.
>
> cheers,
> Charles
- --
.''`.
: :' :rnaud
`. `'
`-
Java Trap: http://www.gnu.org/philosophy/java-trap.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDwlOu4vzFZu62tMIRAtS0AJ9R973xSgRKSS0ZCv6CgCvaTv0MuwCdG29Z
jK7dIKhblWvu5zX3QrgQ7ZE=
=wRbl
-----END PGP SIGNATURE-----
--
To UNSUBSCRIBE, email to email***@***.com
with a subject of "unsubscribe". Trouble? Contact email***@***.com
- 12
- Socket latenciesHi all,
I am working on a Java project and I am interested in measuring TCP
performance over long delay links. Do you know if there is any way to
simulate delay using Sockets, keeping the TCP protocol behaviour
intact? I wrote a FilterInputStream that waits for some time and then
reads from the stream, but I am afraid it could be not very accurate.
Thank you.
Daniela B
- 12
- Function for removing Accents?On Wed, 17 May 2006 11:52:25 +0200, I waved a wand and this message
magically appeared from Domagoj Klepac:
> Because internationalization was always expensive, and the IT industry
> was based in the Western countries, and it had no incentive to adapt
> to the new, small markets. For example, I would guess that there is no
> Esperanto Windows version. Or Esperanto Office. Not enough people
> would buy it. And if even mighty Microsoft can't afford to do it,
> other software vendors certainly can't.
Microsoft can afford to. They just aren't interested.
--
http://www.munted.org.uk
Take a nap, it saves lives.
- 12
- Problems with Java Server Faces in JRun4 (and Tomcat)Hi!
I have downloaded Java Server Faces (jsf-1_0.zip) to have a look at
them. First I tried to install them in my JRun4 server, which supports
J2EE 1.3. When starting the server after that I get the following
Exception (and I can't run the JSF application):
"04/23 18:26:57 error Could not pre-load servlet: JSPServlet
[2]jrun.jsp.compiler.JRunTagLibraryInfo$InvalidTLDElementException:
The tag function on line 14 is not a valid TLD element
at
jrun.jsp.compiler.JRunTagLibraryInfo$TLDParser.startElement(JRunTagLibraryInfo.java:627)
at
jrunx.util.SAXReflectionHandler.startElement(SAXReflectionHandler.java:24)
at
org.xml.sax.helpers.XMLReaderAdapter.startElement(XMLReaderAdapter.java:333)"
Then I tried to install them in the Tomcat 4.0.6 server embedded in
Netbeans 3.5.1. I guess it also follows the J2EE 1.3 specification but
without the EJB:s. There when i start the server I get the message:
"Apache Tomcat/4.0.6
PARSE error at line 6 column 19
org.xml.sax.SAXParseException: Element type 'taglib' must be
declared."
I can however run the faces application in Tomcat. The only problem is
when I run the 'jsf-components' demonstration and try to 'view jsp' or
'view source' with ShowSource.jsp. Then I get a compile-error:
"org.apache.jasper.JasperException: This absolute uri
(http://java.sun.com/jstl/core) cannot be resolved in either web.xml
or the jar files deployed with this application"
I've also tried with java.sun.com/jsp/jstl/core, which it says in the
JSTL-documentation, but the same result. It seems that the
JSTL-taglibraries referenced are not found or the server doesn't
support external URI:s. I saw in the documentation that JSF is tested
with J2SE 1.3.1_04 and later (I have 1.4.2_01), but does it need J2EE
1.4 as well? I don't have J2EE 1.4 yet, so must I download another
server as well?
/Erik D
- 12
- 15
- CLOB.createTemporary throws ClassCastException...I am also having the same problem. Does anyone have a solution? I read
that the workaround is to somehow extract the underlying connection to
give to the createTemporary method. Problem is I'm not sure how to do
that!
bartleby <email***@***.com> wrote in message news:<email***@***.com>...
> I got the same probleme, have you fond out how to solve the problem ?
|
| Author |
Message |
maestroff

|
Posted: 2003-10-29 2:40:00 |
Top |
java-programmer, how to combine paintComponent with add(component)?
I have a Java application with several classes that extend JPanels and
that, till now, didn't have any internal Swing components. They did
display text that was antialiased and sometimes animated by overriding
paintComponent in each of these custom classes. And this worked fine.
But now on one of the panels I want to add in the northeast corner
another customized JPanel extending object. When I just call
basePanel.add(newPan) the newPan would show up when first displayed
but then dissapear the next time repaint() is called on the basePanel.
I imagine I have to do something in the basePanel's paintComponent
method to make sure the new panel is repainted every time. But I'm not
sure how that is handled. Anyone have some advice? Maybe a quick
example?
|
| |
|
| |
 |
maestroff

|
Posted: 2003-10-29 6:23:00 |
Top |
java-programmer >> how to combine paintComponent with add(component)?
A more acurate subject for this thread might have been "How do you
paint a JComponent on top of another JComponent?"
|
| |
|
| |
 |
Babu Kalakrishnan

|
Posted: 2003-10-29 16:35:00 |
Top |
java-programmer >> how to combine paintComponent with add(component)?
Mike wrote:
> I have a Java application with several classes that extend JPanels and
> that, till now, didn't have any internal Swing components. They did
> display text that was antialiased and sometimes animated by overriding
> paintComponent in each of these custom classes. And this worked fine.
>
> But now on one of the panels I want to add in the northeast corner
> another customized JPanel extending object. When I just call
> basePanel.add(newPan) the newPan would show up when first displayed
> but then dissapear the next time repaint() is called on the basePanel.
> I imagine I have to do something in the basePanel's paintComponent
> method to make sure the new panel is repainted every time. But I'm not
> sure how that is handled. Anyone have some advice? Maybe a quick
> example?
Without seeing your code, it would be very difficult to guess why the
panel disappears the second time around. Normally the paint() method
of any JComponent will first call paintComponent on the component itself
and then call its paintChildren() method which causes all the children
added to the panel to get repainted (On top of the parent panel). So by
default you don't need to do anything specific in the paintComponent
method of the parent to paint the children. (All bets are off if you're
overriding the paint() method though)
You must be doing something in your code between your first repaint and
the second that either causes the child panel to get removed from its
parent (are you by any chance adding the same child to another container
?) or cause its size/location to change in such a manner that it isn't
visible on the screen. What LayoutManager do you use for the basePanel ?
BK
|
| |
|
| |
 |
maestroff

|
Posted: 2003-10-30 0:05:00 |
Top |
java-programmer >> how to combine paintComponent with add(component)?
I figured out what I was doing wrong. In my overloaded paintComponent
method I started with super.paintComponent(g). What I was missing, and
what fixed it when I put it in was calling super.paintChildren(g) on
the next line. Thanks BK.
Babu Kalakrishnan <email***@***.com> wrote in message news:<bnnu44$13k22a$email***@***.com>...
>
> Without seeing your code, it would be very difficult to guess why the
> panel disappears the second time around. Normally the paint() method
> of any JComponent will first call paintComponent on the component itself
> and then call its paintChildren() method which causes all the children
> added to the panel to get repainted (On top of the parent panel). So by
> default you don't need to do anything specific in the paintComponent
> method of the parent to paint the children. (All bets are off if you're
> overriding the paint() method though)
>
> You must be doing something in your code between your first repaint and
> the second that either causes the child panel to get removed from its
> parent (are you by any chance adding the same child to another container
> ?) or cause its size/location to change in such a manner that it isn't
> visible on the screen. What LayoutManager do you use for the basePanel ?
>
> BK
|
| |
|
| |
 |
Babu Kalakrishnan

|
Posted: 2003-10-30 1:03:00 |
Top |
java-programmer >> how to combine paintComponent with add(component)?
Mike wrote:
> I figured out what I was doing wrong. In my overloaded paintComponent
> method I started with super.paintComponent(g). What I was missing, and
> what fixed it when I put it in was calling super.paintChildren(g) on
> the next line. Thanks BK.
>
That doesn't look quite right either. Are you by any chance overriding
the paint() method as well ? If so try to avoid that. It is the paint
method of a JComponent that calls paintcomponent followed by
paintChildren. So overriding just the paintComponent method shouldn't
have interfered with the paintChildren call.
BK
|
| |
|
| |
 |
maestroff

|
Posted: 2003-10-30 23:23:00 |
Top |
java-programmer >> how to combine paintComponent with add(component)?
No, I'm only overriding paintComponent. Atleast in the base Panel.
However I am getting some odd error messages since I made the latest
change. What makes them odd is that everything visualy seems to be
working. But I'm getting an error message anyway. Let me explain some
more...
The JPanel (lets call it panA) that I add onto the base JPanel (panB)
is initialized with a CardLayout. Into panA I then put two more JPanel
extending objects as cards. One called ImagePanel for displaying
images, and the other called VideoPanel which uses the JMF api to
display video clips. Don't worry about the video one though, as I only
get the error msgs when the ImagePanel is the active card.
Here is the basic ImagePanel code:
public class ImagePanel extends JPanel
{
private ImageIcon image = null;
/**
* Construct without initializing media player
*/
public ImagePanel(String picture)
{
this();
setImage(picture);
}
public ImagePanel()
{
setOpaque(false);
}
// I also tried this as paint(g) but it didn't make any difference
public void paintComponent(Graphics g)
{
if (! g.drawImage(image.getImage(), 0, 0,
image.getImageObserver()))
System.out.println("Warning: ImagePanel image draw failed");
}
private void setImage(String picture)
{
image = new ImageIcon(picture);
setPreferredSize(new Dimension(image.getIconWidth(),
image.getIconHeight()));
// Use layout manager to set minimum height and width
setLayout(new FlowLayout(FlowLayout.CENTER,
image.getIconWidth() / 2,
image.getIconHeight() / 2));
}
public void changeImage(String picture)
{
setImage(picture);
repaint();
}
}
The problem is that I keep seeing that "Warning: ImagePanel image draw
failed" message even though the pictures are displayed when they
should be, don't dissapear, and change when they should. I do use
another instance of this class in another place in my application and
there it works fine too, but without the complaints. What could cause
the draw to think it failed, and yet still have the image be present
on the screen?? Its very confusing.
And in case it helps you understand my earlier issue, here is a
simplified version of the relevant parts of "panB":
public class BasePanel extends JPanel
{
public BasePanel(Config cfg)
{
...
setOpaque(false);
setLayout(null);
mediaPanel = new JPanel(mediaCards = new CardLayout());
mediaPanel.setOpaque(false);
// Will be made visible later by a call from a separate thread
mediaPanel.setVisible(false);
videoPanel = new VideoPanel();
picturePanel = new ImagePanel();
mediaPanel.add(picturePanel, IMAGE_MEDIA_CARD);
mediaPanel.add(videoPanel, VIDEO_MEDIA_CARD);
add(mediaPanel);
mediaPanel.setBounds(cfg.getWindowResolution().width - 340, 0,
340, 260);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
super.paintChildren(g);
if (booleanVariable)
{
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(answerColor);
g2.setFont(textFont);
....
// call g2.drawString(....); many times
....
g2.dispose();
}
}
}
>
> That doesn't look quite right either. Are you by any chance overriding
> the paint() method as well ? If so try to avoid that. It is the paint
> method of a JComponent that calls paintcomponent followed by
> paintChildren. So overriding just the paintComponent method shouldn't
> have interfered with the paintChildren call.
>
> BK
|
| |
|
| |
 |
maestroff

|
Posted: 2003-10-31 3:48:00 |
Top |
java-programmer >> how to combine paintComponent with add(component)?
Figured it out myself. You were right. I didn't need paintChildren().
The cause both of the initial disapearences and of those error
messages was my calling g2.dispose() at the end of the paintComponent
method. That apparently prevented the child component from painting.
The picture would still appear if I used super.paintChildren(g)
because it would try it twice on each repaint, and it would only fail
(and give the error message) the second time. I used g2.dispose()
because it seemed to be the standard thing to do at the end of a paint
overload. Sort of like always closing a DB connection after a JDBC
process. Using it is supposedly more efficient. Is there a better
place to call dispose, or should I just drop it completely?
|
| |
|
| |
 |
Babu Kalakrishnan

|
Posted: 2003-11-1 0:55:00 |
Top |
java-programmer >> how to combine paintComponent with add(component)?
Mike wrote:
> Figured it out myself. You were right. I didn't need paintChildren().
> The cause both of the initial disapearences and of those error
> messages was my calling g2.dispose() at the end of the paintComponent
> method. That apparently prevented the child component from painting.
> The picture would still appear if I used super.paintChildren(g)
> because it would try it twice on each repaint, and it would only fail
> (and give the error message) the second time. I used g2.dispose()
> because it seemed to be the standard thing to do at the end of a paint
> overload. Sort of like always closing a DB connection after a JDBC
> process. Using it is supposedly more efficient. Is there a better
> place to call dispose, or should I just drop it completely?
Drop it altogether. You should only dispose off recources that you
allocated yourself. So if you created a Graphics object from say a
BufferedImage, it is your responsibility yo dispose it off.
The Graphics object passed to you as an argument to the paint method is
something which the AWT (or Swing) painting subsystem created, and it
will perform the disposal when it is done with it.
BK
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Tabs on the right side in JTabbedPane ?I wanted to add 4 tabs to a JTabbedPane. Two of them should be on the left
side and two on the right side (all on the top). In other words, I want a
pretty big gap between these two sets of tabs.
______ _____ ______ _____
/__1___\/__2__\________________/___3__\/__4__\
|
|
|
|
Something like the above.
Is there a way to do it ?
Thanks.
RC
- 2
- How to release a free source code?Hi All,
I want to release some free source code, but not all code is done by
me. (ex: I use some code from others into my project... )
I think it is too complicate to check every function/routine belongs to
whom, what should I do to avoid the copyright problem?
Thank you very much.
Best regards,
Boki.
- 3
- JFrame to FrontHi,
First of all sorry for my german posting before!
Here is my question in english:
By starting my application I construct a JFrame. By clicking onto a
JButton on this JFrame, it construct a NON-MODAL JDialog, which gets as
parentComponent the JFrame.
Now, if I switch between the Frame and the Dialog, they are correctly
activated, but the Frame does never come to foreground, i.e. it is ever
ovelapped by the Dialog.
I tryed with "Frame.setVisible(true)", "Frame.toFront()" and
"Frame.show()", but unfortunately, it does not work.
Is my desired behavior in this case even possible, or is there only the
way of setting the parentComponent of the Dialog to null?
Thanks!
--
Oliver Hirschi
http://www.FamilyHirschi.ch
- 4
- How do you like Richfaces?How do you like Richfaces?
http://labs.jboss.com/jbossrichfaces/
Do you think it is the best way to integrate AJAX capabilities into
JSF?
- 5
- Why does we need Inner Class?Hello:
Am I correct? And everyone's words is welcome. Thanks.
class A {
int i;
int geti() {
return i;
}
}
class B {
int j;
int getj() {
return j;
}
}
/* It's wrong to write as follows: */
/*
public class C extends A,B {
}
*/
/* But it's right as follow: */
public class C extends A{
class D extends B {
}
}
- 6
- Trouble with reading and appending to lines in a file...Hi there,
Please bare with me on this, I'm a newbie :o). Ok, I'm trying to read a
file (a bunch of 1 word lines), find the last line with the word "SKIP" at
the end, and get the next line. After getting the desired line, I want to
append the word "SKIP" to that line as well and save and close the file.
I also want the class to have an input parameter (integer), which will be
the same name of the file (example: input = 1234 --> filname = 1234.txt).
Here is what I've got so far:
import java.io.*;
public class GetLine {
int number; //let's say the lines in the file are all 5 digit
numbers, with no spaces
public boolean evaluate(String str) {
//
//I'm not sure how to evaluate if the end of the line
has the word SKIP and the following doesn't work????
//
if ( StringBuffer.indexOf("SKIP\n") )
return true;
}
public void get(int c) throws IOException, FileNotFoundException {
String line;
boolean b;
FileReader fr=new FileReader(number + ".txt");
BufferedReader br=new BufferedReader(fr);
while((line=br.readLine())!=null )
{
b = evaluate(line);
if (b==false)
{
//
//not sure if I can just do a "return
line" to get the first line found without SKIP???
return line;
//
//not sure if I can do the following
either???
//
line = line + "SKIP";
}
}
}
}
Please, any suggestions are apprciated. Thanks for your help.
scopp
- 7
- gray boxes instead of the appletHi all,
I'm a newbie, so if I should be posting this to a different group, please
(gently) tell me which one.
I have copied a very small Java applet source off the web and successfully
compiled it. I have taken the resulting Java classes and put them on my
website, using the <applet> html tag. The applet works great for me.
However, most of the people I work with just get a gray box where the applet
should be. (Others can see and use the applet just fine.) The gray box
*does not* have a red X in it. I can detect no pattern whatsoever in the
clients for whom the applet does/doesn't work.
The most mysterious part to me is that even people who do not see the applet
correctly on my website seem to be able to see and use the same applet just
fine on the site I acquired it from. As far as I know, it's identically the
same applet. (I just stole the source and compiled it.) This would tend to
rule out a problem on the client side, but I can't be sure.
I think I've been able to deduce that the problem is not with the location
of the Java classes on my web page; otherwise, there would be a red X in the
upper-left corner of the gray box, right? (And in that case it probably
wouldn't work for anyone, including me.)
Anyone have a clue what's going on? What other information can I provide?
TIA,
Gnome
- 8
- [UPD] SQLeonardo MMV.III released[http://querybuilder.sourceforge.net]
SQLeonardo is a database query tool written in Java, distributed under
the GNU GENERAL PUBLIC LICENSE.
Include FreeQueryBuilder to create SQL queries without directly writing
SQL. All queries can be saved in a workspace for later use. Works
with any JDBC compliant database(ORACLE,MySQL,HSQLDB,Firebird,DB2)
*** NEW ***
Edit tables directly via the data grid
Regards Nickyb
- 9
- ligatures in Java 2DI've been trying to work out how to get Java to handle ligatures such
as "fi" correctly, but without much success. Various online documents
have suggested that I need to be intervening in the rendering process
and laying out my own GlyphVectors based on information associated
with Fonts, but I can't find out the details I need to actually do
that systematically.
I have discovered (<http://mindprod.com/jgloss/ligature.html>) that
'fi' has its own code point (\ufb01) in Unicode - should I be manually
checking whether my Font has specific glyphs for such ligatured
characters and manually substituting them into my char[] to feed to
layoutGlyphVector? Do Fonts come with lists of ligatures they
support, and if so how do I get at them?
And most of all, what is TFM that I am currently foolishly neglecting
to R?
Des
- 10
- Target Frame?After installing the latest Java version an applet on my homepage doesn't
work as it did before!
Instead of showing a new window in the selected target frame, a new popup
window is openend!
Who can help?
- 11
- clearing outputHello,
I've looked far and wide for the answer to this question without any
success. Is there a method in Java that clears output to
System.out.println? My goal is to pass output to the line then erase it
so that I don't have repeating lines in my loop. Any help is much
appreciated.
Thanks,
Ben
- 12
- calling java from DOTNET 2? how stable or painfull?hi.. (sorry but i posted this in a dotnet newsgroup as well becoue i
don't know which would be better handling this question).
i have a java application server whish uses RMI as a delivery transport
for it's apis (it's gets the command in XML but the underlying protocol
needs to be RMI)..
so i need to write an RMI CLIENT to this thing, and expose it microsoft
land.
at first we thought to have it exposed as web service and consume this
service via dotnet dll. the dll would be given to desktop application
developers which canno parse XML.
then i was told i could expose it as JNI and have the dll access it
directly. then the dll in dot net 2.0 would either be given to desktop
developers or exposed as a web service in biztalk if web services are
needed.
btw can i do all of this with express edition versions?
- 13
- strings in javaAs a response to a request to "make a complete and concise statement" and
"to provide some context", I reply here to my own post.
"Boudewijn Dijkstra" <email***@***.com> schreef in bericht
news:40b5afde$0$41748$email***@***.com...
> "Tony Morris" <email***@***.com> schreef in bericht
> news:c91dr1$i3c$email***@***.com...
> > "Ace" <email***@***.com> wrote in message
> > news:s0Usc.167024$email***@***.com...
> > > Now what if you had: String str ="abc"+" "+"def"+"efg";
> >
> > The compiler creates a single String instance with the value "abcdefefg"
>
> It becomes "abc defefg", actually.
> It is
remove "It is"
insert "The exact same string can be"
> created with the following Java statement:
> new StringBuffer().append("abc").append(" ")
> .append("def").append("efg").toString()
Maybe I am just too flexible in my use of language.
- 14
- Wholesale all laptops,Apple Ipods Nano, Xbox 360, Sony PS3, Sony PSP.wii ,SONY SD.SONY USB.GPS http://www.new-nikeshoes.cnhi
We are the biggest wholesale suppliers..........We have a lot of very
nice quality merchandises with the very special price
Our main markets are the USA, the UK, Germany, France, Italy, Greece,
Jordan, Australia, Canada,Sweden, and many other countries in Europe
and the Middle East regions.
Ipod nano 1G 45$ ,2G 55$, 4G 65$,8G 70$, 30G 100$ ,60G 120$
ps3 60GB 400$ 40GB 350$ 80GB 450$
psp 150$
wii 220$
X360 300$
SONY Scandisk or Kingston MicroSD
16GB 50$ 8GB 30$ 4GB 18$ 2GB 13$ 1GB 10$
SONY Kingston USB & Flash
16GB 50$ 8GB 30$ 4GB 18$ 2GB 13$ 1GB 10$
We wholesale all laptops
Sony VGN-CR13/B 380$
Sony VGN-CR13/L 350$
Sony VGN-CR15/B 320$
Sony VGN-CR13/P 480$
Sony VGN-C21CH 450$
Sony VGN-SZ44CN 580$
Sony VGN-C22CH/W 620$
Sony VGN-N17C 480$
Sony VGN-CR13/W 580$
Sony VGN-FZ15 560$
Apple MacBook 580$
Apple MacBook Pro(MA896CH/A)680$
Apple MacBook Pro(MA896CH/A) 630$
Apple MacBook (MB063CH/A) 580$
Apple MacBook Pro(MA895CH/A) 580$
Apple MacBook(MB062CH/A) 590$
Apple MacBook(MA700CH/A) 580$
Apple MacBook(MA701CH/A) 550$
Apple MacBook Pro (MA610CH/A) 650$
Apple MacBook Pro (MA611CH/A) 680$
Apple MacBook (MA699CH/A) 580$
(1).all products are all original and new
(2).they have 1year international warranty.
(3).free shipping include ems, tnt, dhl, ups. you may choose one kind
(4).deliver time is in 5 days to get your door
We insist the principia: Prestige first,high-quality,competitive
price,
best services,and timely delivery.
Website: http://www.new-nikeshoes.cn
msn: email***@***.com
Hong-da Co., Ltd.
- 15
- Batch image compression problem. Help!I am using Java to develop a web application that lets user to upload images
to the web server, and the server will automatically resize and compress the
images. It lets users to upload maximum 5 images at one time. The system
works fine. But sometimes a very strange problem occurs. When the users
upload the image, the images are able to be uploaded to the system
successfully, but the system is hanged on the image compression stage. The
system message returns that the uploaded images are under compression, but
never ended, even one hour.
I have checked the system log and find there is nothing mentioned in the log
file. This problem doesn't happen regularly, but it does happen sometimes.
Please kindly advise me what mistake I have made.
Thanks,
Chris
Herebelow is the part of source code:
==============================================================
/**
* create small image.
* @param oldImage,give a image to create small image.
* @param newImage,the image you want to create.
* @param maxWidth,the max width.
* @param maxHeight, the max height.
* @return the image's name.
* @throws java.lang.Exception
*/
public String createThumbnail(String srcImg,String objImg, int
maxWidth,int maxHeight) throws Exception{
try {
EuwLog.EuwPrint("Begin Thumbnail"+objImg);
ImageIcon ii = new ImageIcon(srcImg);
Image i = ii.getImage();
ii = null;
Image temp = null;
BufferedImage bufferedImage=null;
int iWidth = i.getWidth(null);
int iHeight = i.getHeight(null);
double ratio = getRatio(iWidth,iHeight,maxWidth,maxHeight);
iWidth = (int)(ratio*iWidth);
iHeight = (int)(ratio*iHeight);
if (ratio<1.0f){
temp =
i.getScaledInstance(iWidth,iHeight,Image.SCALE_AREA_AVERAGING);
i.flush();
i = null;
temp = new ImageIcon(temp).getImage();
// Create the buffered image.
bufferedImage = new BufferedImage(iWidth, iHeight,
BufferedImage.TYPE_INT_RGB);
// Copy image to buffered image.
Graphics g = bufferedImage.createGraphics();
// Clear background and paint the image.
g.setColor(Color.white);
g.fillRect(0, 0, iWidth,iHeight);
g.drawImage(temp, 0, 0, null);
g.dispose();
g = null;
// sharpen
float[] sharpenArray = { -0.125f, -0.125f, -0.125f, -0.125f,2,
-0.125f, -0.125f, -0.125f, -0.125f };
Kernel kernel = new Kernel(3, 3, sharpenArray);
ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
null);
bufferedImage = cOp.filter(bufferedImage, null);
cOp = null;
kernel = null;
/* write the jpeg to a file */
//File file = new File(objImg);
FileOutputStream out = new FileOutputStream(objImg);
/* encodes image as a JPEG data stream */
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param =
encoder.getDefaultJPEGEncodeParam(bufferedImage);
// writeParam = new JPEGImageWriteParam(null);
//
writeParam.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
//writeParam.setProgressiveMode(JPEGImageWriteParam.MODE_DEFAULT);
param.setQuality(0.9f, true);
encoder.setJPEGEncodeParam(param);
encoder.encode(bufferedImage);
param = null;
encoder = null;
temp.flush();
temp = null;
bufferedImage.flush();
bufferedImage = null;
out.close();
out = null;
EuwLog.EuwPrint("End Thumbnail"+objImg);
|
|
|