PROGRAM FOR CALCULATORJavaSwing1.java:::
package javaswing1;
import java.awt.Color;
public class JavaSwing1
{
public static void main(String[] args)
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new NewJFrame().setVisible(true);
}
});
}
}
CALC.JAVA::::
package javaswing1;
public class Calc extends javax.swing.JFrame
{
private String str="";
private long num=0;
long r=0,num1=0,num2=0;
public Calc()
{
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents()
{
jLabel1 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton12 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton13 = new javax.swing.JButton();
jButton15 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jButton16 = new javax.swing.JButton();
jButton14 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setPreferredSize(new java.awt.Dimension(320, 250));
jLabel1.setPreferredSize(new java.awt.Dimension(200, 50));
jPanel3.setLayout(new java.awt.GridLayout(4, 4));
jButton1.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton1.setText("1");
jButton1.setPreferredSize(new java.awt.Dimension(50, 50));
jButton1.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton1ActionPerformed(evt);
}
});
jPanel3.add(jButton1);
jButton2.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton2.setText("2");
jButton2.setPreferredSize(new java.awt.Dimension(50, 50));
jButton2.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton2ActionPerformed(evt);
}
});
jPanel3.add(jButton2);
jButton3.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton3.setText("3");
jButton3.setPreferredSize(new java.awt.Dimension(50, 50));
jButton3.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton3.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton3ActionPerformed(evt);
}
});
jPanel3.add(jButton3);
jButton11.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton11.setText("+");
jButton11.setPreferredSize(new java.awt.Dimension(50, 50));
jButton11.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton11.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton11ActionPerformed(evt);
}
});
jPanel3.add(jButton11);
jButton4.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton4.setText("4");
jButton4.setPreferredSize(new java.awt.Dimension(50, 50));
jButton4.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton4.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton4ActionPerformed(evt);
}
});
jPanel3.add(jButton4);
jButton5.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton5.setText("5");
jButton5.setPreferredSize(new java.awt.Dimension(50, 50));
jButton5.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton5.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton5ActionPerformed(evt);
}
});
jPanel3.add(jButton5);
jButton6.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton6.setText("6");
jButton6.setPreferredSize(new java.awt.Dimension(50, 50));
jButton6.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton6.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton6ActionPerformed(evt);
}
});
jPanel3.add(jButton6);
jButton12.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton12.setText("-");
jButton12.setPreferredSize(new java.awt.Dimension(50, 50));
jButton12.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton12.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton12ActionPerformed(evt);
}
});
jPanel3.add(jButton12);
jButton7.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton7.setText("7");
jButton7.setPreferredSize(new java.awt.Dimension(50, 50));
jButton7.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton7.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton7ActionPerformed(evt);
}
});
jPanel3.add(jButton7);
jButton8.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton8.setText("8");
jButton8.setPreferredSize(new java.awt.Dimension(50, 50));
jButton8.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton8.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton8ActionPerformed(evt);
}
});
jPanel3.add(jButton8);
jButton9.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton9.setText("9");
jButton9.setPreferredSize(new java.awt.Dimension(50, 50));
jButton9.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton9.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton9ActionPerformed(evt);
}
});
jPanel3.add(jButton9);
jButton13.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton13.setText("*");
jButton13.setPreferredSize(new java.awt.Dimension(50, 50));
jButton13.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton13.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton13ActionPerformed(evt);
}
});
jPanel3.add(jButton13);
jButton15.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton15.setText("=");
jButton15.setPreferredSize(new java.awt.Dimension(50, 50));
jButton15.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton15.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton15ActionPerformed(evt);
}
});
jPanel3.add(jButton15);
jButton10.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton10.setText("0");
jButton10.setPreferredSize(new java.awt.Dimension(50, 50));
jButton10.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton10.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton10ActionPerformed(evt);
}
});
jPanel3.add(jButton10);
jButton16.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton16.setText("C");
jButton16.setPreferredSize(new java.awt.Dimension(50, 50));
jButton16.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton16.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton16ActionPerformed(evt);
}
});
jPanel3.add(jButton16);
jButton14.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
jButton14.setText("/");
jButton14.setPreferredSize(new java.awt.Dimension(50, 50));
jButton14.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/javaswing1/anu.jpg"))); // NOI18N
jButton14.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton14ActionPerformed(evt);
}
});
jPanel3.add(jButton14);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
.addComponent(jLabel1, 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(jLabel1, 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.DEFAULT_SIZE, 244, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt)
{
str="-";
jLabel1.setText("-");
num1=num;
num=0;
}
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt)
{
str="*";
jLabel1.setText("*");
num1=num;
num=0;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+1;
jLabel1.setText(String.valueOf(num));
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+2;
jLabel1.setText(String.valueOf(num));
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+6;
jLabel1.setText(String.valueOf(num));
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+7;
jLabel1.setText(String.valueOf(num));
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+8;
jLabel1.setText(String.valueOf(num));
}
private void jButton15ActionPerformed(java.awt.event.ActionEvent evt)
{
num2=Integer.parseInt(jLabel1.getText());
if(str.equals("+"))
{
r=num1+num2;
}
if(str.equals("-"))
{
r=num1-num2;
}
if(str.equals("*"))
{
r=num1*num2;
}
if(str.equals("/"))
{
r=num1/num2;
}
jLabel1.setText(String.valueOf(r));
num=r;
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+0;
jLabel1.setText(String.valueOf(num));
}
private void jButton16ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num1=num2=0;
jLabel1.setText("");
// TODO add your handling code here:
}
private void jButton14ActionPerformed(java.awt.event.ActionEvent evt)
{
str="/";
jLabel1.setText("/");
num1=num;
num=0;
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+3;
jLabel1.setText(String.valueOf(num)); }
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+4;
jLabel1.setText(String.valueOf(num));
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+5;
jLabel1.setText(String.valueOf(num));
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt)
{
num=num*10+9;
jLabel1.setText(String.valueOf(num)); }
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt)
{
str="+";
jLabel1.setText("+");
num1=num;
num=0;
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton14;
private javax.swing.JButton jButton15;
private javax.swing.JButton jButton16;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel3;
// End of variables declaration
}
NewJFrame.java:::
package javaswing1;
import java.awt.*;
import javax.swing.*;
public class NewJFrame extends javax.swing.JFrame
{
private String pass;
String a="";
public NewJFrame()
{
initComponents();
showP();
Container c=getContentPane();
}
private void showP()
{
setBounds(100,100,400,400);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents()
{
jPasswordField1 = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("ANU CALCULATOR");
setPreferredSize(new java.awt.Dimension(300, 300));
jPasswordField1.setAlignmentX(1.0F);
jPasswordField1.setAlignmentY(1.0F);
jButton1.setText("OK");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton1ActionPerformed(evt);
}
});
jButton2.setText("CLEAR");
jButton2.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton2ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jLabel1.setText("ENTER PASSWORD");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(43, 43, 43)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(35, 35, 35)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(16, 16, 16))
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addComponent(jPasswordField1))
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(36, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton1))
.addContainerGap(78, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
pass=String.valueOf(jPasswordField1.getPassword());
if (pass.equals("anubhav") )
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new Calc().setVisible(true);
dispose();
}
});
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
jPasswordField1.setText("");
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JPasswordField jPasswordField1;
// End of variables declaration
}
save that fila eith specific names...then open properties of project in netbeans and select compress jar file option ....than using JSMOOTH APP to change jar file into exe file...than using INNO SETUP COMPILER TO CONVERT exe file into installable windows file......
for any queries contact CHAUHANANUBHAV16@GMAIL.COM
No comments:
Post a Comment