OOP : Form dan Event Handler C#, JAVA

Selamat datang di RESTOPROGRAM penyedia sajian tutorial pemrograman terkini. Masih ane sajikan hidangan spesial OOP. Untuk yang kedelapan dan yang terakhir dari postingan masa kuliah ane tentang OOP, ane sajikan hidangan BAKSO C# dengan cita rasa Form dan Event Handler C#, JAVA. Langsung saja ane bahas mengenai sajian ini.

Form dan Event Handler C#, JAVA  Form adalah tampilan user interface yang disediakan oleh bahasa pemrograman agar mudah untuk menjalankan sebuah program. Event handler adalah sebuah method yang dapat mendeteksi suatu kejadian yang terjadi pada sebuah form, contoh ketika sebuah button di Click maka program akan melakukan sebuah eksekusi perintah yang ada pada event handler.

  • Contoh dalam Form dan Event Handler C#

Langkah pertama, buat Form seperti ini;

f1

Class

using System;
namespace PT.BerasMulya
{
///

/// Description of library.
///

public class library
{
public library()
{

}
public int TotalHarga(short a, short x)
{
int total;
total = Convert.ToInt32( a * x );
return total;
}
public int Total(int a, int b, int c)
{
int total;
total =a+b+c;
return total;
}
public int Diskon (int total,out string diskon, out int diskon1)
{
if (total >= 4000000)
{
if (total >= 8000000)
{
diskon="Diskon 5%";
diskon1=Convert.ToInt32(total*0.05);
total=Convert.ToInt32(total-diskon1);
}
else
{
diskon="Diskon 3%";
diskon1=Convert.ToInt32(total*0.03);
total=Convert.ToInt32(total-diskon1);
}
}
else
{
diskon="Tidak Mendapat Diskon";
diskon1=0;
total=Convert.ToInt32(total);
}
return total;
}
public int OngkosAntar(int jumlahPesanan)
{
int ongkosAntar = 0;
if (jumlahPesanan >= 250)
{
if(jumlahPesanan >= 10000)
{
ongkosAntar = 700000;
}
else if(jumlahPesanan >= 7000)
{
ongkosAntar = 500000;
}
else if (jumlahPesanan >= 4000)
{
ongkosAntar = 300000;
}
else if (jumlahPesanan >= 2000)
{
ongkosAntar = 175000;
}
else if (jumlahPesanan >= 1000)
{
ongkosAntar = 125000;
}
else
{
ongkosAntar = 75000;
}
}
else
{
ongkosAntar = 35000;
}

return ongkosAntar;
}
public int TotalKeseluruhan (int total,string diantar,out string antar,int ongAnt,out int antar1 )
{
if (diantar == "ya")
{
antar="Dikenakan Ongkos Antar";
antar1=Convert.ToInt32(ongAnt);
total = Convert.ToInt32(total + ongAnt);
}
else
{
antar="Tidak Dikenakan Ongkos Antar";
antar1 = 0;
total = Convert.ToInt32(total * 1);
}
return total;
}
}
}
[/sourcecode]

Main Program

