第一個java程式

來源:互聯網
上載者:User

標籤:

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() {@Overridepublic 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() {@Overridepublic 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() {@Overridepublic 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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.