背景会变得记事本

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[i] = new Button(buttonLabel[i]);buttons[i].setActionCommand(buttonActionCommands[i]);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="" getselectiοnend="" 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值