[sourcecode language="csharp"]
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace PT.BerasMulya
{
///

/// Description of MainForm.
///

public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
//konstanta
const short harBer1 = 9000;
const short harBer2 = 8000;
const short harBer3 = 7000;
//variabel
string namaToko;
string tanggal;
string diantar;
string diskon;
string antar;
short jmlPes1;
short jmlPes2;
short jmlPes3;
int antar1;
int diskon1;
int totBer1;
int totBer2;
int totBer3;
int totPes;
int totHar;
int ongAnt;
int totHardis;
int totKes;
private void Input1()
{
//inputan
namaToko=Convert.ToString(textBox1.Text);
tanggal=Convert.ToString(textBox2.Text);
jmlPes1=Convert.ToInt16(textBox3.Text);
jmlPes2=Convert.ToInt16(textBox4.Text);
jmlPes3=Convert.ToInt16(textBox5.Text);
}
private void Seleksi()
{
//pernyataan
if (radioButton1.Checked==true)
{diantar=Convert.ToString(radioButton1.Text);}
else
{diantar=Convert.ToString(radioButton2.Text);}
}
private void Output1(string a,string b,int c,string d,string e,int f, int g,int h,int i,int j,int k)
{
//output
textBox9.Text=a.ToString();
textBox10.Text=b.ToString();
textBox6.Text=c.ToString();
textBox7.Text=d.ToString();
textBox8.Text=e.ToString();
textBox16.Text=f.ToString();
textBox11.Text=g.ToString();
textBox12.Text=h.ToString();
textBox13.Text=i.ToString();
textBox14.Text=j.ToString();
textBox15.Text=k.ToString();
}
private void Output2()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox11.Text = "";
textBox12.Text = "";
textBox13.Text = "";
textBox14.Text = "";
textBox15.Text = "";
textBox16.Text = "";
}
void Button1Click(object sender, EventArgs e)
{
Input1();
Seleksi();
//memanggil class
library imamoto = new library();
//memanggil method
totBer1 = imamoto.TotalHarga(jmlPes1,harBer1);
totBer2 = imamoto.TotalHarga(jmlPes2,harBer2);
totBer3 = imamoto.TotalHarga(jmlPes3,harBer3);
totPes = imamoto.Total(jmlPes1,jmlPes2,jmlPes3);
totHar = imamoto.Total(totBer1,totBer2,totBer3);
totHardis = imamoto.Diskon(totHar,out diskon, out diskon1);
ongAnt = imamoto.OngkosAntar(totPes);
totKes = imamoto.TotalKeseluruhan(totHardis,diantar,out antar,ongAnt,out antar1);
Output1(namaToko,tanggal,diskon1,diskon,antar,antar1,totBer1,totBer2,totBer3,totPes,totKes);

}
void Btn_hapusClick(object sender, EventArgs e)
{
Output2();
}
public void MainFormLoad(object sender, EventArgs e)
{
radioButton1.Checked=true;
}
}
}
  • Hasil Form dan Event Handler C#

form1

form1_

  • Contoh Form dan Event Handler JAVA

Langkah pertama, buat Form seperti ini;

f2

Class

/**
*
* @author Imamoto
*/
public class classptberasmulya {
public int TotalHarga(int a, int x)
{
int total;
total = a * x;
return total;
}
public int Total(int a, int b, int c)
{
int total;
total =a+b+c;
return total;
}
public int Diskon(int total)
{
int diskon=0;
if (total >= 4000000)
{
if (total >= 8000000)
{
diskon=((total/100)*5);
}
else
{
diskon=((total/100)*3);
}
}
else
{
diskon=0;
}
return diskon;
}

public int OngkosAntar(int jumlahPesanan)
{
int ongkosAntar = 0;
if (jumlahPesanan >= 250)
{
if(jumlahPesanan >= 10000)
{
ongkosAntar = 700000;
}
else if(jumlahPesanan >= 7000)
{
ongkosAntar = 500000;
}
else if (jumlahPesanan >= 4000)
{
ongkosAntar = 300000;
}
else if (jumlahPesanan >= 2000)
{
ongkosAntar = 175000;
}
else if (jumlahPesanan >= 1000)
{
ongkosAntar = 125000;
}
else
{
ongkosAntar = 75000;
}
}
else
{
ongkosAntar = 35000;
}
return ongkosAntar;
}
public int SeleksiAntar (String diantar, int ongAnt)
{
int ket = 0;
if(diantar == "YA")
{
ket=ongAnt;
}
else if(diantar == "TIDAK")
{
ket=0;
}
return ket;
}
public int TotalKeseluruhan (String diantar, int total , int diskon, int ongAnt)
{
int totKes=0;
if(diantar == "YA")
{
totKes = ((total - diskon) + ongAnt);
}
else if(diantar == "TIDAK")
{
totKes = (total - diskon);
}
return totKes;
}
}

Main Program

