LATIHAN

import java.io.*;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;

public class pertama extends JFrame
{
JMenuBar mb=new JMenuBar();
JMenu Biodata=new JMenu (" Biodata ");
JMenu ProgramStudy=new JMenu (" Program ");
JMenu penilaian=new JMenu (" Laporan ");
JMenu help=new JMenu (" Help");

JMenuItem input1=new JMenuItem("Siswa & Siswi");
JMenuItem input2=new JMenuItem("Guru & Karyawan");
JMenuItem input0=new JMenuItem("");

JMenuItem input3=new JMenuItem("ProgramStudy");
JMenuItem input4=new JMenuItem(" Nilai Akhir ");



JMenuItem input8=new JMenuItem("Laporan Akhir ");

JMenuItem input9=new JMenuItem("Petunjuk Penggunaan");
JMenuItem input10=new JMenuItem("About");

JLabel gambar1=new JLabel (new ImageIcon("utama.jpg"));
JButton exit=new JButton (new ImageIcon("exit.jpg"));

JLabel l_huruf = new JLabel(); //jam
JLabel l_jam = new JLabel();




pertama()
{
//super("DATA SISWA");
setSize(800,640);
setLocation(100,50);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
show();
}
void letakkomponen()
{
getContentPane().setLayout(null);
setJMenuBar(mb); mb.setBounds(100,213,80,20);
mb.add(Biodata);
mb.add(ProgramStudy); Biodata.add(input1); ProgramStudy.add(input3);
Biodata.add(input2); ProgramStudy.add(input4);
mb.add(penilaian); Biodata.add(input0); // administrasi.add(input6);
mb.add(help);

help.add(input9);
help.add(input10); penilaian.add(input8);

mb.setFont(new Font("verdana",Font.BOLD,13));
mb.setBackground(Color.black);

Biodata.setFont(new Font("verdana",Font.BOLD,13));
Biodata.setForeground(Color.white);
Biodata.setBackground(Color.black);
ProgramStudy.setFont(new Font("verdana",Font.BOLD,13));
ProgramStudy.setForeground(Color.white);
ProgramStudy.setBackground(Color.black);

penilaian.setFont(new Font("verdana",Font.BOLD,13));
penilaian.setForeground(Color.white);
penilaian.setBackground(Color.black);
help.setFont(new Font("verdana",Font.BOLD,13));
help.setForeground(Color.white);
help.setBackground(Color.black);

input1.setFont(new Font("verdana",Font.BOLD,13));
input1.setForeground(Color.white);
input1.setBackground(Color.black);
input2.setFont(new Font("verdana",Font.BOLD,13)); input8.setFont(new Font("verdana",Font.BOLD,13));
input2.setForeground(Color.white); input8.setForeground(Color.white);
input2.setBackground(Color.black); input8.setBackground(Color.black);
exit.setFont(new Font("verdana",Font.BOLD,13)); input9.setFont(new Font("verdana",Font.BOLD,13));
exit.setForeground(Color.white); input9.setForeground(Color.white);
exit.setBackground(Color.black); input9.setBackground(Color.black);
input3.setFont(new Font("verdana",Font.BOLD,13)); input10.setFont(new Font("verdana",Font.BOLD,13));
input3.setForeground(Color.white); input10.setForeground(Color.white);
input3.setBackground(Color.black); input10.setBackground(Color.black);
input4.setFont(new Font("verdana",Font.BOLD,13));
input4.setForeground(Color.white);
input4.setBackground(Color.black);
/* input6.setFont(new Font("verdana",Font.BOLD,13));
input6.setForeground(Color.white);
input6.setBackground(Color.black); */



getContentPane().add (exit); exit.setBounds(675,562,80,25);
l_jam.setForeground(Color.white);
l_jam.setFont(new Font("arial",Font.BOLD,16));
getContentPane().add(l_jam); l_jam.setBounds (250,118,130,25);

l_huruf.setForeground(Color.white);
l_huruf.setFont(new Font("arial",Font.BOLD,16));
getContentPane().add(l_huruf); l_huruf.setBounds (490,116,140,25);


getContentPane().add (gambar1); gambar1.setBounds(0,0,800,600);
setVisible(true);
}

void Jam()
{
ActionListener taskPerformer = new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
String nol_bulan = "";
String nol_hari = "";
String nol_jam = "";
String nol_menit = "";
String nol_detik = "";
String Date = "";

// Membuat Date
Date dt=new Date();

// Mengambil nilai JAM, MENIT, dan DETIK Sekarang
int nilai_tahun = dt.getYear() + 1900;
int nilai_bulan = dt.getMonth() + 1;
int nilai_hari = dt.getDate();
int nilai_jam = dt.getHours();
int nilai_menit = dt.getMinutes();
int nilai_detik = dt.getSeconds();

// Jika nilai JAM lebih kecil dari 10 (hanya 1 digit)
if (nilai_bulan <= 9)
{
// Tambahkan "0" didepannya
nol_bulan = "0";
}
if (nilai_hari <= 9)
{
// Tambahkan "0" didepannya
nol_hari = "0";
}
if (nilai_jam <= 9)
{
// Tambahkan "0" didepannya
nol_jam = "0";
}

// Jika nilai MENIT lebih kecil dari 10 (hanya 1 digit)
if (nilai_menit <= 9)
{
// Tambahkan "0" didepannya
nol_menit = "0";
}

// Jika nilai DETIK lebih kecil dari 10 (hanya 1 digit)
if (nilai_detik <= 9)
{
// Tambahkan "0" didepannya
nol_detik = "0";
}

// Membuat String JAM, MENIT, DETIK
String bulan = nol_bulan + Integer.toString(nilai_bulan);
String hari = nol_hari + Integer.toString(nilai_hari);
String jam = nol_jam + Integer.toString(nilai_jam);
String menit = nol_menit + Integer.toString(nilai_menit);
String detik = nol_detik + Integer.toString(nilai_detik);

// Menampilkan pada Layar
l_huruf.setText(hari + " - " + bulan + " - " + nilai_tahun);
l_jam.setText(jam + " : " + menit + " : " + detik);
}
};
// Timer
new Timer(1000, taskPerformer).start();
}

