Advertisement
Guest User

2 Restaurante Preferate

a guest
May 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. (MyFrame.java)
  2.  
  3. package restaurant;
  4.  
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.ResultSet;
  10. import java.util.Vector;
  11.  
  12. import javax.swing.DefaultListModel;
  13. import javax.swing.JButton;
  14. import javax.swing.JFrame;
  15. import javax.swing.JLabel;
  16. import javax.swing.JList;
  17. import javax.swing.JTextField;
  18.  
  19. import org.omg.CORBA.DomainManager;
  20.  
  21. import com.mysql.jdbc.PreparedStatement;
  22. import com.mysql.jdbc.Statement;
  23.  
  24. public class MyFrame extends JFrame{
  25.     /**
  26.      *
  27.      */
  28.     private static final long serialVersionUID = 1L;
  29.     protected JLabel lblCautare;
  30.     protected JTextField txtCautare;
  31.     protected JButton btnStergere;
  32.     protected JList lstAfisare;
  33.    
  34.     Vector<Restaurant> vctRestaurant = new Vector<Restaurant>();
  35.     DefaultListModel<String> listm = new DefaultListModel<String>();
  36.     ResultSet rs;
  37.     PreparedStatement ps;
  38.     Statement sql;
  39.     String url = "jdbc:mysql://localhost:3306/test";
  40.     //rs = sql.statementQuery("select * from test.restaurante");
  41.     //Connection con = DriverManager.getConnection(url, "root", "root"); //.DriverManager;
  42.    
  43.    
  44.     //sql = con.statementQuery("select * from test.restaurante");
  45.    
  46.     @SuppressWarnings({ "unchecked", "rawtypes" })
  47.     public MyFrame(){
  48.         JFrame MyFrame = new JFrame("Restaurante");
  49.        
  50.         MyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  51.         MyFrame.setSize(400, 500);
  52.         MyFrame.setLocation(200,200);
  53.        
  54.         lblCautare = new JLabel("Cauta restaurantul: ");
  55.         lblCautare.setBounds(20, 20, 120, 30);
  56.         txtCautare = new JTextField();
  57.         txtCautare.setBounds(140, 20, 150, 30);
  58.         btnStergere = new JButton("Sterge restaurantul");
  59.         btnStergere.setBounds(75, 100, 150, 30);
  60.         lstAfisare = new JList(listm);
  61.         lstAfisare.setBounds(20, 100, 350, 350);
  62.        
  63.         MyFrame.getContentPane().add(lblCautare);
  64.         MyFrame.getContentPane().add(txtCautare);
  65.         MyFrame.getContentPane().add(btnStergere);
  66.         MyFrame.getContentPane().add(lstAfisare);
  67.        
  68.     //  btnStergere.addActionListener(new ButonApasat);
  69.        
  70.         MyFrame.setVisible(true);
  71.        
  72.         int i = 0;
  73.         /*while(rs.next()){
  74.             vctRestaurant.add(new Restaurant(rs.getString(1), rs.getString(2), rs.getString(3)));
  75.             listm.addElement(vctRestaurant.get(i).getDenumire()+" " +vctRestaurant.get(i).getSpecific()+
  76.                     " "+vctRestaurant.get(i).getZona());
  77.             i++;
  78.         }
  79.         */
  80.         MyFrame.getContentPane().add(lstAfisare);
  81.        
  82.        
  83.         }
  84.        
  85.    
  86.     /*class ButonApasat implements ActionListener{
  87.         public void actionPerformed(ActionEvent e){
  88.             if(e.getSource().equals(btnStergere)){
  89.                 sql = con.statementQuery("delete * from test.restaurante where denumire like txtCautare");
  90.             }
  91.         }
  92.     }*/
  93.    
  94. }
  95.  
  96. (Restaurant.java)
  97.  
  98. package restaurant;
  99.  
  100. public class Restaurant {
  101.     private String denumire;
  102.     private String specific;
  103.     private String zona;
  104.    
  105.     public Restaurant(String denumire, String specific, String zona){
  106.         super();
  107.         this.setDenumire(denumire);
  108.         this.setSpecific(specific);
  109.         this.setZona(zona);
  110.     }
  111.  
  112.     public String getDenumire() {
  113.         return denumire;
  114.     }
  115.  
  116.     public void setDenumire(String denumire) {
  117.         this.denumire = denumire;
  118.     }
  119.  
  120.     public String getSpecific() {
  121.         return specific;
  122.     }
  123.  
  124.     public void setSpecific(String specific) {
  125.         this.specific = specific;
  126.     }
  127.  
  128.     public String getZona() {
  129.         return zona;
  130.     }
  131.  
  132.     public void setZona(String zona) {
  133.         this.zona = zona;
  134.     }
  135.    
  136.     public String toString(){
  137.         return "Restaurantul " + denumire + ", cu specific " + specific +
  138.                 " e situat in zona " + zona + ".";
  139.                  
  140.     }
  141. }
  142.  
  143. (MainApp.java)
  144.  
  145. package restaurant;
  146.  
  147. public class MainApp {
  148.  
  149.     public static void main(String[] args) {
  150.         // TODO Auto-generated method stub
  151.         MyFrame frm = new MyFrame();
  152.         frm.setVisible(true);
  153.     }
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement