0% found this document useful (0 votes)
61 views9 pages

Sarif-Hidayat 1B Pemrograman

The document contains source code for a Java program that creates a GUI for inputting student data. The program creates labels, text fields, combo boxes, radio buttons, and buttons to collect a student's name, date of birth, gender, religion, faculty, study program, class, and student ID. It also includes buttons to save or delete the input data and displays messages when the buttons are clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views9 pages

Sarif-Hidayat 1B Pemrograman

The document contains source code for a Java program that creates a GUI for inputting student data. The program creates labels, text fields, combo boxes, radio buttons, and buttons to collect a student's name, date of birth, gender, religion, faculty, study program, class, and student ID. It also includes buttons to save or delete the input data and displays messages when the buttons are clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Nama : Sarif Hidayat

Nim : 20573014
Kelas : 1B

SOURCE CODE

package tugaspem;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class TugasPem implements ActionListener {

public static void main(String[] args) {

new TugasPem();

public TugasPem () {

isiprogram();

}
private void isiprogram () {

//membuat JFrame

JFrame form = new JFrame("Input Data");

form.setSize(800,1000);

form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

form.setLocationRelativeTo(null);

form.setLayout(null);

//membuat judul

JLabel lbljudul = new JLabel("INPUT DATA MAHASISWA");

lbljudul.setBounds(350,30,150,30);

form.add(lbljudul);

//membuat label nama dan textfield nama

JLabel lblnama = new JLabel("Nama : ");

lblnama.setBounds(20,80,150,25);

form.add(lblnama);

JTextField txtnama = new JTextField();

txtnama.setBounds(150,80,150,25);

form.add(txtnama);

//membuat tempat tanggal lahir

JLabel lblttl = new JLabel("TTL : ");

lblttl.setBounds(20,110,150,30);
form.add(lblttl);

JTextField txttempat = new JTextField();

txttempat.setBounds(150,110,70,25);

form.add(txttempat);

String[] tanggal = {"1","2","3","4","5","6","7","8","9","10","11","12","13",

"14","15","16","17","18","19","20","21",

"22","23","24","25","26","27","28","29","30","31"};

JComboBox cbbtanggal = new JComboBox(tanggal);

cbbtanggal.setBounds(230,110,40,25);

form.add(cbbtanggal);

String[] bulan =
{"jan","feb","mar","apr","mei","jun","jul","ags","sep","okt", "nov","des"};

JComboBox cbbbulan = new JComboBox(bulan);

cbbbulan.setBounds(280,110,50,25);

form.add(cbbbulan);

JTextField txttahun = new JTextField();

txttahun.setBounds(340,110,70,25);

form.add(txttahun);

//Jenis Kelamin

JLabel lblJK= new JLabel("Jenis Kelamin : ");

lblJK.setBounds(20,150,150,30);

form.add(lblJK);

JRadioButton jrblaki = new JRadioButton();


jrblaki.setText("Laki-Laki");

jrblaki.setBounds(150,150,80,30);

form.add(jrblaki);

JRadioButton jrbcewe = new JRadioButton();

jrbcewe.setText("Perempuan");

jrbcewe.setBounds(250,150,90,30);

form.add(jrbcewe);

ButtonGroup bbjenis = new ButtonGroup();

bbjenis.add(jrblaki);

bbjenis.add(jrbcewe);

//Agama

JLabel lblagama= new JLabel("Agama : ");

lblagama.setBounds(20,190,150,30);

form.add(lblagama);

String[] agama = {"islam","kristen","katolik","budha","kong hu


cu","hindu"};

JComboBox cbbagama = new JComboBox(agama);

cbbagama.setBounds(150,190,100,25);

form.add(cbbagama);

//Fakultas

JLabel lblfakultas = new JLabel("Fakultas : ");

lblfakultas.setBounds(20,230,150,30);
form.add(lblfakultas);

String[] fakultas = {"Ilmu Terapan dan Sains","Pendidilan Ilmu Sosial


Bahasa dan Sastra"};

JComboBox cbbfakultas = new JComboBox(fakultas);

cbbfakultas.setBounds(150,230,150,25);

form.add(cbbfakultas);

//Program Studi

JLabel lblprodi = new JLabel("Program Studi : ");

lblprodi.setBounds(20,260,190,30);

form.add(lblprodi);

String[] prodi = {"Pen.Matematika","Pen.Biologi","Pen.Fisika",

"Pen.Tek.Inf","Sistem Informasi","PGSD",",PPKn","IPS","Bahasa dan


Sastar Indonesia"};

JComboBox cbbprodi = new JComboBox(prodi);

cbbprodi.setBounds(150,260,100,25);

form.add(cbbprodi);

//Kelas

JLabel lblkelas = new JLabel("Kelas : ");

lblkelas.setBounds(20,290,150,25);

form.add(lblkelas);

JTextField txtkelas = new JTextField();

txtkelas.setBounds(150,290,150,25);

form.add(txtkelas);
//Nim

JLabel lblnim = new JLabel("NIM : ");

lblnim.setBounds(20,330,150,25);

form.add(lblnim);

JTextField txtnim = new JTextField();

txtnim.setBounds(150,330,150,25);

form.add(txtnim);

//button simpan

JButton btnsimpan = new JButton ("simpan");

btnsimpan.setBounds(140,400,100,30);

form.add(btnsimpan);

//button hapus

JButton btnhapus = new JButton("hapus");

btnhapus.setBounds(270,400,100,30);

form.add(btnhapus);

btnsimpan.addActionListener(this);

btnhapus.addActionListener(this);

btnsimpan.setActionCommand("simpan");
btnhapus.setActionCommand("hapus");

form.setVisible(true);

@Override

public void actionPerformed(ActionEvent ae) {

String tanda = ae.getActionCommand();

switch(tanda) {

case "simpan" :

JOptionPane.showMessageDialog(null,"data berhasil di simpan");

break;

case "hapus":

JOptionPane.showMessageDialog(null,"data berhasil di hapus");

break;

default :

System.out.println("tidak ada pilihan");

}
OUTPUT :

You might also like