27-10-2010, 10:56 PM
Ecco un semplice calcolatrice, creata con il linguaggio di programmazione: Java.
Source:
[spoiler][/spoiler]
Download .jar (eseguibile):
http://www.mediafire.com/?cuv9esirpivir5p
P.S: Non credete che io abbia scritto tutto quel codice, perché molto di quel codice lo ha generato automaticamente: NetBeans nel momento in cui ho creato l'interfaccia grafica con l'editor che ha NetBeans, che fa risparmiare tutto il codice dell'interfaccia e per l'impostazioni del font della scrittura e tutto il resto (Tipo Visual Basic.net per capirci)
Source:
[spoiler]
Codice PHP:
public class Calcolatrice extends javax.swing.JFrame {
double plusminus;
double primoDouble;
double secondoDouble;
double totaleDouble;
int addClick;
int sottClick;
int moltClick;
int divClick;
int puntoClick;
public Calcolatrice() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
testo = new javax.swing.JTextField();
n1 = new javax.swing.JButton();
n2 = new javax.swing.JButton();
n3 = new javax.swing.JButton();
n4 = new javax.swing.JButton();
n5 = new javax.swing.JButton();
n6 = new javax.swing.JButton();
n7 = new javax.swing.JButton();
n8 = new javax.swing.JButton();
n9 = new javax.swing.JButton();
add = new javax.swing.JButton();
sott = new javax.swing.JButton();
molt = new javax.swing.JButton();
div = new javax.swing.JButton();
uguale = new javax.swing.JButton();
canc = new javax.swing.JButton();
piuomeno = new javax.swing.JButton();
n0 = new javax.swing.JButton();
punto = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Calcolatrice");
setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
setResizable(false);
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
testo.setEditable(false);
testo.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n1.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n1.setText("1");
n1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n1ActionPerformed(evt);
}
});
n2.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n2.setText("2");
n2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n2ActionPerformed(evt);
}
});
n3.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n3.setText("3");
n3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n3ActionPerformed(evt);
}
});
n4.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n4.setText("4");
n4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n4ActionPerformed(evt);
}
});
n5.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n5.setText("5");
n5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n5ActionPerformed(evt);
}
});
n6.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n6.setText("6");
n6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n6ActionPerformed(evt);
}
});
n7.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n7.setText("7");
n7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n7ActionPerformed(evt);
}
});
n8.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n8.setText("8");
n8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n8ActionPerformed(evt);
}
});
n9.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n9.setText("9");
n9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n9ActionPerformed(evt);
}
});
add.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
add.setText("+");
add.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addActionPerformed(evt);
}
});
sott.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
sott.setText("-");
sott.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sottActionPerformed(evt);
}
});
molt.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
molt.setText("*");
molt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
moltActionPerformed(evt);
}
});
div.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
div.setText("/");
div.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
divActionPerformed(evt);
}
});
uguale.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
uguale.setText("=");
uguale.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ugualeActionPerformed(evt);
}
});
canc.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
canc.setText("C");
canc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancActionPerformed(evt);
}
});
piuomeno.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
piuomeno.setText("+/-");
piuomeno.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
piuomenoActionPerformed(evt);
}
});
n0.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
n0.setText("0");
n0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
n0ActionPerformed(evt);
}
});
punto.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
punto.setText(".");
punto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
puntoActionPerformed(evt);
}
});
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()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(testo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(n1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(n2, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(n3, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(n4, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(n5, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(n6, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(n0, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
.addComponent(n7, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(n8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(piuomeno, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(n9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
.addComponent(punto, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)))
.addComponent(uguale, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(add, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sott, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
.addComponent(molt, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
.addComponent(div, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
.addComponent(canc, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE))))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(testo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(n1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(n2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(n3, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(add, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(n4, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(n5, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(n6, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sott, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(molt, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(n7, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(n8, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(n9, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(div, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(punto, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(n0, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(piuomeno, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(uguale, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(canc, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void cancActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText("");
puntoClick=0;
}
private void n1ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n1.getText());
}
private void n2ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n2.getText());
}
private void n3ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n3.getText());
}
private void n4ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n4.getText());
}
private void n5ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n5.getText());
}
private void n6ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n6.getText());
}
private void n7ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n7.getText());
}
private void n8ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n8.getText());
}
private void n9ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n9.getText());
}
private void n0ActionPerformed(java.awt.event.ActionEvent evt) {
testo.setText(testo.getText()+n0.getText());
}
private void puntoActionPerformed(java.awt.event.ActionEvent evt) {
if(puntoClick==0){
testo.setText(testo.getText()+punto.getText());
puntoClick=1;
}
}
private void piuomenoActionPerformed(java.awt.event.ActionEvent evt) {
plusminus=(Double.parseDouble(String.valueOf(testo.getText())));
plusminus=plusminus*(-1);
testo.setText(String.valueOf(plusminus));
}
private void addActionPerformed(java.awt.event.ActionEvent evt) {
primoDouble=(Double.parseDouble(String.valueOf(testo.getText())));
testo.setText("");
addClick=1;
puntoClick=0;
}
private void sottActionPerformed(java.awt.event.ActionEvent evt) {
primoDouble=(Double.parseDouble(String.valueOf(testo.getText())));
testo.setText("");
sottClick=1;
puntoClick=0;
}
private void moltActionPerformed(java.awt.event.ActionEvent evt) {
primoDouble=(Double.parseDouble(String.valueOf(testo.getText())));
testo.setText("");
moltClick=1;
puntoClick=0;
}
private void divActionPerformed(java.awt.event.ActionEvent evt) {
primoDouble=(Double.parseDouble(String.valueOf(testo.getText())));
testo.setText("");
divClick=1;
puntoClick=0;
}
private void ugualeActionPerformed(java.awt.event.ActionEvent evt) {
secondoDouble=(Double.parseDouble(String.valueOf(testo.getText())));
if(addClick>0){
totaleDouble=primoDouble+secondoDouble;
testo.setText(String.valueOf(totaleDouble));
primoDouble=0;
secondoDouble=0;
addClick=0;
}
if(sottClick>0){
totaleDouble=primoDouble-secondoDouble;
testo.setText(String.valueOf(totaleDouble));
primoDouble=0;
secondoDouble=0;
sottClick=0;
}
if(moltClick>0){
totaleDouble=primoDouble*secondoDouble;
testo.setText(String.valueOf(totaleDouble));
primoDouble=0;
secondoDouble=0;
moltClick=0;
}
if(divClick>0){
totaleDouble=primoDouble/secondoDouble;
testo.setText(String.valueOf(totaleDouble));
primoDouble=0;
secondoDouble=0;
divClick=0;
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Calcolatrice().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton add;
private javax.swing.JButton canc;
private javax.swing.JButton div;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton molt;
private javax.swing.JButton n0;
private javax.swing.JButton n1;
private javax.swing.JButton n2;
private javax.swing.JButton n3;
private javax.swing.JButton n4;
private javax.swing.JButton n5;
private javax.swing.JButton n6;
private javax.swing.JButton n7;
private javax.swing.JButton n8;
private javax.swing.JButton n9;
private javax.swing.JButton piuomeno;
private javax.swing.JButton punto;
private javax.swing.JButton sott;
private javax.swing.JTextField testo;
private javax.swing.JButton uguale;
// End of variables declaration
}
Download .jar (eseguibile):
http://www.mediafire.com/?cuv9esirpivir5p
P.S: Non credete che io abbia scritto tutto quel codice, perché molto di quel codice lo ha generato automaticamente: NetBeans nel momento in cui ho creato l'interfaccia grafica con l'editor che ha NetBeans, che fa risparmiare tutto il codice dell'interfaccia e per l'impostazioni del font della scrittura e tutto il resto (Tipo Visual Basic.net per capirci)