背景會變得記事本 – JAVA編程語言程序開發技術文章

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="" 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();} */}

摘自 djw10962000的專欄

發佈留言