/**
*
* @author Imamoto
*/
public class ptberasmulya extends javax.swing.JFrame {

/** Creates new form ptberasmulya */
public ptberasmulya() {
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() {

jLabel1 = new javax.swing.JLabel();
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();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jButton1 = new javax.swing.JButton();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jTextField9 = new javax.swing.JTextField();
jTextField10 = new javax.swing.JTextField();
jTextField11 = new javax.swing.JTextField();
jTextField12 = new javax.swing.JTextField();
jTextField13 = new javax.swing.JTextField();
jLabel18 = new javax.swing.JLabel();
jLabel19 = new javax.swing.JLabel();
jLabel20 = new javax.swing.JLabel();
jLabel21 = new javax.swing.JLabel();
jLabel22 = new javax.swing.JLabel();
jLabel23 = new javax.swing.JLabel();
jTextField14 = new javax.swing.JTextField();
jLabel24 = new javax.swing.JLabel();
jLabel25 = new javax.swing.JLabel();
jLabel26 = new javax.swing.JLabel();
jLabel27 = new javax.swing.JLabel();
jLabel28 = new javax.swing.JLabel();
jLabel29 = new javax.swing.JLabel();
jLabel30 = new javax.swing.JLabel();
jLabel31 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Arial", 1, 24));
jLabel1.setText("PT.Beras Mulya");

jLabel2.setFont(new java.awt.Font("Arial", 1, 12));
jLabel2.setText("Masukkan Nama Toko Pemesan");

jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
jLabel3.setText("Masukkan Tanggal Pemesanan");

jLabel4.setFont(new java.awt.Font("Arial", 1, 12));
jLabel4.setText("Jumlah Pesanan Beras Tipe 1");

jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
jLabel5.setText("Jumlah Pesanan Beras Tipe 2");

jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
jLabel6.setText("Jumlah Pesanan Beras Tipe 3");

jLabel7.setFont(new java.awt.Font("Arial", 1, 12));
jLabel7.setText("Diantar [Pilih Salah Satu]");

jRadioButton1.setText("YA");

jRadioButton2.setText("TIDAK");

jButton1.setText("OK");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel8.setText("Pemesan");

jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel9.setText("Tanggal");

jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel10.setText("Total Beras Tipe 1");

jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel11.setText("Total Beras Tipe 2");

jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel12.setText("Total Beras Tipe 3");

jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel13.setText("Total Jumlah Pesanan");

jLabel18.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel18.setText("kg");

jLabel19.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel19.setText("kg");

jLabel20.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel20.setText("kg");

jLabel21.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel21.setText("kg");

jLabel22.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel22.setText("Rp");

jLabel23.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel23.setText("Rp");

jLabel24.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel24.setText("Total Keseluruhan");

jLabel25.setFont(new java.awt.Font("Arial", 1, 11));
jLabel25.setText("By : Imamoto Deputi");

jLabel26.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel26.setText("Rp");

jLabel27.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel27.setText("Rp");

jLabel28.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel28.setText("Rp");

jLabel29.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel29.setText("Rp");

jLabel30.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel30.setText("Diskon");

jLabel31.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel31.setText("Ongkos Antar");

jButton2.setText("Reset");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel8)
.addComponent(jLabel9)
.addComponent(jLabel10))
.addGap(22, 22, 22)
.addComponent(jLabel26))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 104, Short.MAX_VALUE)
.addComponent(jLabel27))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 104, Short.MAX_VALUE)
.addComponent(jLabel28))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel24)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 103, Short.MAX_VALUE)
.addComponent(jLabel29))
.addComponent(jLabel13)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel30)
.addComponent(jLabel31))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel23)
.addComponent(jLabel22))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel21)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jTextField12, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 186, Short.MAX_VALUE))
.addComponent(jTextField6, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jTextField4, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField5, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel18)
.addComponent(jLabel19)
.addComponent(jLabel20))
.addGap(306, 306, 306))
.addComponent(jRadioButton2)
.addComponent(jButton1)
.addComponent(jRadioButton1)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
.addComponent(jLabel25, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(38, 38, 38))
.addComponent(jTextField14, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2)))
.addGroup(layout.createSequentialGroup()
.addGap(233, 233, 233)
.addComponent(jLabel1)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jLabel18))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(jLabel19))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(jLabel20))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jRadioButton1)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10)
.addComponent(jLabel26))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel27)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel28)
.addComponent(jLabel12))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel21)
.addComponent(jLabel13))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel22)
.addComponent(jLabel30))
.addGap(26, 26, 26))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel23)
.addComponent(jLabel31)
.addComponent(jTextField13, 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(jLabel29)
.addComponent(jLabel24)
.addComponent(jTextField14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
.addComponent(jLabel25)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addContainerGap())))
);

pack();
}//

