Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (MyFrame.java)
- package restaurant;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.util.Vector;
- import javax.swing.DefaultListModel;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JTextField;
- import org.omg.CORBA.DomainManager;
- import com.mysql.jdbc.PreparedStatement;
- import com.mysql.jdbc.Statement;
- public class MyFrame extends JFrame{
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- protected JLabel lblCautare;
- protected JTextField txtCautare;
- protected JButton btnStergere;
- protected JList lstAfisare;
- Vector<Restaurant> vctRestaurant = new Vector<Restaurant>();
- DefaultListModel<String> listm = new DefaultListModel<String>();
- ResultSet rs;
- PreparedStatement ps;
- Statement sql;
- String url = "jdbc:mysql://localhost:3306/test";
- //rs = sql.statementQuery("select * from test.restaurante");
- //Connection con = DriverManager.getConnection(url, "root", "root"); //.DriverManager;
- //sql = con.statementQuery("select * from test.restaurante");
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public MyFrame(){
- JFrame MyFrame = new JFrame("Restaurante");
- MyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- MyFrame.setSize(400, 500);
- MyFrame.setLocation(200,200);
- lblCautare = new JLabel("Cauta restaurantul: ");
- lblCautare.setBounds(20, 20, 120, 30);
- txtCautare = new JTextField();
- txtCautare.setBounds(140, 20, 150, 30);
- btnStergere = new JButton("Sterge restaurantul");
- btnStergere.setBounds(75, 100, 150, 30);
- lstAfisare = new JList(listm);
- lstAfisare.setBounds(20, 100, 350, 350);
- MyFrame.getContentPane().add(lblCautare);
- MyFrame.getContentPane().add(txtCautare);
- MyFrame.getContentPane().add(btnStergere);
- MyFrame.getContentPane().add(lstAfisare);
- // btnStergere.addActionListener(new ButonApasat);
- MyFrame.setVisible(true);
- int i = 0;
- /*while(rs.next()){
- vctRestaurant.add(new Restaurant(rs.getString(1), rs.getString(2), rs.getString(3)));
- listm.addElement(vctRestaurant.get(i).getDenumire()+" " +vctRestaurant.get(i).getSpecific()+
- " "+vctRestaurant.get(i).getZona());
- i++;
- }
- */
- MyFrame.getContentPane().add(lstAfisare);
- }
- /*class ButonApasat implements ActionListener{
- public void actionPerformed(ActionEvent e){
- if(e.getSource().equals(btnStergere)){
- sql = con.statementQuery("delete * from test.restaurante where denumire like txtCautare");
- }
- }
- }*/
- }
- (Restaurant.java)
- package restaurant;
- public class Restaurant {
- private String denumire;
- private String specific;
- private String zona;
- public Restaurant(String denumire, String specific, String zona){
- super();
- this.setDenumire(denumire);
- this.setSpecific(specific);
- this.setZona(zona);
- }
- public String getDenumire() {
- return denumire;
- }
- public void setDenumire(String denumire) {
- this.denumire = denumire;
- }
- public String getSpecific() {
- return specific;
- }
- public void setSpecific(String specific) {
- this.specific = specific;
- }
- public String getZona() {
- return zona;
- }
- public void setZona(String zona) {
- this.zona = zona;
- }
- public String toString(){
- return "Restaurantul " + denumire + ", cu specific " + specific +
- " e situat in zona " + zona + ".";
- }
- }
- (MainApp.java)
- package restaurant;
- public class MainApp {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- MyFrame frm = new MyFrame();
- frm.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement