Swing Display Frame

Source: Internet
Author: User

While both programs and applications can become important, it becomes confusing and useless to use them everywhere. The remainder of this section replaces them with the display framework for a swing program example:

: Show.java
//Tool for displaying Swing demos
package c13.swing;
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;

public class Show {public
  static void 
  inframe (JPanel jp, int width, int height) {
    String title = Jp.getclass (). toString ();
    Remove the word "class":
    if (Title.indexof ("class")!=-1)
      title = title.substring (6);
    JFrame frame = new JFrame (title);
    Frame.addwindowlistener (New Windowadapter () {public
      void windowclosing (WindowEvent e) {
        system.exit (0);
    Frame.getcontentpane (). Add (
      JP, borderlayout.center);
    Frame.setsize (width, height);
    Frame.setvisible (True);

Classes that want to show their own will inherit from the JPanel and then add some visual components to themselves. Finally, they create a main () that contains the following line of programs:
Show.inframe (New MyClass (), 500, 300);
The last two arguments are the width and height of the display.
Note that the title of the JFrame is produced with Rtti.

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.