码迷,mamicode.com
首页 > 编程语言 > 详细

第一个java程序

时间:2015-03-18 14:10:15      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

package helloo;


import java.awt.BorderLayout;
import java.awt.EventQueue;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JSplitPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class hellooo extends JFrame {


	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;


	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					hellooo frame = new hellooo();
					frame.setVisible(true);
					frame.setTitle("-*-数字相加-*-");
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}


	/**
	 * Create the frame.
	 */
	public hellooo() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(4, -30, 450, 300);
		contentPane = new JPanel();
		contentPane.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
			}
		});
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("");
		label.setBounds(5, 5, 0, 256);
		contentPane.add(label);
		
		JLabel lblNewLabel = new JLabel("num1");
		lblNewLabel.setBounds(36, 40, 54, 15);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setBounds(122, 37, 66, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel a = new JLabel("num2");
		a.setBounds(36, 95, 54, 15);
		contentPane.add(a);
		
		textField_1 = new JTextField();
		textField_1.setBounds(122, 92, 66, 21);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblNewLabel_2 = new JLabel("sum");
		lblNewLabel_2.setBounds(36, 146, 54, 15);
		contentPane.add(lblNewLabel_2);
		
		textField_2 = new JTextField();
		textField_2.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if(e.getKeyChar()==KeyEvent.VK_ENTER )     {
					 double head = Double.parseDouble(textField.getText());
					    double foot = Double.parseDouble(textField_1.getText());
					    double roosterNum = head+foot;
					    textField_2.setText(""+roosterNum);
				 }
			}
		});
		textField_2.setBounds(122, 143, 66, 21);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		
		JButton btnCal = new JButton("cal");
		btnCal.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				 if(e.getKeyChar()==KeyEvent.VK_ENTER )     {
					 double head = Double.parseDouble(textField.getText());
					    double foot = Double.parseDouble(textField_1.getText());
					    double roosterNum = head+foot;
					    textField_2.setText(""+roosterNum);
				 }
			}
		});
		
		
		btnCal.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				double head = Double.parseDouble(textField.getText());
			    double foot = Double.parseDouble(textField_1.getText());
			    double roosterNum = head+foot;
			    textField_2.setText(""+roosterNum);
			    
			}
		});
		btnCal.setBounds(71, 206, 93, 23);
		contentPane.add(btnCal);
	}
}

技术分享

第一个java程序

标签:

原文地址:http://blog.csdn.net/u013076044/article/details/44408645

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!