您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > JAVA简单用户界面----留言板
JAVA简单用户界面----留言板importjava.awt.*;importjava.awt.event.*;importjava.util.Date;importjava.text.SimpleDateFormat;importjava.io.*;importjava.applet.*;publicclassframe{publicstaticvoidmain(String[]args){newMyFrame();}}classMyFrameextendsFrame{//PanelP1,P2;ButtonbtnYes,btnNo;Labellname,lno,lsex,lmassage,lwelcome;TextFieldno,name;TextAreainfo,massage;Choicesex;Checkboxcheck;StringBuffersb=newStringBuffer();MyFrame(){setVisible(true);setSize(700,300);setTitle(PP);setResizable(false);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});//P1=newPanel();//P1.setBackground(Color.red);//P2=newPanel();//P2.setBackground(Color.yellow);//setLayout(newFlowLayout());lwelcome=newLabel(欢迎使用留言板!);add(lwelcome);lname=newLabel(姓名:);add(lname);name=newTextField(5);add(name);lno=newLabel(学号:);add(lno);no=newTextField(10);add(no);lsex=newLabel(性别:);add(lsex);lmassage=newLabel(留言信息:);add(lmassage);sex=newChoice();sex.add(男);sex.add(女);add(sex);btnNo=newButton(清除);add(btnNo);btnYes=newButton(留言);add(btnYes);info=newTextArea(3,20);add(info);massage=newTextArea(5,70);add(massage);check=newCheckbox(匿名留言);add(check);setLayout(null);lwelcome.setBounds(45,50,130,20);check.setBounds(274,110,80,20);lname.setBounds(45,80,30,20);name.setBounds(80,80,50,20);lno.setBounds(150,80,30,20);no.setBounds(185,80,50,20);lsex.setBounds(250,80,30,20);sex.setBounds(290,80,50,20);info.setBounds(130,130,210,100);lmassage.setBounds(45,125,60,50);btnYes.setBounds(55,235,100,30);btnNo.setBounds(200,235,100,30);massage.setBounds(360,50,300,200);massage.setEditable(false);btnYes.addActionListener(newSubmit());btnNo.addActionListener(newCancle());check.addItemListener(newChecked());}classCheckedimplementsItemListener{publicvoiditemStateChanged(ItemEvente){Checkboxtemp;temp=(Checkbox)(e.getSource());if(temp.getState()){name.enable(false);no.enable(false);sex.enable(false);}else{name.enable(true);no.enable(true);sex.enable(true);}}}classSubmitimplementsActionListener{publicvoidactionPerformed(ActionEvente){SimpleDateFormatdf=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);//Filefile=newFile(d:\\a.txt);//OutPutStreamout=newFileOutPutStream(file);if((e.getSource())==btnYes){if(check.getState()){massage.setText(massage.getText()+匿名留言!+\r\n+留言时间:+df.format(newDate())+\r\n+留言内容:+info.getText()+\r\n\n);info.setText();}else{massage.setText(massage.getText()+学号:+no.getText()+姓名:+name.getText()+性别:+sex.getSelectedItem()+\r\n+留言时间:+df.format(newDate())+\r\n+留言内容:+info.getText()+\r\n\n);no.setText();name.setText();info.setText();}}}}classCancleimplementsActionListener{publicvoidactionPerformed(ActionEvente){if((e.getSource())==btnNo){no.setText();name.setText();info.setText();massage.setText();}}}}效果图:
本文标题:JAVA简单用户界面----留言板
链接地址:https://www.777doc.com/doc-4294399 .html