V
Vasu
Hi !
I've coded the following, which represents two scrollbar horizontal
and vertical, and two strings s and s1 values each 50 represented as
one on top of the other where s represents the position of
selectionpoint of scrollbar horizontal and s1 represents position of
vertical one's.
Now the problem is that even if I change the situation of
selectionpoint of any scrollbar Vertical or Horizontal, only string s
changes but not the s1, whereas principly s should change for
Horizontal and s1 should change for Vertical, which is not happening.
Can anybody explain the required change in the code.
Will be grateful to him/her.
Thanks
Vasu
"
import java.awt.*;
import java.applet.*;
public class ScrllApplet extends Applet
{
Scrollbar scrollbar1;
Scrollbar scrollbar2;
String s, s1;
public void init()
{
BorderLayout layout = new BorderLayout();
setLayout(layout);
scrollbar1 = new Scrollbar(Scrollbar.HORIZONTAL,50, 0, 1,100);
scrollbar2 = new Scrollbar(Scrollbar.VERTICAL, 50, 0, 1,100);
add("North", scrollbar1);
add("East", scrollbar2);
s = "50";
s1= "50";
Font font = new Font("TimesRoman", Font.BOLD, 72);
setFont(font);
resize(200, 200);
}
public void paint(Graphics g)
{
g.drawString(s, 60, 120);
g.drawString(s1, 60, 190);
}
public boolean handleEvent(Event evt)
{
if (evt.target instanceof Scrollbar)
{
scrollbar1 = (Scrollbar)evt.target;
int value = scrollbar1.getValue();
s = String.valueOf(value);
repaint();
return true;
}
else if (evt.target instanceof Scrollbar)
{
scrollbar2 = (Scrollbar)evt.target;
int value1 = scrollbar2.getValue();
s1 = String.valueOf(value1);
repaint();
return true;
}
else
{
boolean result = super.handleEvent(evt);
return result;
}
}
}
"
I've coded the following, which represents two scrollbar horizontal
and vertical, and two strings s and s1 values each 50 represented as
one on top of the other where s represents the position of
selectionpoint of scrollbar horizontal and s1 represents position of
vertical one's.
Now the problem is that even if I change the situation of
selectionpoint of any scrollbar Vertical or Horizontal, only string s
changes but not the s1, whereas principly s should change for
Horizontal and s1 should change for Vertical, which is not happening.
Can anybody explain the required change in the code.
Will be grateful to him/her.
Thanks
Vasu
"
import java.awt.*;
import java.applet.*;
public class ScrllApplet extends Applet
{
Scrollbar scrollbar1;
Scrollbar scrollbar2;
String s, s1;
public void init()
{
BorderLayout layout = new BorderLayout();
setLayout(layout);
scrollbar1 = new Scrollbar(Scrollbar.HORIZONTAL,50, 0, 1,100);
scrollbar2 = new Scrollbar(Scrollbar.VERTICAL, 50, 0, 1,100);
add("North", scrollbar1);
add("East", scrollbar2);
s = "50";
s1= "50";
Font font = new Font("TimesRoman", Font.BOLD, 72);
setFont(font);
resize(200, 200);
}
public void paint(Graphics g)
{
g.drawString(s, 60, 120);
g.drawString(s1, 60, 190);
}
public boolean handleEvent(Event evt)
{
if (evt.target instanceof Scrollbar)
{
scrollbar1 = (Scrollbar)evt.target;
int value = scrollbar1.getValue();
s = String.valueOf(value);
repaint();
return true;
}
else if (evt.target instanceof Scrollbar)
{
scrollbar2 = (Scrollbar)evt.target;
int value1 = scrollbar2.getValue();
s1 = String.valueOf(value1);
repaint();
return true;
}
else
{
boolean result = super.handleEvent(evt);
return result;
}
}
}
"