pacote sokic;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import com.mysql.jdbc.Statement;
classe pública Nastavnici estende JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField tx_id_nastavnika;
private JTextField txt_ime;
private JTextField txt_prezime;
private JTextField txt_staz;
private JTextField txt_email;
private JTextField txt_telefon;
private JTextField txt_oblast;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Nastavnici frame = new Nastavnici();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public static void main1(String[] args) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/studije";
String user = "rootr";
String password = "root";
try {
con = DriverManager.getConnection(url, user, password);
st = (Statement) con.createStatement();
rs = st.executeQuery("SELECT VERSION()");
if (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Nastavnici.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Nastavnici.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
public Nastavnici() {
setTitle("Nastavnici");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("Unesi");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
NOW HOW ????
}
});
btnNewButton.setBounds(12, 12, 131, 25);
contentPane.add(btnNewButton);
JLabel lblIdNastavnika = new JLabel("id nastavnika");
lblIdNastavnika.setBounds(12, 49, 102, 15);
contentPane.add(lblIdNastavnika);
JLabel lblIme = new JLabel("ime");
lblIme.setBounds(12, 76, 70, 15);
contentPane.add(lblIme);
JLabel lblPrezime = new JLabel("prezime");
lblPrezime.setBounds(12, 103, 70, 15);
contentPane.add(lblPrezime);
JLabel lblStaz = new JLabel("staz");
lblStaz.setBounds(12, 130, 70, 15);
contentPane.add(lblStaz);
JLabel lblEmail = new JLabel("email");
lblEmail.setBounds(12, 157, 70, 15);
contentPane.add(lblEmail);
JLabel lblTelefon = new JLabel("telefon");
lblTelefon.setBounds(12, 184, 70, 15);
contentPane.add(lblTelefon);
JLabel lblOblast = new JLabel("oblast");
lblOblast.setBounds(12, 211, 70, 15);
contentPane.add(lblOblast);
tx_id_nastavnika = new JTextField();
tx_id_nastavnika.setBounds(132, 47, 114, 19);
contentPane.add(tx_id_nastavnika);
tx_id_nastavnika.setColumns(10);
txt_ime = new JTextField();
txt_ime.setBounds(69, 74, 177, 19);
contentPane.add(txt_ime);
txt_ime.setColumns(10);
txt_prezime = new JTextField();
txt_prezime.setBounds(100, 101, 146, 19);
contentPane.add(txt_prezime);
txt_prezime.setColumns(10);
txt_staz = new JTextField();
txt_staz.setBounds(69, 128, 145, 19);
contentPane.add(txt_staz);
txt_staz.setColumns(10);
txt_email = new JTextField();
txt_email.setBounds(69, 155, 214, 19);
contentPane.add(txt_email);
txt_email.setColumns(10);
txt_telefon = new JTextField();
txt_telefon.setBounds(100, 182, 167, 19);
contentPane.add(txt_telefon);
txt_telefon.setColumns(10);
txt_oblast = new JTextField();
txt_oblast.setBounds(100, 209, 167, 19);
contentPane.add(txt_oblast);
txt_oblast.setColumns(10);
}
}