Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Some text issues with drawString

 
Jacob H
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All solved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic