Small java Experiment

Source: Internet
Author: User

[Java]
Package Second;
Import java. awt .*;
Import javax. swing .*;
Import java. math .*;
Import java. awt. event .*;
Public class test1 implements ActionListener {
 
/**
* @ Param args
*/Www.2cto.com
Public JTextField s = new JTextField (13 );
Public JTextField s1 = new JTextField (13 );
Public JLabel l1 = new JLabel ("square ");
Public JLabel l2 = new JLabel ("cube ");
Public JLabel l3 = new JLabel (" ");
Public JButton b1 = new JButton ("square result ");
Public JButton b2 = new JButton ("cube result ");
Public JButton b3 = new JButton (" ");
Void display ()
{

JPanel panel = new JPanel (new GridLayout (4, 2 ));
JFrame jf = new JFrame ("Test Program ");
Jf. setSize (300,200 );
Jf. setContentPane (panel );
Jf. setVisible (true );
Jf. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE );
Jf. setResizable (false );
Panel. add (s );
Panel. add (s1 );
Panel. add (l1 );
Panel. add (b1 );
Panel. add (l2 );
Panel. add (b2 );
Panel. add (l3 );
Panel. add (b3 );
B1.addActionListener (this );
B2.addActionListener (this );
B3.addActionListener (this );
}
Public void actionreceivmed (ActionEvent e ){

If (e. getSource () = b1)
{
Double a = Double. parseDouble (s. getText ());
A = a *;
S1.setText ("" + );
}
Else if (e. getSource () = b2)
{
Double a = Double. parseDouble (s. getText ());
A = a *;
S1.setText ("" + );

}
Else if (e. getSource () = b3)
{
Double a = Double. parseDouble (s. getText ());
A = a *;
S1.setText ("" + );
}
}
Public static void main (String [] args ){
// TODO Auto-generated method stub
Test1 m = new test1 ();
M. display ();
}
 
}

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.