灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2346回复:0

背景会变得记事本代码

楼主#
更多 发布于:2012-09-08 09:35

import java.awt.Color;import java.awt.Frame;import java.awt.Label;import java.awt.Button;import java.awt.Panel;import java.awt.TextArea;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseMotionAdapter;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.Random;public class TestTextArea {public static void main(String[]args){int i1 = new Random().nextInt(255);int i2 = new Random().nextInt(255);int i3 = new Random().nextInt(255);Frame f = new Frame("段晋文的留言板");TextArea message =new TextArea("请您留言:");System.out.println(i1);System.out.println(i2);System.out.println(i3);message.setBackground(new Color(i1,i2,i3));//TextArea message =new TextArea(20,20);f.add(message,"Center");Panel p1 = new Panel();GridLayout gl = new GridLayout(1,6);p1.setLayout(gl);String[] buttonLabel ={"剪贴","复制","粘贴","删除","提交","清屏"};String[] buttonActionCommands = {"CUT","COPY","PASTE","DEL","SUB","CLEAR"};Button[] buttons = new Button[6];OuterMonitor11 om = new OuterMonitor11(message,buttons);for(int i=0;i<buttons.length;i++){buttons = new Button(buttonLabel);buttons.setActionCommand(buttonActionCommands);if(i<4 buttons="" i="" setenabled="" false="" buttons="" i="" addactionlistener="" om="" p1="" add="" buttons="" i="" message="" addmousemotionlistener="" om="" f="" add="" p1="" north="" f="" addwindowlistener="" new="" windowadapter="" public="" void="" windowclosing="" windowevent="" e="" system="" exit="" 0="" f="" setlocation="" 500="" 300="" f="" setsize="" 280="" 200="" f="" setbackground="" color="" cyan="" f="" setvisible="" true="" import="" java="" awt="" textarea="" import="" java="" awt="" button="" import="" java="" awt="" event="" actionevent="" import="" java="" awt="" event="" mousemotionadapter="" import="" java="" awt="" event="" mouseevent="" import="" java="" awt="" event="" actionlistener="" public="" class="" outermonitor11="" extends="" mousemotionadapter="" implements="" actionlistener="" private="" textarea="" msgboard="" private="" button="" buttons="" private="" string="" clipboard="" public="" outermonitor11="" textarea="" newmsgboard="" button="" buttons="" this="" msgboard="newmsgBoard;" this="" buttons="buttons;" public="" void="" setclipboard="" string="" text="" this="" clipboard="text;" public="" string="" getclipboard="" return="" this="" clipboard="" public="" void="" actionperformed="" actionevent="" e="" int="" positon="msgBoard.getSelectionStart();" string="" s="e.getActionCommand();" if="" s="" equals="" clear="" msgboard="" settext="" else="" if="" s="" equals="" sub="" system="" out="" println="" n="" msgboard="" gettext="" else="" if="" s="" equals="" copy="" clipboard="msgBoard.getSelectedText();" msgboard="" setselectionstart="" msgboard="" getselectionend="" else="" if="" e="" equals="" cut="" clipboard="msgBoard.getSelectedText();" this="" delete="" else="" if="" e="" equals="" paste="" string="" content="msgBoard.getText();" string="" alter="content.substring(0,positon)+clipBoard+content.substring(positon);" msgboard="" settext="" alter="" else="" if="" e="" equals="" del="" this="" delete="" public="" void="" delete="" int="" start="msgBoard.getSelectionStart();" int="" end="msgBoard.getSelectionEnd();" string="" content="msgBoard.getText();" string="" alter="content.substring(0," start="" content="" substring="" end="" msgboard="" settext="" alter="" public="" void="" switchbuttons="" boolean="" clipped="(clipBoard!=null);;(clipBoard.length()">0);buttons[2].setEnabled(clipped);boolean selected = msgBoard.getSelectionEnd()!=msgBoard.getSelectionStart();buttons[0].setEnabled(selected);buttons[1].setEnabled(selected);buttons[3].setEnabled(selected);}public void mouseDragged(MouseEvent e){this.switchButtons();}/*public void switchButtons(){boolean clipped = (clipBoard!=null) ;; (clipBoard.length()>0);buttons[2].setEnabled(clipped);boolean selected = msgBoard.getSelectionEnd() != msgBoard.getSelectionStart();buttons[0].setEnabled(selected);buttons[1].setEnabled(selected);buttons[3].setEnabled(selected);}@Overridepublic void mouseDragged(MouseEvent te){this.switchButtons();} */}


喜欢0 评分0
游客

返回顶部