//konstanta
int harBer1=9000;
int harBer2=8000;
int harBer3=7000;
//variabel
String pemesan;
String tgl;
public String diantar;
String hasTotber1;
String hasTotber2;
String hasTotber3;
String hasTotpes;
String hasDiskon;
String hasKet;
String hasTotkes;
int jmlPes1;
int jmlPes2;
int jmlPes3;
int totBer1;
int totBer2;
int totBer3;
int totPes;
int totHar;
int diskon;
int ongAnt;
int ket;
int totKes;

private void Input()
{
pemesan=String.valueOf(jTextField1.getText());
tgl=String.valueOf(jTextField2.getText());
jmlPes1=Short.valueOf(jTextField3.getText());
jmlPes2=Short.valueOf(jTextField4.getText());
jmlPes3=Short.valueOf(jTextField5.getText());
}

private void Seleksi()
{
if (jRadioButton1.isSelected()==true)
{diantar=String.valueOf(jRadioButton1.getText());}
else
{diantar=String.valueOf(jRadioButton2.getText());}
}

private void Output()
{
hasTotber1 = String.valueOf(totBer1);
hasTotber2 = String.valueOf(totBer2);
hasTotber3 = String.valueOf(totBer3);
hasTotpes = String.valueOf(totPes);
hasDiskon = String.valueOf(diskon);
hasKet = String.valueOf(ket);
hasTotkes = String.valueOf(totKes);
jTextField6.setText(pemesan);
jTextField7.setText(tgl);
jTextField8.setText(hasTotber1);
jTextField9.setText(hasTotber2);
jTextField10.setText(hasTotber3);
jTextField11.setText(hasTotpes);
jTextField12.setText(hasDiskon);
jTextField13.setText(hasKet);
jTextField14.setText(hasTotkes);
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Input();
Seleksi();
classptberasmulya imamoto = new classptberasmulya();
totBer1 = imamoto.TotalHarga(jmlPes1,harBer1);
totBer2 = imamoto.TotalHarga(jmlPes2,harBer2);
totBer3 = imamoto.TotalHarga(jmlPes3,harBer3);
totPes = imamoto.Total(jmlPes1, jmlPes2, jmlPes3);
totHar = imamoto.Total(totBer1, totBer2, totBer3);
diskon = imamoto.Diskon(totHar);
ongAnt = imamoto.OngkosAntar(totPes);
ket = imamoto.SeleksiAntar(diantar, ongAnt);
totKes = imamoto.TotalKeseluruhan(diantar, totHar, diskon, ongAnt);
Output();
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
jTextField8.setText("");
jTextField9.setText("");
jTextField10.setText("");
jTextField11.setText("");
jTextField12.setText("");
jTextField13.setText("");
jTextField14.setText("");
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ptberasmulya().setVisible(true);
}
});
}

// Variables declaration - do not modify
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 jLabel13;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel19;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel20;
private javax.swing.JLabel jLabel21;
private javax.swing.JLabel jLabel22;
private javax.swing.JLabel jLabel23;
private javax.swing.JLabel jLabel24;
private javax.swing.JLabel jLabel25;
private javax.swing.JLabel jLabel26;
private javax.swing.JLabel jLabel27;
private javax.swing.JLabel jLabel28;
private javax.swing.JLabel jLabel29;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel30;
private javax.swing.JLabel jLabel31;
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.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField10;
private javax.swing.JTextField jTextField11;
private javax.swing.JTextField jTextField12;
private javax.swing.JTextField jTextField13;
private javax.swing.JTextField jTextField14;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
private javax.swing.JTextField jTextField8;
private javax.swing.JTextField jTextField9;
// End of variables declaration
}
  • Hasil Form dan Event Handler JAVA

ak1

ak2

Makasih udah nikamatin hidangan BAKSO C# ane dengan cita rasa Form dan Event Handler C#, JAVA. Jangan sungkan – sungkan mampir lagi ke RESTOPROGRAM. Masih banyak hidangan – hidangan yang akan memanjakan agan – agan semua.

Pada beberapa postingan spesial kali ini agan akan dapetin sourcode project gratis per-sub postingan ane. Caranya tinggal komentar di postingan yang agan ingin dapetin sourcodenya dan WA ke nomer ane 082247505610 untuk konfirmasi, hehehe. Gampang sekali kan gan.

Jangan lupa share hidangan ane di media sosial yang ada di bawah ini !!!

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *