Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package firstlabb2;
- public class FirstLabB2
- {
- public static void main(String[] args)
- {
- TestFrame1 obj = new TestFrame1();
- obj.setVisible(true);
- }
- }
- public class TestFrame1 extends javax.swing.JFrame {
- /**
- * Creates new form TestFrame1
- */
- public TestFrame1() {
- 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() {
- nameLabel = new javax.swing.JLabel();
- nameTextField = new javax.swing.JTextField();
- showLabel = new javax.swing.JLabel();
- showTextField = new javax.swing.JTextField();
- showButton = new javax.swing.JButton();
- num1TextField = new javax.swing.JTextField();
- num2TextField = new javax.swing.JTextField();
- resultTextField = new javax.swing.JTextField();
- addButton = new javax.swing.JButton();
- minusButton = new javax.swing.JButton();
- multiplyButton = new javax.swing.JButton();
- divideButton = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- nameLabel.setText("Enter you name");
- showLabel.setText("Hello");
- showTextField.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- showTextFieldActionPerformed(evt);
- }
- });
- showButton.setText("SHOW");
- showButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- showButtonActionPerformed(evt);
- }
- });
- resultTextField.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- resultTextFieldActionPerformed(evt);
- }
- });
- addButton.setText("ADD");
- addButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- addButtonActionPerformed(evt);
- }
- });
- minusButton.setText("Minus");
- minusButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- minusButtonActionPerformed(evt);
- }
- });
- multiplyButton.setText("Multiply");
- multiplyButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- multiplyButtonActionPerformed(evt);
- }
- });
- divideButton.setText("Divide");
- divideButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- divideButtonActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(53, 53, 53)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(nameLabel)
- .addComponent(showLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(num1TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(num2TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
- .addGap(18, 18, 18)
- .addComponent(resultTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(showTextField)
- .addComponent(nameTextField))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(divideButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(multiplyButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(showButton)
- .addComponent(minusButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(addButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(76, 76, 76))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(99, 99, 99)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(nameLabel)
- .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(showLabel)
- .addComponent(showTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(showButton))
- .addGap(27, 27, 27)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(num1TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(num2TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(resultTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(addButton))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(minusButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(multiplyButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(divideButton)
- .addContainerGap(15, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void showTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void showButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String name = nameTextField.getText();
- showTextField.setText(name);
- }
- private void resultTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int num1,num2,result;
- num1=Integer.parseInt(num1TextField.getText());
- num2=Integer.parseInt(num2TextField.getText());
- result=num1+num2;
- //resultTextField.setText(Integer.toString(result));
- //another way to write the previous line :
- resultTextField.setText(""+result);
- }
- private void minusButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int num1,num2,result;
- num1=Integer.parseInt(num1TextField.getText());
- num2=Integer.parseInt(num2TextField.getText());
- result=num1-num2;
- //resultTextField.setText(Integer.toString(result));
- //another way to write the previous line :
- resultTextField.setText(""+result);
- }
- private void multiplyButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int num1,num2,result;
- num1=Integer.parseInt(num1TextField.getText());
- num2=Integer.parseInt(num2TextField.getText());
- result=num1*num2;
- //resultTextField.setText(Integer.toString(result));
- //another way to write the previous line :
- resultTextField.setText(""+result);
- }
- private void divideButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- int num1,num2,result;
- num1=Integer.parseInt(num1TextField.getText());
- num2=Integer.parseInt(num2TextField.getText());
- result=num1/num2;
- //resultTextField.setText(Integer.toString(result));
- //another way to write the previous line :
- resultTextField.setText(""+result);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(TestFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(TestFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(TestFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(TestFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new TestFrame1().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton addButton;
- private javax.swing.JButton divideButton;
- private javax.swing.JButton minusButton;
- private javax.swing.JButton multiplyButton;
- private javax.swing.JLabel nameLabel;
- private javax.swing.JTextField nameTextField;
- private javax.swing.JTextField num1TextField;
- private javax.swing.JTextField num2TextField;
- private javax.swing.JTextField resultTextField;
- private javax.swing.JButton showButton;
- private javax.swing.JLabel showLabel;
- private javax.swing.JTextField showTextField;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment