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

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 这里有一处错误请大家帮我看一下 ! !!
lbssy





发贴: 3
积分: 0
于 2008-05-09 19:48 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
package guyuanxinxi;

import java.applet.Applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;

public class UseBasicComponent_1 extends Applet implements TextListener,ActionListener,ItemListener
{
Employee newEmp;
Label prompt=new Label("输入新雇员的信息");
TextField no=new TextField("姓名");
Checkbox isMgr=new Checkboxs("主管");
CheckboxGroup sex=new CheckboxGroup();
Checkbox maleSex=new Checkbox("男",true,sex);
Checkbox femaleSex=new Checkbox("女",false,sex);
TextField sal=new TextField("工资");
SliderFrame sf;
List year=new List(3,false);
Choice month=new Choice();
Choice date1=new Choice();
Choice date2=new Choice();
TextArea reset=new TextArea("无信息",5,30);
Button result=new Button("清空");
Button enter=new Button("输入");
public void init(){
add(prompt);
no.setEditable(false);
add(no);
name.addTextListener(this);
add(name);
isMgr.addItemListener(this);
add(isMgr);
maleSex.addItemListener(this) ;
add(maleSex);
femaleSex.addItemListener(this);
add(femaleSex);
sal.addActionListener(this);
add(sal);
year.add("1996年");
year.add("1997年");year.add("1998年");year.add("1999年");year.addActionListener(this) ;
year.addItemListener(this);
add(year);
month.add("一月");
month.add("二月");
month.add("三月");
month.add("四月");
month.add("五月");
month.add("六月");
month.add("七月");
month.add("八月");
month.add("九月");
month.add("十月");
month.add("十一月");
month.add("十二月");
month.addItemListener(this);
add(month);
date1.add("0");
date1.add("1");
date1.add("2");
date1.add("3");
date2.add("0");
date2.add("1");
date2.add("2");
date2.add("3");
date2.add("4");
date2.add("5");
date2.add("6");
date2.add("7");
date2.add("8");
date1.add("9");
date1.addItemListener(this);
date2.addItemListener(this);
add(date1);
add(date2);
add(result);
reset.addActionListener(this);
add(reset);
enter.addActionListener(this);
add(enter);
}
public void textValueChanged(TextEvent e){
if(e.getSource()==name)
result.setText("响应文本改变事件,名字为:"+((TextField)e.getSource()).getText() );
}
public void actionPerformed(ActionEvent e){

if(e.getSource() ==sal){
double initSal;
String s=((TextField)e.getSource()).getText();
if(s.compareTo("")==0||s.compareTo("工资")==0||s==null)
initSal=0;
else
initSal=Double.valueOf(((TextField)e.getSource()).getText()).doubleValue() ;
sf=new SliderFrame(initSal,Employee.getMinSal(),sal);
}
else if(e.getActionCommand() =="清空"){
no.setText("");
name.setText("");
isMgr.setState(false);
maleSex.setState(true);
sal.setText("");
year.deselect(year.getSelectedIndex());
month.select(0);
date1.select(0);
date2.select(0);
result.setText("没有信息");
}
else if(e.getActionCommand() =="输入"){
String n=name.getText();
double s=Double.valueOf(sal.getText() ).doubleValue() ;
char ch;
boolean mgr=isMgr.getState();
int y,m,d;
if(maleSex.getState() )
ch='m';
else
ch='f';
y=(year.getSelectedIndex()) +96;
m=month.getSelectedIndex();
d=date1.getSelectedIndex() *10+date2.getSelectedIndex() ;
newEmp=new Employee(n,s,ch,mgr,new Date(y,m,d));
no.setText(Integer.toString(newEmp.getEmpNo()) );
result.setText(newEmp.toString());
}
else
{
result.setText(e.getActionCommand());
}
}
public void itemStateChanged(ItemEvent e)
{
ItemSelectable is=e.getItemSelectable();
if(is=isMgr){
result.setText("改变了复选框状态:");
if(e.getStateChange() ==ItemEvent.SELECTED)
result.appendText("选中");

else if(e.getStateChanged()==ItemEvent.DESELECTED)
result.appendText("未选中");
}
else if(is==maleSex)
result.setText("选中"+maleSex.getLabel());
else if(is==femaleSex)
result.setText("选中"+femaleSex.getLabel());
else if(is==year)
result.setText("选中第"+((List)is).getSelectedIndex()+"个月份");
else if(is==month)
result.setText("选中第"+((Choice)is).getSelectedIndex()+"个月份");
else if(is==date1)
result.setText("选中第"+((Choice)is).getSelectedIndex()+"个数天数十位");
else if(is==date2)
result.setText("选中第"+((Choice)is).getSelectedIndex()+"个数天数十位");
}
}class SliderFrame extends Frame implements ActionListener,AdjustmentListener{
Scrollbar salSlider;
TextField salValue,sal_ref;
double value;
Button close=new Button("关闭");
SliderFrame(double initSal,double minSal,TextField return_sal)
{
super("输入工资");
sal_ref=return_sal;
setLayout(new BorderLayout());
salSlider=new Scrollbar(Scrollbar.HORIZONTAL ,(int)initSal,1,(int)minSal,(int)minSal*20);
salSlider.setUnitIncrement(1);
salSlider.setBlockIncrement(50);
salSlider.addAdjustmentListener(this);
add("North",salSlider);
salValue=new TextField(Double.toString(initSal),6 );
add("South",close);
close.addActionListener(this);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand() =="关闭"){
sal_ref.setText(new Integer((int)value).toString() ) ;
dispose();
}
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
if(e.getAdjustable() ==salSlider)
{
value=e.getValue() ;
salValue.setText(new Integer((int)value).toString() ) ;
}
}
double getValue()
{
return value;
}
}

  class Employee{ //定义雇员类
int m_EmpNo;
String m_EmpName;
boolean m_isMgr;
char m_EmpGender;
static int m_NextEmpNo;
static final double m_MinSalary=250;
Date m_StartWorkDate;
double m_EmpSalary;
static{
m_NextEmpNo=1001;
}
Employee(String name,double initSal,char sex,boolean mgr,Date wdate)
{
m_EmpNo=m_NextEmpNo++;
m_EmpName=new String(name);
m_isMgr=mgr;
if(initSal<m_MinSalary)
System.exit(0);
m_EmpSalary=initSal;
m_EmpGender=sex;
m_StartWorkDate=new Date(wdate.getTime());
}
int getEmpNo(){
return m_EmpNo;
}
static double getMinSal(){
return m_MinSalary;
}
public String toString()
{
String s;
s="编号:"+m_EmpNo+";姓名:"+m_EmpName;
if(m_isMgr)
s=s+":是主管";
if(m_EmpGender=='m')
s=s+";\n 性别:女";
s=s+";\n工资:"+m_EmpSalary;
if(m_StartWorkDate!=null)
s=s+";\n开始工作:"+(m_StartWorkDate.getYear()+1900)+"/"+(m_StartWorkDate.getMonth()+1)+"/"+m_StartWorkDate.getDate();
return s;
}
}




话题树型展开
人气 标题 作者 字数 发贴时间
11304 这里有一处错误请大家帮我看一下 ! !! lbssy 7245 2008-05-09 19:48

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