This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

scrollpane

 
CD Phillips
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is obviously a novice's question. I can't seem to figure out how to get my applet to scroll?? Can anyone help??

import java.applet.*;
import java.awt.*;

public class TheApplet2 extends Applet {
int x1, y1, z1,
hLineLen,
vLineLen1,
vLineLen2,
boxAdjH,
boxAdjV,
rectWid,
rectHth,
depth;
String menuTitle;

public void init() {
setBackground( Color.black );
hLineLen = 36;
vLineLen1 = 8;
vLineLen2 = 10;
rectWid = 60;
rectHth = 18;
boxAdjH = 40;
boxAdjV = 19;
x1 =30;
y1 =20;
z1 =50;
}

public void paint(Graphics g) {
g.setColor( Color.green );
g.drawRect( x1, y1, rectWid, rectHth );
g.drawString( menuTitle, x1 + 15, y1 + 15);

for(int i=1;i<=depth;i++) {
g.drawLine( x1 + rectWid/2, y1 + rectHth, x1 + rectWid/2, y1 + rectHth + vLineLen1);
g.drawLine( x1 + rectWid/2, y1 + rectHth + vLineLen1, x1 + rectWid/2 + hLineLen, y1 + rectHth + vLineLen1);
g.drawLine( x1 + rectWid/2 + hLineLen, y1 + rectHth + vLineLen1, x1 + rectWid/2 + hLineLen, y1 + rectHth + vLineLen1 + vLineLen2 );
g.drawRect( x1 + rectWid/2 + hLineLen - rectWid/2, y1 + rectHth + vLineLen1 + vLineLen2, rectWid, rectHth );
g.drawString( menuTitle, x1 + rectWid/2 + hLineLen - rectWid/2 + 15, y1 + rectHth + vLineLen1 + vLineLen2 + 15);
x1 += hLineLen;
y1 += rectHth + vLineLen1 + vLineLen2;
if((x1 > 120) | (x1 < 60)) hLineLen *= -1;
}//for
}//graphics

public void messageFromJS(String sMessage, String MT){
depth = Integer.parseInt(sMessage);
menuTitle = MT;
repaint();
}//messageFromJS

}//applet
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
CD Phillips
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Craig. I'm still tyring to get it to run though. The applet opens in the window but the for loop does not execute for whatever reason(probably minor). I'll keep working on it.

Many thanks so far.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!