Java====color, Font, button, label, TextField, textarea use

Source: Internet
Author: User
Tags event listener set background

1. The Color class Μ public static properties: A total of 13 static properties representing 13 different color constants. Μ constructor üpublic Color (int r,int g,int b): Gives the values of the three components of red, green, and blue as integers, the range of each component: 0~255üpublic Color (float r,float g,float b): R, G, B are single-precision floating-point numbers. The value range is 0.0f~1.0füpublic Color (int RGB): RGB 16~23 bit: Red component, 0~7 bit: Blue component, 8~15 bit: Green component.    2. Common method public int getred (): Returns the red component value of the Color object public int getgreen (): Returns the green component value of the Color object public int getBlue (): Returns the blue component value of the Color object ¯ Set color settings component background and foreground color: public void SetBackground (color c): Set background color public void setforeground (color c): Set foreground color cyan: cyan; gray: Grey; Magenta: dark red; 9p3. The font class in the FONTJAVA.AWT package provides a font class for constructing fonts objects, which also provide properties and methods for some of the font-related columns. ¯ Constructor Public Font (String name,int style,int size); Name: Specifies the font name (Arial, italic, etc.). You can use the Getavailablefontfamilyname () method provided in the Graphicsenvironment class to get the names of the various available fonts); style: Make the appearance of the font (public static properties: Bold (Bold), ITALIC (Italic), PLAIN (normal)); Size: Specifies the font size. The unit is a point (a point =1/72 inch) in pixels (pixel). Example: Font font1=new font ("Arial", font.bold,50); methods commonly used in 4.Font classes: public string toString ()--Returns a descriptive string of the font. public int GetStyle ()--Returns the integer value of the current font style public int getsize ()--Returns the integer value of the current font size public int String getName ()--Returns the name of the current font public String getfamily ()--Returns the current font family name public boolean isplain ()--whether the current font is Normal style public boolean isbold ()-- Whether the current font is bold style public Boolean isitalic ()--whether the current font is Italic style 5. The Java.awt.Font class is used to set the font of the display text on the component in GUI development, and the corresponding method is defined in the Java.awt.Component class in the following format: public void SetFont (font font)---- Set Font public font getfont ()----Returns the creation and setting of the font for the current font object should be made before the output is displayed, otherwise it will be displayed in the system default font. 6. Labels and buttons µ labels label: Used to display a line of text messages. It cannot respond to mouse events.    ü Construction Method PUBLICC label (): Constructs a label that does not have any display text.    Public label (String str): Constructs a label that specifies the display text. Public label (String str,int Alignment): Alignment refers to the alignment of the label. The parameter alignment has three values that specify the alignment of the text in the label: label.left, Text Habitat label component left align Label.center, text Center align Label.right, Text Habitat label component Right align ü Other common methods public String GetText ();p ublic void SetText (String str);p ublic void setalignment (in alignment) public void SetBackground (Color c );p ublic void Setforeground (Color c); Μ button: Used to receive the user's click action and trigger the appropriate processing logic. ü Construction method Public button (): Creates a button without a caption. Public Button (Stirng label): with a caption. ü Triggered event: The ActionEvent event is triggered when the user clicks the button with the mouse, registering the event listener method: public void addActionListener (ActionlisteneR L) 7. Text components A so-called text component is a component that can display and edit text information. ComponentTextComponentTextFieldTextArea8. text box TextField: Used to receive/edit single-line text information (such as user name, password): Construction method: Public TextField (): Default length text box. public TextField (int columns): An empty text box that can hold columns characters. Public TextField (String str): A text box with the initial text.  Public TextField (string str,int columns); Common method: Public String getText (); public void SetText (string str) public string Getselectedtext (): Returns the text that is selected in the text box. public void Setechochar (char c): Sets the echo character in the text box. public void seteditable (Boolean b): Sets the editable state of the text box, and B is false when the text box is not editable. Triggering events can trigger the ActionEvent event when the ENTER key is pressed in the TextField component, so the ActionListener listener can be registered on the TextField component to correlate the required processing logic. 9. Text area TextArea: Used to display and edit multi-line, multi-column text information, when the display text exceeds the size of the text area automatically appear horizontal and vertical scroll bar u construction method Public TextArea (): Default rows and columns. Public TextArea (int rows,int columns);p ublic TextArea (string str,int rows,int columns);p ublic TextArea (String str,int Rows,int columns,int ScrollBar): ScrollBar is a scroll bar. The constants that the scrollbar can set: TextArea.SCROLLBARS_BOTHTextArea.SCROLLBARS_HORIZONTAL_ONLY: Only horizontal. Textarea.scrollbars_nonEtextarea.scrollbars_vertical_onlyü Common Methods Public String getText ();p ublic void SetText (String str);p ublic void append (str ing str): Appends the string str to the end of the current text in the text area. public int getcaretposition (): Returns the position of the current insertion point in the text area. public void Insert (String str,int POS): Inserts str into the specified position. Public String Getselectedtext (): Returns the selected text. public int Getselectionstart ();p ublic int getselectionend ();p ublic void Replacerange (String str,intstart,int end) : Replaces str with text from start to end in the text area. The event is triggered when the content in the text area changes: TextEvent event, moving in a text box, dragging the mouse triggers the MouseEvent event TEXTAREA component originally supported the quick way to cut, copy, paste General editing operations (corresponding to shortcut keys Ctrl+x,ctrl+c, CTRL + V, respectively)

  

Java====color, Font, button, label, TextField, textarea use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.