首页 > 代码库 > 第一个java程序
第一个java程序
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程序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。