void AksiReaksi()
{

input1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input1)
{

daftar df= new daftar ();
df.letakkomponen();
df.AksiReaksi();
df.Jam();

setVisible(false);
}
}
});




input2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input2)
{
biodataguru df= new biodataguru ();
df.letakkomponen();
df.AksiReaksi();
df.Jam();
setVisible(false);
}
}
});

input3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input3)
{

bimbingan bb= new bimbingan ();
bb.letakkomponen();
bb.AksiReaksi();

setVisible(false);
}
}
});

input4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input4)
{
penilaian ap=new penilaian();
ap.komponenVisual();
ap.AksiReaksi();
setVisible(false);
}
}
});


input8.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input8)
{
Laporan sc= new Laporan ();
sc.koneksi();
sc. AksiReaksi();
sc.Komponen();
setVisible(false);

}
}
});
input9.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input9)
{
cara sc= new cara ();
sc.Komponen();
sc.aksireaksi();
setVisible(false);
}
}
});
input10.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input10)
{
about sc= new about ();
sc.Komponen();
sc.aksireaksi();
setVisible(false);
}
}
});


exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int i= JOptionPane.showConfirmDialog(null,"Are you sure to exit programs ?","Exit", JOptionPane.YES_NO_OPTION);
if(i==0)

System.exit(0);
}
});
}
public static void main (String args[])
{
pertama df= new pertama ();
df.letakkomponen();
df.AksiReaksi();
df.Jam();
}
}


import java.io.*;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;

