Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Canvas as Text Area  RSS feed

 
Hasan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Written below is the program in which we r facing problem. Let me briefly explain u its funationality. When executed thru appletviewer this program creates a button on applet, when clicked on this("Click") button a frame opens which contains a Canvas and a button in the name of "Enter". When "Enter" is clicked it will paint a string "test" on Canvas. Now the problem
is that when we scroll Canvas that string goes off which we don't want, we want it to be there even after scrolling also.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* < applet code=sample.class width=300 height=200>
< /applet> */
public class sample extends Applet implements ActionListener
{
Button click,enter;
Frame f;
myColor myc;
ScrollPane sp;
public void init()
{
click=new Button("Click");
add(click);
click.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==click)
{
call();
}
if(ae.getSource()==enter)
{
myc.color("test");
}
}
public void call()
{
f=new Frame("Sample");
f.setLayout(new FlowLayout());
sp=new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
enter=new Button("Enter");
myc=new myColor();
sp.add(myc);
f.add(sp);
f.add(enter);
f.setSize(300,300);
f.setVisible(true);
enter.addActionListener(this);
}
}
class myColor extends Canvas
{
int y=10;

public myColor()
{
this.setSize(500,1000);
}
public void color(String s)
{
Graphics g=getGraphics();
g.setColor(Color.blue);
g.drawString(s,10,y);
y=y+10;
}
}

[This message has been edited by Jim Yingst (edited May 19, 2000).]
 
Tom P
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if you don't want it to scroll then why the scrollbars? That's what scrollbars do!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!