tugas 9 : resy rahma kurnia marhani / 2012420149

tugas 9 : resy rahma kurnia marhani / 2012420149








/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication18;

import javax.swing.ButtonGroup;

/**
 *
 * @author User
 */
public class VVVV extends javax.swing.JFrame {
/** Creates new form kkkalkulator */
public VVVV() {
initComponents();
ButtonGroup group = new ButtonGroup();
group.add(jRadioButton1);
group.add(jRadioButton2);
group.add(jRadioButton3);
group.add(jRadioButton4);
jRadioButton4.setSelected(true);
operator_mati(true);
huruf_mati(false);
angka_mati(true, true,true,true,true,true,true,true,true,true);
}
/** 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.
*/
void huruf_mati(boolean a){
jButton18.setEnabled(a);
jButton19.setEnabled(a);
jButton20.setEnabled(a);
jButton23.setEnabled(a);
jButton24.setEnabled(a);
jButton25.setEnabled(a);
jButton26.setEnabled(a);
}
void operator_mati(boolean a){
jButton4.setEnabled(a);
jButton8.setEnabled(a);
jButton13.setEnabled(a);
jButton15.setEnabled(a);
jButton12.setEnabled(a);
jButton27.setEnabled(a);
}
void angka_mati(boolean a,boolean b,boolean c,boolean d,boolean e,boolean f,boolean g,boolean h,boolean i,boolean j){
jButton14.setEnabled(a);
jButton1.setEnabled(b);
jButton2.setEnabled(c);
jButton3.setEnabled(d);
jButton5.setEnabled(e);
jButton6.setEnabled(f);
jButton7.setEnabled(g);
jButton9.setEnabled(h);
jButton10.setEnabled(i);
jButton11.setEnabled(j);
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox();
jPanel1 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jButton18 = new javax.swing.JButton();
jButton19 = new javax.swing.JButton();
jButton20 = new javax.swing.JButton();
jButton23 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton24 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton25 = new javax.swing.JButton();
jButton13 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
jButton26 = new javax.swing.JButton();
jButton15 = new javax.swing.JButton();
jButton21 = new javax.swing.JButton();
jButton14 = new javax.swing.JButton();
jButton22 = new javax.swing.JButton();
jButton12 = new javax.swing.JButton();
jButton27 = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton3 = new javax.swing.JRadioButton();
jRadioButton4 = new javax.swing.JRadioButton();
jButton16 = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jButton17 = new javax.swing.JButton();
monitor = new javax.swing.JTextField();
jTextField1.setText("jTextField1");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("KALKULATOR");
setResizable(false);
getContentPane().setLayout(new java.awt.GridLayout());
jPanel1.setBackground(new java.awt.Color(51, 153, 0));
jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
jPanel7.setOpaque(false);
jPanel2.setBackground(new java.awt.Color(255, 153, 255));
jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
jPanel2.setOpaque(false);
jPanel2.setLayout(new java.awt.GridLayout(5, 5, 10, 10));
jButton18.setText("A");
jPanel2.add(jButton18);
jButton19.setText("B");
jButton19.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton19ActionPerformed(evt);
}
});
jPanel2.add(jButton19);
jButton20.setText("C");
jPanel2.add(jButton20);
jButton23.setText("D");
jPanel2.add(jButton23);
jButton4.setText("*");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});
jPanel2.add(jButton4);
jButton1.setText("1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton1);
jButton2.setText("2");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton2);
jButton3.setText("3");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton3);
jButton24.setText("E");
jPanel2.add(jButton24);
jButton8.setText("/");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});
jPanel2.add(jButton8);
jButton5.setText("4");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton5);
jButton6.setText("5");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton6);
jButton7.setText("6");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton7);
jButton25.setText("F");
jPanel2.add(jButton25);
jButton13.setText("+");
jButton13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});
jPanel2.add(jButton13);
jButton9.setText("7");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton9);
jButton10.setText("8");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton10);
jButton11.setText("9");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton11);
jButton26.setText("G");
jPanel2.add(jButton26);
jButton15.setText("-");
jButton15.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});
jPanel2.add(jButton15);
jButton21.setBorderPainted(false);
jButton21.setContentAreaFilled(false);
jButton21.setOpaque(false);
jPanel2.add(jButton21);
jButton14.setText("0");
jButton14.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton14);
jButton22.setBorderPainted(false);
jButton22.setContentAreaFilled(false);
jPanel2.add(jButton22);
jButton12.setText(".");
jButton12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton12ActionPerformed(evt);
}
});
jPanel2.add(jButton12);
jButton27.setText("%");
jPanel2.add(jButton27);
jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jPanel3.setOpaque(false);
jPanel3.setLayout(new java.awt.GridLayout(4, 1));
jRadioButton1.setBackground(new java.awt.Color(255, 153, 204));
jRadioButton1.setText("bin");
jRadioButton1.setOpaque(false);
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
jPanel3.add(jRadioButton1);
jRadioButton2.setBackground(new java.awt.Color(255, 153, 204));
jRadioButton2.setText("hexa");
jRadioButton2.setOpaque(false);
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
jPanel3.add(jRadioButton2);
jRadioButton3.setBackground(new java.awt.Color(255, 153, 204));
jRadioButton3.setText("okt");
jRadioButton3.setOpaque(false);
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton3ActionPerformed(evt);
}
});
jPanel3.add(jRadioButton3);
jRadioButton4.setBackground(new java.awt.Color(255, 153, 204));
jRadioButton4.setText("des");
jRadioButton4.setOpaque(false);
jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton4ActionPerformed(evt);
}
});
jPanel3.add(jRadioButton4);
jButton16.setBackground(new java.awt.Color(124, 68, 205));
jButton16.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jButton16.setText("=");
jButton16.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton16ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE))
.addContainerGap())
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
.addContainerGap())
);
jPanel4.setOpaque(false);
jButton17.setBackground(new java.awt.Color(124, 238, 182));
jButton17.setText("clear");
jButton17.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton17ActionPerformed(evt);
}
});
monitor.setEditable(false);
monitor.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(jButton17)
.addContainerGap(308, Short.MAX_VALUE))
.addComponent(monitor, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addComponent(monitor, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton17))
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(10, 10, 10))
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
getContentPane().add(jPanel1);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-409)/2, (screenSize.height-352)/2, 409, 352);
}// </editor-fold>
String angka3="",b,c;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

angka3 +=evt.getActionCommand();
monitor.setText(angka3) ;
}
String operator;
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {

operator=evt.getActionCommand();
if(a==false)
b=angka3;
else
b=b;
angka3="";
}
boolean a=false;
private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {
try{
String angka2=monitor.getText();
if(operator.equalsIgnoreCase("+")){
b=""+(Double.parseDouble(b)+Double.parseDouble(angka2));
monitor.setText(b);

a=true;
} else if(operator.equalsIgnoreCase("*")){
b=""+(Double.parseDouble(b)*Double.parseDouble(angka2));
monitor.setText(""+(b));

a=true;
} else if(operator.equalsIgnoreCase("-")){
b=""+(Double.parseDouble(b)-Double.parseDouble(angka2));
monitor.setText(""+(b));

a=true;
}else if(operator.equalsIgnoreCase("/")){
b=""+(Double.parseDouble(b)/Double.parseDouble(angka2));
monitor.setText(""+(b));
a=true;
}
}catch(NumberFormatException ab){
monitor.setText("error");
}

}
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String a=monitor.getText();
int b=a.indexOf(".");
if(b<0){

angka3 +=".";
monitor.setText(angka3);
}
}
private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka3="";
b="";
monitor.setText("");
a=false;
}
String op="des",op1="";
public void biokhex(){
try{
String mon=monitor.getText();
if(op.equalsIgnoreCase("bin")&& op1.equalsIgnoreCase("des")){
monitor.setText(""+Integer.parseInt(mon,2));
op="des";
}else if(op.equalsIgnoreCase("bin")&& op1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(mon,2);
monitor.setText(""+Integer.toOctalString(a));
op="okt";
}else if(op.equalsIgnoreCase("bin")&& op1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(mon,2);
monitor.setText(""+Integer.toHexString(a));
op="hex";
}else if(op.equalsIgnoreCase("okt")&& op1.equalsIgnoreCase("des")){
int a=Integer.parseInt(mon,8);
monitor.setText(""+a);
op="des";
}else if(op.equalsIgnoreCase("okt")&& op1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(mon,8);
monitor.setText(""+Integer.toBinaryString(a));
op="bin";
}else if(op.equalsIgnoreCase("okt")&& op1.equalsIgnoreCase("hex")){
int a=Integer.parseInt(mon,8);
monitor.setText(""+Integer.toHexString(a));
op="hex";
}else if(op.equalsIgnoreCase("hex")&& op1.equalsIgnoreCase("des")){
int a=Integer.parseInt(mon,16);
monitor.setText(""+a);
op="des";
}else if(op.equalsIgnoreCase("hex")&& op1.equalsIgnoreCase("bin")){
int a=Integer.parseInt(mon,16);
monitor.setText(""+Integer.toBinaryString(a));
op="bin";
}else if(op.equalsIgnoreCase("hex")&& op1.equalsIgnoreCase("okt")){
int a=Integer.parseInt(mon,16);
monitor.setText(""+Integer.toOctalString(a));
op="okt";
}else if(op.equalsIgnoreCase("des")&& op1.equalsIgnoreCase("bin")){
monitor.setText(""+Integer.toBinaryString(Integer.parseInt(mon)));
op="bin";
}else if(op.equalsIgnoreCase("des")&& op1.equalsIgnoreCase("okt")){
monitor.setText(""+Integer.toOctalString(Integer.parseInt(mon)));
op="okt";
}else if(op.equalsIgnoreCase("des")&& op1.equalsIgnoreCase("hex")){
monitor.setText(""+Integer.toHexString(Integer.parseInt(mon)));
op="hex";
}
}catch(NumberFormatException ab){
monitor.setText("error");
}
}

private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {
op1="des";
biokhex();
operator_mati(true);
huruf_mati(false);
angka_mati(true, true,true,true,true,true,true,true,true,true);
// TODO add your handling code here:
}
private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
op1="okt";
biokhex();
operator_mati(false);
huruf_mati(false);
angka_mati(true, true,true,true,true,true,true,true,false,false);
// TODO add your handling code here:
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
op1="hex";
biokhex();
operator_mati(false);
huruf_mati(true);
angka_mati(true, true,true,true,true,true,true,true,true,true);
// TODO add your handling code here:
}
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
op1="bin";
biokhex();
operator_mati(false);
huruf_mati(false);
angka_mati(true, true,false,false,false,false,false,false,false,false);
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new VVVV().setVisible(true);
}
});
}
// 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 jButton17;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton19;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton20;
private javax.swing.JButton jButton21;
private javax.swing.JButton jButton22;
private javax.swing.JButton jButton23;
private javax.swing.JButton jButton24;
private javax.swing.JButton jButton25;
private javax.swing.JButton jButton26;
private javax.swing.JButton jButton27;
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.JComboBox jComboBox1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel7;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JRadioButton jRadioButton4;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField monitor;
// End of variables declaration
}
 




   
   



share this article to: Facebook Twitter Google+ Linkedin Technorati Digg
Posted by arek informatika, Published at 00.21 and have 0 komentar

Tidak ada komentar:

Posting Komentar