public class daftar extends komponen
{
JTextField tx_no=new JTextField(10);
JTextField tx_nama=new JTextField(10);
JTextField tx_ttl=new JTextField(10);
JTextField tx_alamat=new JTextField(10);
JTextField tx_tlp=new JTextField(10);
JTextField tx_status=new JTextField(10);

JLabel gambar1=new JLabel (new ImageIcon("gambar1.jpg"));
// JLabel foto=new JLabel (new ImageIcon("foto.jpg"));
JButton Button1=new JButton (new ImageIcon("button1.jpg"));
JButton Button2=new JButton (new ImageIcon("button2.jpg"));
JButton save=new JButton (new ImageIcon("save.jpg"));
JButton edit=new JButton (new ImageIcon("edit.jpg"));
JButton back=new JButton (new ImageIcon("back1.jpg"));
JButton btcari=new JButton(new ImageIcon("search.jpg"));
JLabel lbsave=new JLabel ("save");
JLabel lbedit=new JLabel ("update");
JLabel lbcari=new JLabel ("cari");
JButton view=new JButton (new ImageIcon("view.jpg"));


JLabel l_huruf = new JLabel(); //jam
JLabel l_jam = new JLabel();

JTextArea text = new JTextArea();
JScrollPane scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

String nomor="";
String nama="";
String alamat="";
String ttl="";
String tlp="";
String status="";
String Search="";
String cari="";

daftar()
{
//super("DATA SISWA");
setSize(800,625);
setLocation(100,50);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
show();
}
void letakkomponen()
{
getContentPane().setLayout(null);
l_jam.setForeground(Color.white);
l_jam.setFont(new Font("arial",Font.BOLD,16));
getContentPane().add(l_jam); l_jam.setBounds (250,118,130,25);

l_huruf.setForeground(Color.white);
l_huruf.setFont(new Font("arial",Font.BOLD,16));
getContentPane().add(l_huruf); l_huruf.setBounds (490,116,140,25);

getContentPane().add (tx_no); tx_no.setBounds(630,213,80,20);
getContentPane().add (tx_nama); tx_nama.setBounds(220,315,200,20);
getContentPane().add (tx_ttl); tx_ttl.setBounds(220,345,200,20);
getContentPane().add (tx_alamat); tx_alamat.setBounds(220,375,200,20);
getContentPane().add (tx_tlp); tx_tlp.setBounds(220,405,200,20);
getContentPane().add (tx_status); tx_status.setBounds(220,435,200,20);

// getContentPane().add (foto); foto.setBounds(627,120,100,100);
getContentPane().add (Button1); Button1.setBounds(85,485,210,30);
getContentPane().add (Button2); Button2.setBounds(340,485,90,30);
getContentPane().add (save); save.setBounds(575,350,30,30);
getContentPane().add (edit); edit.setBounds(630,295,30,30);
getContentPane().add (btcari); btcari.setBounds(685,350,30,30);

lbsave.setForeground(Color.white);
lbedit.setForeground(Color.white);
lbcari.setForeground(Color.white);
getContentPane().add (lbsave); lbsave.setBounds(575,370,30,30);
getContentPane().add (lbedit); lbedit.setBounds(630,315,40,30);
getContentPane().add (lbcari); lbcari.setBounds(685,370,30,30);
getContentPane().add (view); view.setBounds(470,485,90,30);
getContentPane().add (back); back.setBounds(675,562,80,25);
getContentPane().add (gambar1); gambar1.setBounds(0,0,800,600);
setVisible(true);
}

void Jam()
{
ActionListener taskPerformer = new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
String nol_bulan = "";
String nol_hari = "";
String nol_jam = "";
String nol_menit = "";
String nol_detik = "";
String Date = "";

// Membuat Date
Date dt=new Date();

// Mengambil nilai JAM, MENIT, dan DETIK Sekarang
int nilai_tahun = dt.getYear() + 1900;
int nilai_bulan = dt.getMonth() + 1;
int nilai_hari = dt.getDate();
int nilai_jam = dt.getHours();
int nilai_menit = dt.getMinutes();
int nilai_detik = dt.getSeconds();

// Jika nilai JAM lebih kecil dari 10 (hanya 1 digit)
if (nilai_bulan <= 9)
{
// Tambahkan "0" didepannya
nol_bulan = "0";
}
if (nilai_hari <= 9)
{
// Tambahkan "0" didepannya
nol_hari = "0";
}
if (nilai_jam <= 9)
{
// Tambahkan "0" didepannya
nol_jam = "0";
}

// Jika nilai MENIT lebih kecil dari 10 (hanya 1 digit)
if (nilai_menit <= 9)
{
// Tambahkan "0" didepannya
nol_menit = "0";
}

// Jika nilai DETIK lebih kecil dari 10 (hanya 1 digit)
if (nilai_detik <= 9)
{
// Tambahkan "0" didepannya
nol_detik = "0";
}

// Membuat String JAM, MENIT, DETIK
String bulan = nol_bulan + Integer.toString(nilai_bulan);
String hari = nol_hari + Integer.toString(nilai_hari);
String jam = nol_jam + Integer.toString(nilai_jam);
String menit = nol_menit + Integer.toString(nilai_menit);
String detik = nol_detik + Integer.toString(nilai_detik);

// Menampilkan pada Layar
l_huruf.setText(hari + " - " + bulan + " - " + nilai_tahun);
l_jam.setText(jam + " : " + menit + " : " + detik);
}
};
// Timer
new Timer(1000, taskPerformer).start();
}

