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

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 为什么List功能无法实现
dyhb





发贴: 4
积分: 0
于 2005-05-29 08:00 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
要求选择List框中的字体选项,改变Button按钮的字体,程序如下:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class test extends Applet implements ItemListener
{
Checkbox bg,cb1,cb2,cb3;
CheckboxGroup style;
Choice size;
List lt;
Button btn;
public void init()
{
style= new CheckboxGroup();
cb1 = new Checkbox("ÆÕͨ",true,style);
cb2 = new Checkbox("ºÚÌå",true,style);
cb3 = new Checkbox("бÌå",true,style);
bg= new Checkbox("±³¾°É«");
lt= new List(3,false);
lt.add("TimesRoman");
lt.add("SansSerif");
lt.add("Courier");
size=new Choice();
size.addItem("10");
size.addItem("12");
size.addItem("14");
btn=new Button("Ч¹û");
add(lt);
add(cb1);
add(cb2);
add(cb3);
add(size);
add(bg);
add(btn);
size.addItemListener(this);
lt.addItemListener(this);
bg.addItemListener(this);
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
Checkbox cbtemp;
Choice ctemp;
List ltemp;
Font oldF=btn.getFont();
String s;
int si;
if(e.getItemSelectable()instanceof Checkbox)
{
cbtemp=(Checkbox)(e.getItemSelectable());
if(cbtemp.getLabel()=="±³¾°É«")
   if(cbtemp.getState())
   btn.setBackground(Color.gray);
else
  btn.setBackground(Color.cyan);
if(cbtemp.getLabel()=="ÆÕͨ")
  btn.setFont(new Font(oldF.getName(),Font.PLAIN,oldF.getSize()));
if(cbtemp.getLabel()=="ºÚÌå")
  btn.setFont(new Font(oldF.getName(),Font.BOLD,oldF.getSize()));
if(cbtemp.getLabel()=="бÌå")
  btn.setFont(new Font(oldF.getName(),Font.ITALIC,oldF.getSize()));
}
if(e.getItemSelectable()instanceof Choice)
{
  ctemp=(Choice)(e.getItemSelectable());
  s=ctemp.getSelectedItem();
  si=Integer.parseInt(s);
  btn.setFont(new Font(oldF.getName(),oldF.getStyle(),si));
}
if(e.getItemSelectable()instanceof List)
{
  ltemp=(List)(e.getItemSelectable());
  btn.setFont(new Font(ltemp.getSelectedItem(),oldF.getStyle(),oldF.getSize()));
}
}
}


其htm文件如下:
<html>
<head><title>Test</title></head>
<body>
<hr>
<applet code=test.class Width=600 height=400>
</applet>
</body>
</html>

请各位高手指点一下!


why edited on 2005-06-06 17:09


话题树型展开
人气 标题 作者 字数 发贴时间
6722 为什么List功能无法实现 dyhb 2904 2005-05-29 08:00
5361 Re:为什么List功能无法实现 zhaoshuxian 151 2005-05-29 09:50
5406 Re:为什么List功能无法实现 dyhb 10 2005-05-29 17:00
5890 Re:为什么List功能无法实现 undefined 73 2005-06-02 22:15
5786 Re:为什么List功能无法实现 dyhb 89 2005-06-06 16:01

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