TUGAS TEORI
BAHASA PEMROGRAMAN 1
Program PDAM JFrame
Dosen:
Dede Irawan, M.Kom.
Disusun Oleh:
AGUNG TRIANGGORO
20180910015
Sistem Informasi-A 2018
FAKULTAS
ILMU KOMPUTER
UNIVERSITAS
KUNINGAN
TAHUN
2018
PROGRAM PDAM DENGAN JFrame (Non Visual)
Source Code:
package tespdam;
import javax.swing.*;
import java.awt.event.*;
public class pdam extends JFrame implements ActionListener{
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
JLabel label5 = new JLabel();
JTextField text1 = new JTextField();
JTextField text2 = new JTextField();
JTextField text3 = new JTextField();
JTextField text4 = new JTextField();
JTextField text5 = new JTextField();
JButton button1 = new JButton();
JButton button2 = new JButton();
JButton button3 = new JButton();
JButton button4 = new JButton();
public void ciptakanJFrame(){
setLayout(null);
setTitle("Program PDAM - Agung Trianggoro");
setVisible(true);
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setLocationRelativeTo(null);
}
public void ciptakanJLabel(){
label1.setText("Kode Pelanggan:");
label1.setBounds(10,10,250,20);
add(label1);
label2.setText("Nama:");
label2.setBounds(10,50,250,20);
add(label2);
label3.setText("Pemakaian Air dalam M3:");
label3.setBounds(10,90,250,20);
add(label3);
label4.setText("Harga:");
label4.setBounds(10,200,250,20);
add(label4);
label5.setText("Pembayaran:");
label5.setBounds(10,230,250,20);
add(label5);
}
public void ciptakanJTextField(){
text1.setBounds(180,10,160,20);
add(text1);
text2.setBounds(180,50,160,20);
add(text2);
text3.setBounds(180,90,160,20);
add(text3);
text4.setBounds(180,200,160,20);
add(text4);
text5.setBounds(180,230,160,20);
add(text5);
}
public void ciptakanJButton(){
button1.setText("Proses");
button1.setBounds(20,150,80,20);
button1.addActionListener(this);
add(button1);
button2.setText("Ulangi");
button2.setBounds(120,150,80,20);
button2.addActionListener(this);
add(button2);
button3.setText("Keluar");
button3.setBounds(220,150,80,20);
button3.addActionListener(this);
add(button3);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Proses")){
class prosespdam {
int pakai;
int a;
int b;
int c;
int d;
int biaya;
int[] total;
}
prosespdam hitung = new prosespdam();
hitung.pakai = Integer.parseInt(text3.getText());
hitung.a = 10;
hitung.b = 0;
hitung.c = 0;
hitung.d = 0;
if (hitung.pakai > 30)
{
hitung.b = 10;
hitung.c = 10;
hitung.d = hitung.pakai - 30;
}
else if (hitung.pakai > 20)
{
hitung.b = 10;
hitung.c = hitung.pakai - 20;
}
else if (hitung.pakai > 10)
{
hitung.b = hitung.pakai - 10;
}
hitung.biaya = ((hitung.a * 2000) + (hitung.b * 3000) + (hitung.c * 4000) + (hitung.d * 5000) );
text4.setText(String.valueOf(hitung.biaya));
hitung.total = new int[hitung.biaya];
text5.setText(String.valueOf(hitung.biaya));
}
if(e.getActionCommand().equals("Ulangi")){
text1.setText("");
text2.setText("");
text3.setText("");
text4.setText("");
}
if(e.getActionCommand().equals("Keluar")){
System.exit(0);
}
}
public static void main(String[]args){
pdam f1 = new pdam();
f1.ciptakanJFrame();
f1.ciptakanJLabel();
f1.ciptakanJTextField();
f1.ciptakanJButton();
}
}
import javax.swing.*;
import java.awt.event.*;
public class pdam extends JFrame implements ActionListener{
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
JLabel label5 = new JLabel();
JTextField text1 = new JTextField();
JTextField text2 = new JTextField();
JTextField text3 = new JTextField();
JTextField text4 = new JTextField();
JTextField text5 = new JTextField();
JButton button1 = new JButton();
JButton button2 = new JButton();
JButton button3 = new JButton();
JButton button4 = new JButton();
public void ciptakanJFrame(){
setLayout(null);
setTitle("Program PDAM - Agung Trianggoro");
setVisible(true);
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setLocationRelativeTo(null);
}
public void ciptakanJLabel(){
label1.setText("Kode Pelanggan:");
label1.setBounds(10,10,250,20);
add(label1);
label2.setText("Nama:");
label2.setBounds(10,50,250,20);
add(label2);
label3.setText("Pemakaian Air dalam M3:");
label3.setBounds(10,90,250,20);
add(label3);
label4.setText("Harga:");
label4.setBounds(10,200,250,20);
add(label4);
label5.setText("Pembayaran:");
label5.setBounds(10,230,250,20);
add(label5);
}
public void ciptakanJTextField(){
text1.setBounds(180,10,160,20);
add(text1);
text2.setBounds(180,50,160,20);
add(text2);
text3.setBounds(180,90,160,20);
add(text3);
text4.setBounds(180,200,160,20);
add(text4);
text5.setBounds(180,230,160,20);
add(text5);
}
public void ciptakanJButton(){
button1.setText("Proses");
button1.setBounds(20,150,80,20);
button1.addActionListener(this);
add(button1);
button2.setText("Ulangi");
button2.setBounds(120,150,80,20);
button2.addActionListener(this);
add(button2);
button3.setText("Keluar");
button3.setBounds(220,150,80,20);
button3.addActionListener(this);
add(button3);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Proses")){
class prosespdam {
int pakai;
int a;
int b;
int c;
int d;
int biaya;
int[] total;
}
prosespdam hitung = new prosespdam();
hitung.pakai = Integer.parseInt(text3.getText());
hitung.a = 10;
hitung.b = 0;
hitung.c = 0;
hitung.d = 0;
if (hitung.pakai > 30)
{
hitung.b = 10;
hitung.c = 10;
hitung.d = hitung.pakai - 30;
}
else if (hitung.pakai > 20)
{
hitung.b = 10;
hitung.c = hitung.pakai - 20;
}
else if (hitung.pakai > 10)
{
hitung.b = hitung.pakai - 10;
}
hitung.biaya = ((hitung.a * 2000) + (hitung.b * 3000) + (hitung.c * 4000) + (hitung.d * 5000) );
text4.setText(String.valueOf(hitung.biaya));
hitung.total = new int[hitung.biaya];
text5.setText(String.valueOf(hitung.biaya));
}
if(e.getActionCommand().equals("Ulangi")){
text1.setText("");
text2.setText("");
text3.setText("");
text4.setText("");
}
if(e.getActionCommand().equals("Keluar")){
System.exit(0);
}
}
public static void main(String[]args){
pdam f1 = new pdam();
f1.ciptakanJFrame();
f1.ciptakanJLabel();
f1.ciptakanJTextField();
f1.ciptakanJButton();
}
}
HASIL RUN PROGRAM:
0 komentar:
Posting Komentar