hay para Bomber`s sudah lama saya tidak update blog ini . karena kesibukan saya kuliah dan kerja hehehe :D . kali ini saya akan membahas sedikit Tentang tugas dari tempat saya kulauh . Tentang Pembuatan APlikasi java Iframe . di sini saya akan membuat aplikasi Penjualan Paket Komputer Dengan fasilitas Kupon discon. saya tidak akan panjang lebar menjelasakan Scrip dan funginya karena keterbataan waktu . tapi kalo ada yang ingin bertanya Bisa langsung ke Twitter saya di @olidfire .
1 Pertama buat Desain Iframe seperti ini .
- Berikut code atau scripnya
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author BomberCom
*/
public class daftarPaket extends javax.swing.JFrame {
/**
* Creates new form daftarPaket
*/
public daftarPaket() {
initComponents();
}
/**
* 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")
//
private void initComponents() {
grup = new javax.swing.ButtonGroup();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
po = new javax.swing.JRadioButton();
grup.add(po);
of = new javax.swing.JRadioButton();
grup.add(of);
ga = new javax.swing.JRadioButton();
grup.add(ga);
de = new javax.swing.JRadioButton();
grup.add(de);
ed = new javax.swing.JRadioButton();
grup.add(ed);
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
pr = new javax.swing.JTextField();
mo = new javax.swing.JTextField();
me = new javax.swing.JTextField();
hd = new javax.swing.JTextField();
ve = new javax.swing.JTextField();
mr = new javax.swing.JTextField();
km = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
hg = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
D = new javax.swing.JTextField();
jLabel11 = new javax.swing.JLabel();
T = new javax.swing.JTextField();
dis = new javax.swing.JTextField();
jLabel12 = new javax.swing.JLabel();
dl = new javax.swing.JButton();
st = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jButton2.setText("jButton2");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Virtual DJ", 1, 14)); // NOI18N
jLabel1.setText("DAFTAR PAKET KOMPUTER");
po.setText("Personal");
po.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
poActionPerformed(evt);
}
});
of.setText("Office");
of.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ofActionPerformed(evt);
}
});
ga.setText("Gameing");
ga.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
gaActionPerformed(evt);
}
});
de.setText("Desain");
de.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deActionPerformed(evt);
}
});
ed.setText("Editor Music / Video");
ed.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
edActionPerformed(evt);
}
});
jButton1.setText("CEK");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel2.setText("Prosessor");
jLabel3.setText("Motherboard");
jLabel4.setText("Memory");
jLabel5.setText("Harddisk");
jLabel6.setText("VGA");
jLabel7.setText("Monitor");
jLabel8.setText("Keyboard & Mouse");
mo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
moActionPerformed(evt);
}
});
jLabel9.setText("HARGA");
jLabel10.setText("KUPON DISCON");
jLabel11.setText("TOTAL");
jLabel12.setText("%");
dl.setText("DEAL");
dl.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dlActionPerformed(evt);
}
});
st.setText("status");
jMenu1.setText("File");
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(de)
.addComponent(po)
.addComponent(of)
.addComponent(ga)
.addComponent(ed)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel8)
.addComponent(jLabel9)
.addComponent(jLabel10)
.addComponent(jLabel11))
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(mo)
.addComponent(me)
.addComponent(hd)
.addComponent(ve)
.addComponent(mr)
.addComponent(km)
.addComponent(pr)
.addComponent(hg)
.addComponent(D)
.addComponent(T, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(st, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(dis, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.addGap(68, 68, 68))
.addComponent(dl, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(jLabel1)))
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(3, 3, 3)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(po)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(of)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ga)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(de)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ed)
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(pr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(mo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(me, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(hd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(ve, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(mr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(km, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(hg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(D, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(dis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12)
.addComponent(st)
.addComponent(jButton1))
.addGap(2, 2, 2)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(T, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(dl, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE))
);
pack();
}//
/**
*
* Awal Scrip
*/
private void poActionPerformed(java.awt.event.ActionEvent evt) {
if (po.isSelected());
pr.setText("Pentium IV");
mo.setText("Asus G31");
me.setText("Kingston 2gb");
hd.setText("80 GB");
ve.setText("---");
mr.setText("LCD 14inch ");
km.setText("include");
hg.setText("1500000");
}
private void moActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ofActionPerformed(java.awt.event.ActionEvent evt) {
if (of.isSelected());
pr.setText("Pentium IV");
mo.setText("Asus G31");
me.setText("Kingston 2gb");
hd.setText("120 GB");
ve.setText("---");
mr.setText("LCD 14inch ");
km.setText("include");
hg.setText("1550000");
}
private void gaActionPerformed(java.awt.event.ActionEvent evt) {
if (of.isSelected());
pr.setText("intel i3");
mo.setText("Asus H61");
me.setText("Kingston 8gb");
hd.setText("1 TB");
ve.setText("Asus Pixma 2 GB ");
mr.setText("LCD 21inch ");
km.setText("include");
hg.setText("4500000");
}
private void deActionPerformed(java.awt.event.ActionEvent evt) {
if (de.isSelected());
pr.setText("intel i5 4670");
mo.setText("Gigabyte GA-Z87M-D3H");
me.setText("Corsair 8gb");
hd.setText("1 TB");
ve.setText("Gigabyte GTX 660 2Gb ");
mr.setText("LCD 21inch ");
km.setText("include");
hg.setText("8000000");
}
private void edActionPerformed(java.awt.event.ActionEvent evt) {
if (ed.isSelected());
pr.setText("intel i7 4670");
mo.setText("Gigabyte GA-Z87M-D3H");
me.setText("Corsair 16gb");
hd.setText("2 TB");
ve.setText("Gigabyte GTX 660 2Gb ");
mr.setText("LCD 21inch ");
km.setText("include");
hg.setText("12000000");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int res=Integer.parseInt(D.getText());
if (res==32304) {
st.setText("Valid");
dis.setText("20");
}else if (res==32305) {
st.setText("Valid");
dis.setText("30");
}else if (res==32306) {
st.setText("Valid");
dis.setText("25");
}else if (res==32302) {
st.setText("Valid");
dis.setText("10");
}else {
st.setText("Invalid");
dis.setText("0");{
}
}
}
private void dlActionPerformed(java.awt.event.ActionEvent evt) {
int num1 = Integer.parseInt(hg.getText());
int num2 = Integer.parseInt(dis.getText());
int num3 = (num1*num2/100);
int num4 = (num1-num3);
T.setText(""+ num4);
}
/**
* Akhir Scrip
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//
/* 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(daftarPaket.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(daftarPaket.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(daftarPaket.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(daftarPaket.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new daftarPaket().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField D;
private javax.swing.JTextField T;
private javax.swing.JRadioButton de;
private javax.swing.JTextField dis;
private javax.swing.JButton dl;
private javax.swing.JRadioButton ed;
private javax.swing.JRadioButton ga;
private javax.swing.ButtonGroup grup;
private javax.swing.JTextField hd;
private javax.swing.JTextField hg;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextField km;
private javax.swing.JTextField me;
private javax.swing.JTextField mo;
private javax.swing.JTextField mr;
private javax.swing.JRadioButton of;
private javax.swing.JRadioButton po;
private javax.swing.JTextField pr;
private javax.swing.JLabel st;
private javax.swing.JTextField ve;
// End of variables declaration
}
dis.setText("20");
}else if (res==32305) {
st.setText("Valid");
dis.setText("30");
}else if (res==32306) {
st.setText("Valid");
dis.setText("25");
}else if (res==32302) {
st.setText("Valid");
dis.setText("10");
}else {
st.setText("Invalid");
dis.setText("0");{
}
}
}
Scrip diatas untuk Code kupon