South Mail Java Programming Experiment 1 integrated graphical interface programming

Source: Internet
Author: User

South Mail Java Programming Experiment 1 integrated graphical interface programming


Experimental Purpose:

Learn and understand the container, part, Layout manager, and part event handling methods in Java swing. Master the basic methods of programming Java GUI by writing and debugging the program.


Experimental content:

To design and write a program for converting renminbi into equivalent dollars, the interface requires that the amount of the renminbi be entered and the converted result can be obtained. (Buy RMB per $100 equivalent: 619.72)


Experiment Code:

Import java.awt.*;import java.awt.event.*;import java.math.*;import javax.swing.*;class Java1{public static void main (        String[] args) {/* Create Interface Settings tab, etc. */JFrame frame = new JFrame ("exchange rate conversion");        Container ct = Frame.getcontentpane ();        JPanel panel = new JPanel ();        Panel.setlayout (New FlowLayout ());        JLabel LABELRMB = new JLabel ("RMB");        Final JTextArea TEXTRMB = new JTextArea (1, 15);        JLabel Labeldol = new JLabel ("USD");        Final JTextArea Textdol = new JTextArea (1, 15);        JButton button = new JButton ("exchange rate conversion");        /* Set dollar out text box read-only property */textdol.setenabled (FALSE);        /* Add controls */Panel.add (LABELRMB);        Panel.add (TEXTRMB);        Panel.add (Labeldol);        Panel.add (Textdol);        Panel.add (button);        Ct.add (panel);        Frame.setvisible (TRUE);        Frame.setsize (200, 200); /* Set the Listener, press the button to convert the binary/button.addactionlistener (new ActionListener () {public void actionperformed (ACtionevent e) {String STRRMB = Textrmb.gettext ();                Double DRMB = double.parsedouble (STRRMB);                Double Ddol = DRMB * 100.00/619.72;                /* Keep two decimal places */BigDecimal B = new BigDecimal (Ddol);                Double dol = B.setscale (2, bigdecimal.round_half_up). Doublevalue ();                String Strdol = string.valueof (DOL);            Textdol.settext (Strdol);        }        });                /* Monitor Close Window event */Frame.addwindowlistener (new Windowadapter () {public void windowclosing (WindowEvent e) {            System.exit (0);    }        }); }}






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

South Mail Java Programming Experiment 1 integrated graphical interface programming

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.