[JAVA100 example]018, using HTML language

Source: Internet
Author: User
Tags event listener

Import javax.swing.*;


import java.awt.*;


import java.awt.event.*;


/**


* <p>title: Using HTML language </p>
in swing

* <p>description: This demonstrates the use of HTML language to construct display information on swing panels </p>


* <p>copyright:copyright (c) 2003</p>


* <p>Filename:HtmlDemo.java</p>


* @version 1.0


*/


public class Htmldemo extends JPanel


implements ActionListener {


JLabel Thelabel;


JTextArea HtmlTextArea;


/**


*<br> Method Description: Constructor, which describes the members of a form


*<br> input Parameters:


*<br> return type:


*/


public Htmldemo () {


setlayout (The new BoxLayout (this, boxlayout.line_axis));


String initialtext = "<html>\n" +


"Color and font test: \ n" +


"<ul>\n" +


"<li><font color=red>red</font>\n" +


"<li><font color=blue>blue</font>\n" +


"<li><font color=green>green</font>\n" +


"<li><font size=-2>small</font>\n" +


"<li><font size=+2>large</font>\n" +


"<li><i>italic</i>\n" +


"<li><b>bold</b>\n" +


"</ul>\n";


//Define a text box


HtmlTextArea = new JTextArea (10, 20);


Htmltextarea.settext (Initialtext);


JScrollPane ScrollPane = new JScrollPane (HtmlTextArea);


//Definition button


JButton Changethelabel = new JButton ("Change display");


changethelabel.setmnemonic (Keyevent.vk_c);


Changethelabel.setalignmentx (component.center_alignment);


Changethelabel.addactionlistener (this);


//Definition label


Thelabel = new JLabel (initialtext) {


public Dimension getpreferredsize () {


return new Dimension (200, 200);


      }


public Dimension getminimumsize () {


return new Dimension (200, 200);


      }


public Dimension getmaximumsize () {


return new Dimension (200, 200);


      }


    };


//sets the alignment of the label


thelabel.setverticalalignment (Swingconstants.center);


thelabel.sethorizontalalignment (Swingconstants.center);


//Constructs a border-left edit panel


JPanel Leftpanel = new JPanel ();


Leftpanel.setlayout (New BoxLayout (Leftpanel, Boxlayout.page_axis));


Leftpanel.setborder (Borderfactory.createcompoundborder (


Borderfactory.createtitledborder (


edit HTML, click the button to display the results. "),


Borderfactory.createemptyborder (10,10,10,10)));


Leftpanel.add (ScrollPane);


Leftpanel.add (Box.createrigidarea (New Dimension (0,10)));


Leftpanel.add (Changethelabel);


//Construct a panel with a border to the right display


JPanel Rightpanel = new JPanel ();


rightpanel.setlayout (New BoxLayout (Rightpanel, Boxlayout.page_axis));


Rightpanel.setborder (Borderfactory.createcompoundborder (


Borderfactory.createtitledborder ("Show HTML results here using tags"),


Borderfactory.createemptyborder (10,10,10,10)));


Rightpanel.add (Thelabel);





SetBorder (Borderfactory.createemptyborder (10,10,10,10));


Add (Leftpanel);


Add (Box.createrigidarea (new Dimension (10,0)));


Add (Rightpanel);


  }


/**


*<br> Method Description: Event listener, when the user clicks on the button to trigger the


*<br> input Parameters:


*<br> return type:


*/


public void actionperformed (ActionEvent e) {


Thelabel.settext (Htmltextarea.gettext ());


  }


/**


*<br> Method Description: Main method


*<br> input Parameters:


*<br> return type:


*/


public static void Main (string[] args) {


jframe.setdefaultlookandfeeldecorated (TRUE);


//Create form


JFrame frame = new JFrame ("Htmldemo");


frame.setdefaultcloseoperation (jframe.exit_on_close);


//Create panel


JComponent Newcontentpane = new Htmldemo ();


Newcontentpane.setopaque (TRUE);


Frame.setcontentpane (Newcontentpane);


//Display form


Frame.pack ();


frame.setvisible (TRUE);


  }


}

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.