package uts_pbo_2;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
public class Read extends JFrame {
Scanner input = new Scanner(System.in);
JCheckBox cbox[];
DataHandler data;
private JRadioButton[] radioButton;
JButton ok;
ButtonGroup bg;
String[] btnText = {"No Surat", "Perihal", "Penerima", "Pengirim", "Tanggal Kirim", "Tanggal Terima"};
JPanel cpanel, opanel;
String word = null;
Surat key;
Read() {
}
public Read(Frame owner) {
Container content = getContentPane();
setTitle("Read Mail");
setSize(300, 300);
setLocation(300, 300);
content.setLayout(new BorderLayout());
cpanel = new JPanel(new GridLayout(0, 1));
cpanel.setBorder(BorderFactory.createTitledBorder("Cari Berdasarkan: "));
bg = new ButtonGroup();
radioButton = new JRadioButton[btnText.length];
for (int i = 0; i < radioButton.length; i++) {
radioButton[i] = new JRadioButton(btnText[i]);
// radioButton[i].addItemListener(this);
bg.add(radioButton[i]);
cpanel.add(radioButton[i]);
}
ok = new JButton("OK");
opanel = new JPanel();
opanel.add(ok);
content.add(cpanel, BorderLayout.CENTER);
content.add(opanel, BorderLayout.SOUTH);
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (radioButton[0].isSelected()) {
data = new DataHandler();
try {
Surat surat = new Surat();
word = JOptionPane.showInputDialog("Masukkan Keyword: ");
surat.setSearch(word);
ArrayList test = data.searchNo(surat.getSearch());
for (int i = 0; i < test.size(); i++) {
DataHandler temp = (DataHandler) test.get(i);
JOptionPane.showMessageDialog(rootPane, temp.getNo());
}
} catch (SQLException ex) {
Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (radioButton[1].isSelected()) {
data = new DataHandler();
try {
Surat surat = new Surat();
word = JOptionPane.showInputDialog("Masukkan Keyword: ");
surat.setSearch(word);
ArrayList test = data.searchHal(surat.getSearch());
for (int i = 0; i < test.size(); i++) {
DataHandler temp = (DataHandler) test.get(i);
JOptionPane.showMessageDialog(rootPane, temp.getHal());
}
} catch (SQLException ex) {
Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (radioButton[2].isSelected()) {
data = new DataHandler();
try {
Surat surat = new Surat();
word = JOptionPane.showInputDialog("Masukkan Keyword: ");
surat.setSearch(word);
ArrayList test = data.searchPenerima(surat.getSearch());
for (int i = 0; i < test.size(); i++) {
DataHandler temp = (DataHandler) test.get(i);
JOptionPane.showMessageDialog(rootPane, temp.getPnrm());
}
} catch (SQLException ex) {
Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (radioButton[3].isSelected()) {
data = new DataHandler();
try {
Surat surat = new Surat();
word = JOptionPane.showInputDialog("Masukkan Keyword: ");
surat.setSearch(word);
ArrayList test = data.searchPengirim(surat.getSearch());
for (int i = 0; i < test.size(); i++) {
DataHandler temp = (DataHandler) test.get(i);
JOptionPane.showMessageDialog(rootPane, temp.getPkrm());
}
} catch (SQLException ex) {
Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (radioButton[4].isSelected()) {
data = new DataHandler();
try {
Surat surat = new Surat();
word = JOptionPane.showInputDialog("Masukkan Keyword: ");
surat.setSearch(word);
ArrayList test = data.searchTglSurat(surat.getSearch());
for (int i = 0; i < test.size(); i++) {
DataHandler temp = (DataHandler) test.get(i);
JOptionPane.showMessageDialog(rootPane, temp.getTglSurat());
}
} catch (SQLException ex) {
Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
}
} else{
data = new DataHandler();
try {
Surat surat = new Surat();
word = JOptionPane.showInputDialog("Masukkan Keyword: ");
surat.setSearch(word);
ArrayList test = data.searchNo(surat.getSearch());
for (int i = 0; i < test.size(); i++) {
DataHandler temp = (DataHandler) test.get(i);
JOptionPane.showMessageDialog(rootPane, temp.getTglTerima());
}
} catch (SQLException ex) {
Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
}
}
Tidak ada komentar:
Posting Komentar