[原创]APPLET滚动条的问题?
import java.applet.*;import java.awt.*;
public class colordemo extends Applet
{
mypanel myscroll;
int cred=0,cgreen=0,cblue=0;
Color custom;
public void init()
{
resize(320,200);
myscroll=new mypanel();
add(myscroll);
custom=new Color(cred,cgreen,cblue);
}
public boolean handleEvent(Event e)
{
if(e.target.equals(myscroll.scroll1))
{
cred=myscroll.scroll1.getValue();
custom=new Color(cred,cgreen,cblue);
repaint();
}
if(e.target.equals(myscroll.scroll2))
{
cgreen=myscroll.scroll2.getValue();
custom=new Color(cred,cgreen,cblue);
repaint();
}
if(e.target.equals(myscroll.scroll3))
{
cblue=myscroll.scroll3.getValue();
custom=new Color(cred,cgreen,cblue);
repaint();
}
myscroll.text1.setText("red:"+String.valueOf(cred)+";green:"+String.valueOf(cgreen)+";blue:"+String.valueOf(cblue));
return true;
}
public void paint(Graphics g)
{
g.setColor(custom);
g.fillRect(80,120,90,130);
}
class mypanel extends Panel
{
Scrollbar scroll1,scroll2,scroll3;
TextField text1;
mypanel()
{
setLayout(new GridLayout(4,1));
scroll1=new Scrollbar(Scrollbar.HORIZONTAL,1,10,1,255);
scroll2=new Scrollbar(Scrollbar.HORIZONTAL,1,10,1,255);
scroll3=new Scrollbar(Scrollbar.HORIZONTAL,1,10,1,255);
text1=new TextField(30);
add(scroll1);
add(scroll2);
add(scroll3);
add(text1);
scroll1.setBackground(Color.red);
scroll2.setBackground(Color.green);
scroll3.setBackground(Color.blue);
}
}
}
/*custom词JAVA里有吗?(还是自己定的)
*g.fillRect(80,120,90,130);这句的四个数字分别是起什么做用的?
改了之后就不随滚动条滑动而改变颜色了。
哪句话说明TextField放在滚动条下面。是不是他选择了GridLayout容器后自己排的?
*/
----------------解决方案--------------------------------------------------------
那四个数字
应该是填充矩形的颜色
的位置,可以使用 fillRect() 方法
指定颜色填充矩形像素组。
----------------解决方案--------------------------------------------------------