Trang Chủ | Diễn Đàn | Thành Viên (Đăng Ký) | Tìm Kiếm | Tutorial Room

RA MẮT THỬ NGHIỆM PHIÊN BẢN MỚI CỦA DIỄN ĐÀN

Java - Giúp mình vấn đề này với
Hỏi đáp, trao đổi về lập trình Java.
- Các câu hỏi về JavaScript xin hãy gởi vào box HTML & JavaScript.
- Các câu hỏi về lập trình JSP/Server, J2EE xin hãy gởi vào box JSP/Servlet - J2EE.
Chú ý: Java FAQs
First page Previous page  (Page 1 )   1   Next page Last page
Giúp mình vấn đề này với
Member
Member since
02:11 11-05-2010
Posts: 4
Fantasy Points: 16
Rank
sad Posted at 21:52 31-05-2010 Move Move Topic   Pin/Unpin Pin Topic   Lock Lock Topic
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* Calculator.java
*
* Created on May 31, 2010, 10:09:58 PM
*/
/**
*
* @author Administrator
*/
public class Calculator extends javax.swing.JFrame {

    /** Creates new form Calculator */
    public Calculator() {
        initComponents();
    }

    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        txtDesktop = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jb7 = new javax.swing.JButton();
        jb8 = new javax.swing.JButton();
        jb9 = new javax.swing.JButton();
        jbChia = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jb4 = new javax.swing.JButton();
        jb5 = new javax.swing.JButton();
        jb6 = new javax.swing.JButton();
        jbNhan = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jbBang = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        txtDesktop.setText("0");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtDesktop, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(txtDesktop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(6, Short.MAX_VALUE))
        );

        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        jb7.setText("7");
        jb7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb7ActionPerformed(evt);
            }
        });
        jPanel2.add(jb7);

        jb8.setText("8");
        jb8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb8ActionPerformed(evt);
            }
        });
        jPanel2.add(jb8);

        jb9.setText("9");
        jPanel2.add(jb9);

        jbChia.setText("/");
        buttonGroup1.add(jbChia);
        jbChia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbChiaActionPerformed(evt);
            }
        });
        jPanel2.add(jbChia);

        jPanel3.setLayout(new java.awt.GridLayout(1, 0));

        jb4.setText("4");
        jPanel3.add(jb4);

        jb5.setText("5");
        jPanel3.add(jb5);

        jb6.setText("6");
        jPanel3.add(jb6);

        jbNhan.setText("*");
        buttonGroup1.add(jbNhan);
        jbNhan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNhanActionPerformed(evt);
            }
        });
        jPanel3.add(jbNhan);

        jPanel4.setLayout(new java.awt.GridLayout(1, 0));

        jbBang.setText("=");
        jbBang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBangActionPerformed(evt);
            }
        });
        jPanel4.add(jbBang);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                .addGap(10, 10, 10))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void jb7ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        String s = jb7.getText();
        String s1 = txtDesktop.getText();
        if (s1.indexOf("0") == 0) {
            s1 = s1.substring(1);
        }
        txtDesktop.setText(s1 + s);
    }

    private void jb8ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        String s = jb8.getText();
        String s1 = txtDesktop.getText();
        if (s1.indexOf("0") == 0) {
            s1 = s1.substring(1);
        }
        txtDesktop.setText(s1 + s);
    }

    private void jbChiaActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        NumberLast = Integer.parseInt(txtDesktop.getText());
        txtDesktop.setText("0");
    }

    private void jbBangActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:

    }

    private void jbNhanActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        NumberLast = Integer.parseInt(txtDesktop.getText());
        txtDesktop.setText("0");
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Calculator().setVisible(true);
            }
        });
    }
    int NumberLast;
    int NumberNext;
    // Variables declaration - do not modify
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JButton jb4;
    private javax.swing.JButton jb5;
    private javax.swing.JButton jb6;
    private javax.swing.JButton jb7;
    private javax.swing.JButton jb8;
    private javax.swing.JButton jb9;
    private javax.swing.JButton jbBang;
    private javax.swing.JButton jbChia;
    private javax.swing.JButton jbNhan;
    private javax.swing.JTextField txtDesktop;
    // End of variables declaration
}


Mình đang bí chỗ là khi mình chọn button "*" or "/" thì khi xuống button "=" nó sẽ làm sao biết là mình bắt sự kiên nào ("*" or "/") ???. Ai biết chỉ dùm cái nhá. [:p] [:p] [:p]
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 437 time(s). 1 direct repli(es) and 0 indirect repli(es).
Title Poster
sad Giúp mình vấn đề này với
 
answer Re: Giúp mình vấn đề này với
ddung
Re: Giúp mình vấn đề này với
Member
Member since
01:52 31-07-2006
Posts: 57
Fantasy Points: 219
answer Posted at 03:45 11-06-2010
Reply to Giúp mình vấn đề này với (tigker)
thì lưu nó vào 1 biến rồi lấy cái nhấn - sự kiến cuối cùng ấy.
Giúp tư vấn, hỗ trợ làm đồ án môn học, tốt nghiệp.
Liên hệ:
yahoo do_an_mon
Email: do_an_mon@yahoo.com
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 364 time(s). 0 direct repli(es) and 0 indirect repli(es).
First page Previous page  (Page 1 )   1   Next page Last page

Permissions: Create Topic: No  |  Reply Topic: No  |  Attach File: No  |  Make Poll: No

Vietnamese Keyboard: AUTO TELEX VNI VIQR VIQR* OFF

Go top || Print page ||

All logos, trademarks and graphics artwork in this site are property of their respective owners.
Opinions expressed in articles within this site are those of their owners and may not reflect the opinion of TXBB.

TXBB: Home - Disclaimer - Help - Contact
Copyright (C) 2000-2006 TXBB. All rights reserved.

TreXanh Bulletin Board v2.0 (Build: #332 Nov 21, 2006)

DEBUG INFORMATION
Execution 0.229s - SQL used 6s - Concurrent process(es) 0