Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 怎么回事呀!快来帮忙呀!
kudo





发贴: 15
积分: 0
于 2004-10-16 20:34 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这个问题困扰我好几天了~拜托帮帮忙~
import java.awt.*;
import java.awt.event.*;
public class Change implements AdjustmentListener
{  
  static Frame fra=new Frame("改变颜色");
  static Scrollbar scrRed=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,255);
  static Scrollbar scrGreen=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255);
  static Scrollbar scrBlue=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255);
  static Button btn=new Button();
  public static void main(String[] args)
  {  //设定各Scrollbar的初始植,取的是按钮btn的底色
    try{
    scrRed.setValue(btn.getBackground().getRed());
    scrGreen.setValue(btn.getBackground().getGreen());
    scrBlue.setValue(btn.getBackground().getBlue());}
    catch(Exception e)
    {};
    //注册事件监听器
    fra.addWindowListener(new MyWindowEvent());
    scrRed.addAdjustmentListener(new Change());
    scrGreen.addAdjustmentListener(new Change());
    scrBlue.addAdjustmentListener(new Change());
    fra.setLocation(100,100);
    //设定各控件的位置和大小
    btn.setBounds(120,120,150,150);
    scrRed.setBounds(120,50,150,30);
    scrGreen.setBounds(65,120,30,150);
    scrBlue.setBounds(300,120,30,150);
    //将各控件添加到fra上
    fra.add(scrRed);
    fra.add(scrGreen);
    fra.add(scrBlue);
    fra.add(btn);
    fra.setLayout(null);
    fra.setSize(400,350);
    fra.setVisible(true);
  }
  public void adjustmentValueChanged(AdjustmentEvent e)
  {  //使btn的底色随Scrollbar的变化而变化
    btn.setBackground(new Color(scrRed.getValue(),scrGreen.getValue(),scrBlue.getValue()));
  }
}  
class MyWindowEvent extends WindowAdapter
{
  public void windowClosing(WindowEvent e)
  {
    System.exit(0);
  }
}
/*
如果把try catch去掉,编译能通过,但运行出现以下错误:
java.lang.NullPointerException
  at Change.main(Change.java:12)
Exception in thread "main" Normal Termination
好像是null的异常~这个问题怎么解决呀?拜托了!!!!!
*/




JAVA学习日子分享

话题树型展开
人气 标题 作者 字数 发贴时间
4945 怎么回事呀!快来帮忙呀! kudo 1749 2004-10-16 20:34
4017 Re:怎么回事呀!快来帮忙呀! kavinwang 66 2004-10-16 20:54
3900 Re:怎么回事呀!快来帮忙呀! kudo 30 2004-10-16 20:58
3944 Re:怎么回事呀!快来帮忙呀! kavinwang 19 2004-10-16 21:01
3821 Re:怎么回事呀!快来帮忙呀! nothing 13 2004-10-16 21:10
4097 Re:怎么回事呀!快来帮忙呀! kavinwang 28 2004-10-17 15:12

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923