calcframe.java
public class calcframe extends javax.swing.JFrame {
public calcframe() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
SecondText = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
FirstText = new javax.swing.JTextField();
AddButton = new javax.swing.JButton();
SubButton = new javax.swing.JButton();
DivButton = new javax.swing.JButton();
MulButton = new javax.swing.JButton();
ClearButton = new javax.swing.JButton();
Result = new javax.swing.JLabel();
ResultText = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 18));
jLabel1.setForeground(new java.awt.Color(0, 51, 255));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("CALCULATOR");
jLabel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 0), 1, true));
jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 14));
jLabel2.setForeground(new java.awt.Color(51, 102, 255));
jLabel2.setText("Enter Second number");
SecondText.setFont(new java.awt.Font("Times New Roman", 1, 14));
SecondText.setForeground(new java.awt.Color(0, 0, 255));
SecondText.setName("Second");
jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 14));
jLabel3.setForeground(new java.awt.Color(51, 102, 255));
jLabel3.setText("Enter First number");
FirstText.setFont(new java.awt.Font("Times New Roman", 1, 14));
FirstText.setForeground(new java.awt.Color(0, 0, 255));
FirstText.setName("First");
AddButton.setFont(new java.awt.Font("Times New Roman", 1, 18));
AddButton.setForeground(new java.awt.Color(255, 51, 51));
AddButton.setText("+");
AddButton.setToolTipText("Select + to perform ADD operation");
AddButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AddButtonActionPerformed(evt);
}
});
SubButton.setFont(new java.awt.Font("Times New Roman", 1, 18));
SubButton.setForeground(new java.awt.Color(255, 51, 51));
SubButton.setText("-");
SubButton.setToolTipText("Select - to perform SUBTRACT operation");
SubButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SubButtonActionPerformed(evt);
}
});
DivButton.setFont(new java.awt.Font("Times New Roman", 1, 18));
DivButton.setForeground(new java.awt.Color(255, 51, 51));
DivButton.setText("/");
DivButton.setToolTipText("Select / to perform DIVIDE operation");
DivButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DivButtonActionPerformed(evt);
}
});
MulButton.setFont(new java.awt.Font("Times New Roman", 1, 18));
MulButton.setForeground(new java.awt.Color(255, 51, 51));
MulButton.setText("*");
MulButton.setToolTipText("Select * to perform MULTIPLICATION operation");
MulButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MulButtonActionPerformed(evt);
}
});
ClearButton.setFont(new java.awt.Font("Times New Roman", 1, 12));
ClearButton.setForeground(new java.awt.Color(255, 51, 51));
ClearButton.setText("CLEAR");
ClearButton.setToolTipText("Select + to perform ADD operation");
ClearButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ClearButtonActionPerformed(evt);
}
});
Result.setFont(new java.awt.Font("Times New Roman", 1, 12));
Result.setForeground(new java.awt.Color(51, 51, 255));
Result.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(255, 51, 51)));
ResultText.setFont(new java.awt.Font("Times New Roman", 1, 14));
ResultText.setForeground(new java.awt.Color(0, 102, 255));
ResultText.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(255, 0, 0)));
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(94, 94, 94)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(38, 38, 38)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(AddButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(SubButton)
.addGap(18, 18, 18)
.addComponent(MulButton)
.addGap(14, 14, 14)
.addComponent(DivButton)
.addGap(18, 18, 18)
.addComponent(ClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(SecondText, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(Result, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ResultText, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(58, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(244, Short.MAX_VALUE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(197, Short.MAX_VALUE)
.addComponent(FirstText, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(66, 66, 66)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(62, 62, 62)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(SecondText, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(AddButton)
.addComponent(SubButton)
.addComponent(DivButton)
.addComponent(MulButton)
.addComponent(ClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Result, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(ResultText, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE))
.addGap(31, 31, 31))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(195, Short.MAX_VALUE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(FirstText, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(185, Short.MAX_VALUE)))
);
pack();
}
private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) { int a,b,c;
a=Integer.parseInt(FirstText.getText());
b=Integer.parseInt(SecondText.getText());
c=a+b;
Result.setText("Added Value ");
ResultText.setText(Integer.toString(c));
}
private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt) { Result.setText("");
FirstText.setText("");
SecondText.setText("");
ResultText.setText("");
}
private void SubButtonActionPerformed(java.awt.event.ActionEvent evt) { int a,b,c;
a=Integer.parseInt(FirstText.getText());
b=Integer.parseInt(SecondText.getText());
c=a-b;
Result.setText("Subtracted Value ");
ResultText.setText(Integer.toString(c));
}
private void MulButtonActionPerformed(java.awt.event.ActionEvent evt) { int a,b,c;
a=Integer.parseInt(FirstText.getText());
b=Integer.parseInt(SecondText.getText());
c=a*b;
Result.setText("Multiplied Value ");
ResultText.setText(Integer.toString(c));
}
private void DivButtonActionPerformed(java.awt.event.ActionEvent evt) {
int a,b,c;
a=Integer.parseInt(FirstText.getText());
b=Integer.parseInt(SecondText.getText());
c=a/b;
Result.setText("Divided Value ");
ResultText.setText(Integer.toString(c));
}
public static void main(String args[]) {
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(calcframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(calcframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(calcframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(calcframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new calcframe().setVisible(true);
}
});
}
private javax.swing.JButton AddButton;
private javax.swing.JButton ClearButton;
private javax.swing.JButton DivButton;
private javax.swing.JTextField FirstText;
private javax.swing.JButton MulButton;
private javax.swing.JLabel Result;
private javax.swing.JTextField ResultText;
private javax.swing.JTextField SecondText;
private javax.swing.JButton SubButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
}
OUTPUT:
No comments:
Post a Comment