void AksiReaksi()
{
save.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if (event.getSource()==save)
{
try
{
nomor=tx_no.getText();
nama=tx_nama.getText();

ttl=tx_ttl.getText();
alamat=tx_alamat.getText();
status=tx_status.getText();
tlp=tx_tlp.getText();

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:odbc:Administrasi;uid='admin';pw='admin'");
Statement statement = connection.createStatement();
String sql="insert into Daftar values ('"+nomor+"','"+nama+"','"+ttl+"','"+alamat+"','"+tlp+"','"+status+"');";

statement.executeUpdate(sql);
statement.close();
connection.close();

JOptionPane.showMessageDialog(null,"Data Anda Telah masuk","Konfirmasi",JOptionPane.INFORMATION_MESSAGE);
tx_no.setText("");
tx_nama.setText("");
tx_alamat.setText("");
tx_ttl.setText("");
tx_status.setText("");
tx_tlp.setText("");
tx_no.requestFocus();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null," Apakah Nomor sudah terisi dengan benar !!!\n atau mungkin No sudah ada dalam data base?\n ULANGI SEKALI LAGI ","Konfirmasi",JOptionPane.INFORMATION_MESSAGE);
}

}
}
});


edit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if (event.getSource()==edit)
{
try
{
nomor=tx_no.getText();
nama=tx_nama.getText();
ttl=tx_ttl.getText();
alamat=tx_alamat.getText();
status=tx_status.getText();
tlp=tx_tlp.getText();


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:odbc:Administrasi;uid='admin';pw='admin'");
Statement statement = connection.createStatement();
String sql="update Daftar set nama='"+nama+"',ttl='"+ttl+"',alamat='"+alamat+"',tlp='"+tlp+"',status='"+status+"'where nomor='"+nomor+"'";
statement.executeUpdate(sql);
statement.close();
connection.close();

JOptionPane.showMessageDialog(null," Data Telah Teredit","Konfirmasi",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e)
{
//JOptionPane.showMessageDialog(null,"Data Error","Konfirmasi",JOptionPane.INFORMATION_MESSAGE);
System.out.print("ERROR"+e);
}
}
}
});


btcari.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==btcari)
{
try
{
cari=tx_no.getText();

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:odbc:Administrasi;uid='admin';pw='admin'");
Statement statement = connection.createStatement();
String sql="select * from Daftar where nomor like '"+cari+"'";
ResultSet rs=statement.executeQuery(sql);

if(rs.next())
{


tx_no.setText(rs.getString(1));
tx_nama.setText(rs.getString(2));

tx_ttl.setText(rs.getString(3));
tx_alamat.setText(rs.getString(4));
tx_tlp.setText(rs.getString(5));
tx_status.setText(rs.getString(6));

}
else
{
JOptionPane.showMessageDialog(null,"Maaf Data Tidak Ditemukan ","Konfirmasi",JOptionPane.INFORMATION_MESSAGE);
}
statement.close();
connection.close();
}
catch(Exception ex)
{

System.out.print("" + ex);
}

}
}
});


view.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ViewDaftar vp=new ViewDaftar();

vp.komponenVisual();
vp.aksiReaksi();
}
});

Button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==Button1)
{
bimbingan bb= new bimbingan ();
bb.letakkomponen();
bb.AksiReaksi();
// bb.Jam();

setVisible(false);
}
}
});
Button2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==Button2)
{
Laporan sc= new Laporan ();
sc.koneksi();
sc. AksiReaksi();
sc.Komponen();
setVisible(false);

}
}
});

back.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==back)
{

pertama df= new pertama ();
df.letakkomponen();
df.AksiReaksi();
df.Jam();
setVisible(false);
}
}
});
}
public static void main (String args[])
{
daftar df= new daftar ();
df.letakkomponen();
df.AksiReaksi();
df.Jam();
}
}

Tidak ada komentar:

Posting Komentar

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More