Java Image Interface Development Simple example-jtextarea, JScrollPane, JPanel, JButton application Example

Source: Internet
Author: User

Java Image Interface Development Simple example

JTextArea, JScrollPane, JPanel, JButton application examples, through the ' Insert Text ' button function, write Test text, line-wrapping function can be used for line and no line, the code is as follows: Import java.awt.BorderLayout;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;

Import Javax.swing.JButton;
Import Javax.swing.JFrame;
Import Javax.swing.JPanel;
Import Javax.swing.JScrollPane;
Import Javax.swing.JTextArea;


/**
* JTextArea, JScrollPane, JPanel, JButton application examples
* @author Zuojie JDK 5.0
*/
public class Example8frame extends JFrame {

Private static final long serialversionuid = 1L;
Private JTextArea TextArea; Text fields
Private JScrollPane ScrollPane; with scroll bar panel
Private JPanel Buttonpanel; Store button panel
Private JButton Wrapbutton; Line Wrap button
Public Example8frame () {
Settitle ("text editor"); Set the title of a form
SetSize (300, 300); Set the size of a form
Creating JTextArea Components
TextArea = new JTextArea ();
Create the JScrollPane panel and put the JTextArea component in the scroll bar panel
ScrollPane = new JScrollPane (TextArea);
Add a scroll bar panel to a form
Add (ScrollPane, borderlayout.center);

Buttonpanel = new JPanel (); Create a button panel
Create the Insert Text button and add a click event to add the test text
JButton Insertbutton = new JButton ("Insert text"); Create the Insert Text button
Buttonpanel.add (Insertbutton); Add this button to the panel
Add event Monitoring for this button
Insertbutton.addactionlistener (new ActionListener () {
public void actionperformed (ActionEvent event) {
Textarea.append ("This is a simple application instance of a TextArea component, this is the test text.") " ); JTextArea Component Add text information
}
});
Add a "line break" button and add a click event to control line break and no wrap
Wrapbutton = new JButton ("newline"); Create a NewLine text button
Buttonpanel.add (Wrapbutton); Add this button to the panel
Add event Monitoring for this button
Wrapbutton.addactionlistener (new ActionListener () {
public void actionperformed (ActionEvent event) {
Boolean wrap =! Textarea.getlinewrap (); Gets whether the JTextArea component has a newline state, default to False, and reverse
Textarea.setlinewrap (wrap); Reset whether line wrapping properties
Wrapbutton.settext (Wrap?) "Do not Wrap": "Line Change"); Display text based on the property settings button
}
});
Add a button panel to a form
Add (Buttonpanel, Borderlayout.south);
}
public static void Main (string[] args) {
Example8frame frame = new Example8frame ();
Frame.setdefaultcloseoperation (Jframe.exit_on_close);
Frame.setvisible (TRUE);
}
}

Related Article

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.