File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Some text issues with drawString Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Some text issues with drawString" Watch "Some text issues with drawString" New topic
Author

Some text issues with drawString

Jacob H
Greenhorn

Joined: Oct 03, 2003
Posts: 9
Ok I'm having some problems with drawString.
Here are parts of the code:
//g.setColor(new Color(0xffffff));
//g.fillRect(0, 35,400,230);
----------
if (Start == null)
doStart(g); <- does a drawString, works fine.
if (Sort == null)
g.drawString( "Sorted Employee Names", 20,60);

---------------
class MyMouseAdapter extends MouseAdapter{
public void mouseReleased(MouseEvent event) {
JButton b = (JButton)event.getSource();
if(b == Start)
Start = null;

else if (b == Sort)
Sort = null;

repaint();
}

Ok so my first problem is when Start is pressed and it goes to goStart to write the text using drawString, it loops endlessly.. so instead of having 4 lines of text it just loops and fills the whole screen. I can put some sort of counter in there but would like to know if its something technical that I missed.
My second problem is that when the Sort button is pressed it does not clear what Start put on screen. So the text in sort is placed on top of whats there before. i tried placing repaint() in a couple of spots but it did not help.
Lastly, the first two lines I commented out. If I uncomment them the screen flickers when I view the applet, so all the text mainly flickers..
I've been at this for a couple hours and will continue figuring it out after I hit submit. Any help is apprciated!
Jacob H
Greenhorn

Joined: Oct 03, 2003
Posts: 9
Ok I've seem to solve the flickering and the filling up of the screen with text.
The one problem I have is switching between buttons.
First time I run I can switch fine from Start to Sort but after that nothign works and it stays on Sort.
Here's the code:
if (Start == null && Sort != null)
doStart(g);
else if (Sort == null)
doSort(g);
-------------
class MyMouseAdapter extends MouseAdapter{
public void mouseReleased(MouseEvent event) {
JButton b = (JButton)event.getSource();
if(b == Start)
Start = null;
else if (b == Sort)
Sort = null;

else if (b == Clear)
Clear = null;

repaint();
}
[ November 24, 2003: Message edited by: Jacob H ]
Jacob H
Greenhorn

Joined: Oct 03, 2003
Posts: 9
All solved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Some text issues with drawString