package uts_pbo_2;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class DataSuratMasuk extends JDialog {
JLabel labelNo, labelHal, labelTglSurat, labelTglTerima, labelPengirim, labelPenerima;
JTextField fieldNo, fieldHal, fieldTglSurat, fieldTglTerima, fieldPengirim, fieldPenerima;
JButton btnOK;
public DataSuratMasuk(Frame owner) {
super(owner);
setTitle("Data Surat Masuk");
setSize(500, 250);
setLocation(300, 300);
setResizable(false);
setLayout(new FlowLayout());
labelNo = new JLabel("No");
labelHal = new JLabel("Perihal");
labelTglSurat = new JLabel("Tanggal Surat (DD-MMM-YY)");
labelTglTerima = new JLabel("Tanggal Terima (DD-MMM-YY)");
labelPengirim = new JLabel("Pengirim");
labelPenerima = new JLabel("Penerima");
fieldNo = new JTextField(20);
fieldHal = new JTextField(20);
fieldPenerima = new JTextField(20);
fieldPengirim = new JTextField(20);
fieldTglSurat = new JTextField(20);
fieldTglTerima = new JTextField(20);
JPanel panel = new JPanel(new GridLayout(6, 1));
getContentPane().add(panel);
panel.setBorder(BorderFactory.createTitledBorder("Masukkan Identitas Surat: "));
panel.add(labelNo);
panel.add(fieldNo);
panel.add(labelHal);
panel.add(fieldHal);
panel.add(labelPenerima);
panel.add(fieldPenerima);
panel.add(labelPengirim);
panel.add(fieldPengirim);
panel.add(labelTglSurat);
panel.add(fieldTglSurat);
panel.add(labelTglTerima);
panel.add(fieldTglTerima);
btnOK = new JButton("Simpan");
getContentPane().add(btnOK);
btnOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (fieldNo.getText().equals("") || fieldHal.getText().equals("") || fieldPenerima.getText().equals("")
|| fieldPengirim.getText().equals("") || fieldTglSurat.getText().equals("")
|| fieldTglTerima.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Ada Field yang Kosong");
} else {
Surat surat = new Surat();
surat.setNoSurat(fieldNo.getText());
surat.setPerihal(fieldHal.getText());
surat.setTglSurat(fieldTglSurat.getText());
surat.setTglTerima(fieldTglTerima.getText());
surat.setPenerima(fieldPenerima.getText());
surat.setPengirim(fieldPengirim.getText());
JOptionPane.showMessageDialog(rootPane, "Surat Telah Berhasil Disimpan");
DataHandler datahandler = new DataHandler();
try {
datahandler.add(surat.getNoSurat(), surat.getPerihal(), surat.getPenerima(),
surat.getPengirim(), surat.getTglSurat(), surat.getTglTerima());
} catch (SQLException ex) {
Logger.getLogger(DataSuratMasuk.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
}
}
Tidak ada komentar:
Posting Komentar