berikut adalah contoh codingan KALKULATOR dgn menggunakan Jframeform......
package tugas5algo2;
import javax.swing.JFrame;
/**
*
* @author somad
*/
public class kalkulator extends javax.swing.JFrame {
double jumlah,total,bil1;
//operator, hasil, bil1;
/**
* Creates new form kalkulator
*/
public kalkulator() {
initComponents();
setTitle("K A L K U L A T O R ");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
String perhitungan="des",perhitungan1="";
public void kalk(){
try{
String coy = hasil.getText();
if(perhitungan.equalsIgnoreCase("bin")&& perhitungan1.equalsIgnoreCase("des")){
hasil.setText(""+Integer.parseInt(coy,2));
perhitungan="des";
}
else if(perhitungan.equalsIgnoreCase("bin")&& perhitungan1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(coy,2);
hasil.setText(""+Integer.toOctalString(a));
perhitungan="okt";
}
else if(perhitungan.equalsIgnoreCase("bin")&& perhitungan1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(coy,2);
hasil.setText(""+Integer.toHexString(a));
perhitungan="hex";
}
else if(perhitungan.equalsIgnoreCase("okt")&& perhitungan1.equalsIgnoreCase("des")){
int a=Integer.parseInt(coy,8);
hasil.setText(""+a);
perhitungan="des";
}
else if(perhitungan.equalsIgnoreCase("okt")&& perhitungan1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(coy,8);
hasil.setText(""+Integer.toBinaryString(a));
perhitungan="bin";
}
else if(perhitungan.equalsIgnoreCase("okt")&& perhitungan1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(coy,8);
hasil.setText(""+Integer.toHexString(a));
perhitungan="hex";
}
else if(perhitungan.equalsIgnoreCase("hex")&& perhitungan1.equalsIgnoreCase("des")){
int a=Integer.parseInt(coy,16);
hasil.setText(""+a);
perhitungan="des";
}
else if(perhitungan.equalsIgnoreCase("hex")&& perhitungan1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(coy,16);
hasil.setText(""+Integer.toBinaryString(a));
perhitungan="bin";
}
else if(perhitungan.equalsIgnoreCase("hex")&& perhitungan1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(coy,16);
hasil.setText(""+Integer.toOctalString(a));
perhitungan="okt";
}
else if(perhitungan.equalsIgnoreCase("des")&& perhitungan1.equalsIgnoreCase("bin")){
hasil.setText(""+Integer.toBinaryString(Integer.parseInt(coy)));
perhitungan="bin";
}
else if(perhitungan.equalsIgnoreCase("des")&& perhitungan1.equalsIgnoreCase("okt")){
hasil.setText(""+Integer.toOctalString(Integer.parseInt(coy)));
perhitungan="okt";
}
else if(perhitungan.equalsIgnoreCase("des")&& perhitungan1.equalsIgnoreCase("hex")){
hasil.setText(""+Integer.toHexString(Integer.parseInt(coy)));
perhitungan="hex";
}
}catch(NumberFormatException ab){
hasil.setText("error");
}
}
/**
* 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();
jRadioButton7 = new javax.swing.JRadioButton();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
hasil = new javax.swing.JTextField();
jPanel4 = new javax.swing.JPanel();
jRadioButton3 = new javax.swing.JRadioButton();
jRadioButton4 = new javax.swing.JRadioButton();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jPanel3 = new javax.swing.JPanel();
no3 = new javax.swing.JButton();
koma = new javax.swing.JButton();
no9 = new javax.swing.JButton();
no6 = new javax.swing.JButton();
no7 = new javax.swing.JButton();
no00 = new javax.swing.JButton();
no8 = new javax.swing.JButton();
no0 = new javax.swing.JButton();
no1 = new javax.swing.JButton();
no4 = new javax.swing.JButton();
no2 = new javax.swing.JButton();
no5 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jButton13 = new javax.swing.JButton();
jButton14 = new javax.swing.JButton();
jButton15 = new javax.swing.JButton();
jButton16 = new javax.swing.JButton();
jButton17 = new javax.swing.JButton();
jButton18 = new javax.swing.JButton();
sama_dengan = new javax.swing.JButton();
jButton19 = new javax.swing.JButton();
jPanel5 = new javax.swing.JPanel();
A = new javax.swing.JButton();
B = new javax.swing.JButton();
C = new javax.swing.JButton();
D = new javax.swing.JButton();
E = new javax.swing.JButton();
F = new javax.swing.JButton();
jRadioButton7.setText("jRadioButton7");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setBackground(new java.awt.Color(204, 255, 204));
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("\"CALCULATOR\"");
jPanel4.setBackground(new java.awt.Color(153, 153, 153));
buttonGroup1.add(jRadioButton3);
jRadioButton3.setText("hexa");
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton3ActionPerformed(evt);
}
});
buttonGroup1.add(jRadioButton4);
jRadioButton4.setText("oct");
jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton4ActionPerformed(evt);
}
});
buttonGroup1.add(jRadioButton1);
jRadioButton1.setText("bin");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
buttonGroup1.add(jRadioButton2);
jRadioButton2.setText("des");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton4)
.addComponent(jRadioButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton3)
.addComponent(jRadioButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jRadioButton1)
.addComponent(jRadioButton3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jRadioButton4)
.addComponent(jRadioButton2))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3.setBackground(new java.awt.Color(153, 153, 153));
no3.setText("3");
no3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no3ActionPerformed(evt);
}
});
koma.setText(".");
koma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
komaActionPerformed(evt);
}
});
no9.setText("9");
no9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no9ActionPerformed(evt);
}
});
no6.setText("6");
no6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no6ActionPerformed(evt);
}
});
no7.setText("7");
no7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no7ActionPerformed(evt);
}
});
no00.setText("00");
no00.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no00ActionPerformed(evt);
}
});
no8.setText("8");
no8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no8ActionPerformed(evt);
}
});
no0.setText("0");
no0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no0ActionPerformed(evt);
}
});
no1.setText("1");
no1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no1ActionPerformed(evt);
}
});
no4.setText("4");
no4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no4ActionPerformed(evt);
}
});
no2.setText("2");
no2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no2ActionPerformed(evt);
}
});
no5.setText("5");
no5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no5ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(no4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no0, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no7, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(no8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no00, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no5, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(no9, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(no3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(koma, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(no6, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap(23, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(no7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(no8, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(no6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(no5, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no4, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(no1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no3, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(koma, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no00, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(no0, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel2.setBackground(new java.awt.Color(153, 153, 153));
jButton13.setText("CE");
jButton13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});
jButton14.setText("%");
jButton14.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton14ActionPerformed(evt);
}
});
jButton15.setText("+");
jButton15.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton15ActionPerformed(evt);
}
});
jButton16.setText("/");
jButton16.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton16ActionPerformed(evt);
}
});
jButton17.setText("-");
jButton17.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton17ActionPerformed(evt);
}
});
jButton18.setText("X");
jButton18.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton18ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton16, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton17, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(76, 76, 76))
);
sama_dengan.setText("=");
sama_dengan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sama_denganActionPerformed(evt);
}
});
jButton19.setText("mod");
jButton19.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton19ActionPerformed(evt);
}
});
A.setText("A");
B.setText("B");
C.setText("C");
D.setText("D");
E.setText("E");
F.setText("F");
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addComponent(A)
.addGap(34, 34, 34)
.addComponent(B)
.addGap(30, 30, 30)
.addComponent(C)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(D)
.addGap(33, 33, 33)
.addComponent(E)
.addGap(27, 27, 27)
.addComponent(F)
.addContainerGap())
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(A)
.addComponent(B)
.addComponent(C)
.addComponent(D)
.addComponent(E)
.addComponent(F))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(97, 97, 97)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(hasil)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel4, 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.LEADING, false)
.addComponent(jButton19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(sama_dengan, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap(22, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(hasil, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton19, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sama_dengan, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(44, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(19, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(26, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void no7ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+7); // TODO add your handling code here:
}
private void no4ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+4); // TODO add your handling code here:
}
private void no1ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+1);
}
private void no0ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+0);
}
private void no8ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+8); // TODO add your handling code here:
}
private void no5ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+5); // TODO add your handling code here:
}
private void no2ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+2);
}
private void no00ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+"00");
}
private void no9ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+9); // TODO add your handling code here:
}
private void no6ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+6); // TODO add your handling code here:
}
private void no3ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+3); // TODO add your handling code here:
}
private void komaActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText(hasil.getText()+"'");
}
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
hasil.setText("0");
hasil.setText("");// TODO add your handling code here:
}
private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {
total = Double.parseDouble(hasil.getText())/100;
hasil.setText(String.valueOf(total));
// TODO add your handling code here:
}
private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {
jumlah = 1;
bil1 = Double.parseDouble(hasil.getText());
hasil.setText(""); // TODO add your handling code here:
}
private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {
jumlah = 4;
bil1 = Double.parseDouble(hasil.getText());
hasil.setText("");// TODO add your handling code here:
}
private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
jumlah = 2;
bil1 = Double.parseDouble(hasil.getText());
hasil.setText(""); // TODO add your handling code here:
}
private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
jumlah = 3;
bil1 = Double.parseDouble(hasil.getText());
hasil.setText("");// TODO add your handling code here:
}
private void sama_denganActionPerformed(java.awt.event.ActionEvent evt) {
if(jumlah==1){
total = bil1+Double.parseDouble(hasil.getText());
hasil.setText((String.valueOf(total)));
}else if(jumlah==2){
total = bil1-Double.parseDouble(hasil.getText());
hasil.setText((String.valueOf(total)));
}else if(jumlah==3){
total = bil1*Double.parseDouble(hasil.getText());
hasil.setText((String.valueOf(total)));
}else if(jumlah==4){
total = bil1/Double.parseDouble(hasil.getText());
hasil.setText((String.valueOf(total)));
}else if(jumlah==5){
total = bil1%Double.parseDouble(hasil.getText());
hasil.setText((String.valueOf(total)));
}else if(jumlah==6){
if(total<0){
hasil.setText("Syntax Error");
}else{
total = Math.pow(bil1, Double.parseDouble(hasil.getText()));
hasil.setText(String.valueOf(total)); } // TODO add your handling code here:
}
}
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
perhitungan1="bin";
kalk();
no00.setEnabled(false);
no2.setEnabled(false);
no3.setEnabled(false);
no4.setEnabled(false);
no5.setEnabled(false);
no6.setEnabled(false);
no7.setEnabled(false);
no8.setEnabled(false);
no9.setEnabled(false);
koma.setEnabled(false);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
// TODO add your handling code here:
}
private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {
perhitungan1="okt";
kalk();
no8.setEnabled(false);
no9.setEnabled(false);
koma.setEnabled(false);
no2.setEnabled(true);
no3.setEnabled(true);
no4.setEnabled(true);
no5.setEnabled(true);
no6.setEnabled(true);
no7.setEnabled(true);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
// TODO add your handling code here:
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
perhitungan1="des";
kalk();
no1.setEnabled(true);
no2.setEnabled(true);
no3.setEnabled(true);
no4.setEnabled(true);
no5.setEnabled(true);
no6.setEnabled(true);
no7.setEnabled(true);
no8.setEnabled(true);
no9.setEnabled(true);
no0.setEnabled(true);
koma.setEnabled(true);
A.setEnabled(false);
B.setEnabled(false);
C.setEnabled(false);
D.setEnabled(false);
E.setEnabled(false);
F.setEnabled(false);
// TODO add your handling code here:
}
private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
perhitungan1="hex";
kalk();
no1.setEnabled(true);
no2.setEnabled(true);
no3.setEnabled(true);
no4.setEnabled(true);
no5.setEnabled(true);
no6.setEnabled(true);
no7.setEnabled(true);
no8.setEnabled(true);
no9.setEnabled(true);
no0.setEnabled(true);
koma.setEnabled(true);
A.setEnabled(true);
B.setEnabled(true);
C.setEnabled(true);
D.setEnabled(true);
E.setEnabled(true);
F.setEnabled(true);
// TODO add your handling code here:
}
private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {
jumlah = 5;
bil1 = Double.parseDouble(hasil.getText());
hasil.setText(""); // TODO add your handling code here:
}
/**
* @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(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new kalkulator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton A;
private javax.swing.JButton B;
private javax.swing.JButton C;
private javax.swing.JButton D;
private javax.swing.JButton E;
private javax.swing.JButton F;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JTextField hasil;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton14;
private javax.swing.JButton jButton15;
private javax.swing.JButton jButton16;
private javax.swing.JButton jButton17;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton19;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JRadioButton jRadioButton4;
private javax.swing.JRadioButton jRadioButton7;
private javax.swing.JButton koma;
private javax.swing.JButton no0;
private javax.swing.JButton no00;
private javax.swing.JButton no1;
private javax.swing.JButton no2;
private javax.swing.JButton no3;
private javax.swing.JButton no4;
private javax.swing.JButton no5;
private javax.swing.JButton no6;
private javax.swing.JButton no7;
private javax.swing.JButton no8;
private javax.swing.JButton no9;
private javax.swing.JButton sama_dengan;
// End of variables declaration
}
saya sertakan pula bentuk kalkulatornya:
Posted by 23.14 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar