Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.32 KB | None | 0 0
  1. package Pack1;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.FlowLayout;
  7. import java.util.Comparator;
  8. import java.util.Vector;
  9.  
  10. import javax.swing.BoxLayout;
  11. import javax.swing.DefaultListModel;
  12. import javax.swing.JButton;
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15. import javax.swing.JList;
  16. import javax.swing.JPanel;
  17. import javax.swing.JTextField;
  18.  
  19. class MyFrame extends JFrame
  20. {
  21. private JTextField txtTitlu;
  22. private JTextField txtAutor;
  23. private JTextField txtAn;
  24. private JButton btnAdaugare;
  25. private JButton btnAfisare;
  26. private JButton btnAfisareo;
  27. DefaultListModel<String> myModel;
  28. JList<String> myList;
  29.  
  30.  
  31. public MyFrame()
  32. {
  33. super("Carti");
  34. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  35. setLocation(400,400);
  36. setSize(470, 440);
  37. getContentPane().setLayout(null);
  38. JLabel lblTitlu=new JLabel("Titlu");
  39. txtTitlu=new JTextField();
  40. JLabel lblAutor=new JLabel("Autor");
  41. txtAutor=new JTextField();
  42. JLabel lblAn=new JLabel("An");
  43. txtAn=new JTextField();
  44. btnAdaugare=new JButton("Adaugare");
  45. btnAfisare=new JButton("Afisare");
  46. btnAfisareo=new JButton("Afisare ordonata");
  47. myModel=new DefaultListModel<String>();
  48. myList=new JList<String>();
  49.  
  50.  
  51. lblTitlu.setBounds(20,10,70,20);
  52. txtTitlu.setBounds(90, 10, 150, 20);
  53. lblAutor.setBounds(20,40,70,20);
  54. txtAutor.setBounds(90, 40, 150, 20);
  55. lblAn.setBounds(20,70,70,20);
  56. txtAn.setBounds(90, 70, 150, 20);
  57. btnAdaugare.setBounds(20, 100, 100, 20);
  58. btnAfisare.setBounds(140, 100, 100, 20);
  59. btnAfisareo.setBounds(260, 100, 130, 20);
  60. myList.setBounds(20,130, 360, 150);
  61. getContentPane(). add(myList);
  62. getContentPane().add(lblTitlu);
  63. getContentPane().add(txtTitlu);
  64. getContentPane().add(lblAutor);
  65. getContentPane().add(txtAutor);
  66. getContentPane().add(lblAn);
  67. getContentPane().add(txtAn);
  68. getContentPane().add(btnAdaugare);
  69. getContentPane().add(btnAfisare);
  70. getContentPane().add(btnAfisareo);
  71. btnAdaugare.addActionListener(new ButonApasat());
  72. btnAfisare.addActionListener(new ButonApasat());
  73. btnAfisareo.addActionListener(new ButonApasat());
  74. setVisible(true);
  75.  
  76.  
  77. }
  78. Vector<Carte>carti = new Vector<>();
  79. class ButonApasat implements ActionListener
  80. {
  81. public void actionPerformed(ActionEvent e) {
  82. // TODO Auto-generated method stub
  83. JButton source = (JButton) e.getSource();
  84.  
  85. if (source == btnAdaugare)
  86. {
  87. String titlu = txtTitlu.getText();
  88. String autor = txtAutor.getText();
  89. int an = Integer.parseInt(txtAn.getText());
  90.  
  91. Carte c = new Carte(titlu,autor,an);
  92.  
  93.  
  94. carti.add(c);
  95. System.out.println("Am reusit ");
  96. txtTitlu.setText("");
  97. txtAutor.setText("");
  98. txtAn.setText("");
  99. }
  100. if (source == btnAfisare)
  101. {myModel.clear();
  102. for (int i=0; i<carti.size(); i++)
  103. {
  104.  
  105. Carte cr = (Carte) carti.elementAt(i);
  106. myModel.addElement(cr.toString());
  107. myList.setModel(myModel);
  108.  
  109. }
  110. }
  111. if (source == btnAfisareo)
  112. {
  113. System.out.println("Am ajuns aici");
  114. myModel.clear();
  115. carti.sort(Comparator.comparing(Carte::getTitlu));
  116. for (int i=0; i<carti.size(); i++)
  117. {
  118.  
  119. Carte cr = (Carte) carti.elementAt(i);
  120. myModel.addElement(cr.toString());
  121. myList.setModel(myModel);
  122.  
  123. }
  124. }
  125. }
  126. public DefaultListModel<String> getModel() {
  127. return myModel;
  128. }
  129. }
  130. }
  131.  
  132. package grafica;
  133.  
  134. public class Carte {
  135. private String titlu;
  136. private String autor;
  137. private int an;
  138. public Carte(String titlu,String autor,int an)
  139. {
  140. this.titlu=titlu;
  141. this.autor=autor;
  142. this.an=an;
  143. }
  144. public String getTitlu() {
  145. return titlu;
  146. }
  147. public void setTitlu(String titlu) {
  148. this.titlu = titlu;
  149. }
  150. public String getAutor() {
  151. return autor;
  152. }
  153. public void setAutor(String autor) {
  154. this.autor = autor;
  155. }
  156. public int getAn() {
  157. return an;
  158. }
  159. public void setAn(int an) {
  160. this.an = an;
  161. }
  162. @Override
  163. public String toString() {
  164. return "titlu=" + getTitlu() + ", autor=" + getAutor() + ", an=" +getAn() + "]";
  165. }
  166.  
  167. }
  168. package grafica;
  169.  
  170.  
  171.  
  172. public class MainAPP {
  173.  
  174. public static void main(String[] args) {
  175. // TODO Auto-generated method stub
  176. MyFrame frm = new MyFrame();
  177. frm.setVisible(true);
  178. }
  179.  
  180. }
  181.  
  182.  
  183. package Subiect3;
  184.  
  185. import java.awt.Dimension;
  186. import java.awt.FlowLayout;
  187. import java.awt.event.ActionEvent;
  188. import java.awt.event.ActionListener;
  189. import java.sql.Connection;
  190. import java.sql.DriverManager;
  191. import java.sql.ResultSet;
  192. import java.sql.SQLException;
  193. import java.sql.Statement;
  194. import java.util.Iterator;
  195. import java.util.Vector;
  196.  
  197. import javax.swing.JButton;
  198. import javax.swing.JFrame;
  199. import javax.swing.JLabel;
  200. import javax.swing.JTextArea;
  201. import javax.swing.JTextField;
  202.  
  203. public class Interfata extends JFrame {
  204. public static JTextArea txtareaAfis = new JTextArea();
  205. public static Vector<Restaurant> lista = new Vector<Restaurant>();
  206. public static JLabel lblStergere = new JLabel("Stergere");
  207. public static JButton btnStergere = new JButton("Sterge");
  208. public static JTextField txtStergere = new JTextField();
  209.  
  210. public Interfata() throws SQLException
  211. {
  212. setSize(500,500);
  213. setVisible(true);
  214.  
  215. String url = "jdbc:mysql://localhost:3306/test";
  216. Connection con = DriverManager.getConnection (url, "root", "root");
  217. Statement sql;
  218. sql = (Statement)con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  219. ResultSet rs;
  220. rs = sql.executeQuery("SELECT *FROM restaurante");
  221. while(rs.next())
  222. {
  223. Restaurant r = new Restaurant(rs.getString("Denumire"), rs.getString("Specific"), rs.getString("Zona"));
  224. txtareaAfis.setText(txtareaAfis.getText()+r.toString()+"\n");
  225. lista.add(r);
  226. }
  227. lblStergere.setPreferredSize(new Dimension(200,20));
  228. txtStergere.setPreferredSize(new Dimension(100,20));
  229. btnStergere.setPreferredSize(new Dimension(170,30));
  230. txtareaAfis.setPreferredSize(new Dimension(480,300));
  231. getContentPane().add(txtareaAfis);
  232. getContentPane().add(lblStergere);
  233. getContentPane().add(txtStergere);
  234. getContentPane().add(btnStergere);
  235.  
  236. getContentPane().setLayout(new FlowLayout());
  237. }
  238. }
  239.  
  240. //Hello.java
  241. package exemplu2;
  242. import java.io.IOException;
  243. import java.io.PrintWriter;
  244. import javax.servlet.ServletException;
  245. import javax.servlet.annotation.WebServlet;
  246. import javax.servlet.http.HttpServlet;
  247. import javax.servlet.http.HttpServletRequest;
  248. import javax.servlet.http.HttpServletResponse;
  249. /**
  250. * Servlet implementation class Hello
  251. */
  252. @WebServlet("/Hello")
  253. public class Hello extends HttpServlet {
  254. private static final long serialVersionUID = 1L;
  255. /**
  256. * @see HttpServlet#HttpServlet()
  257. */
  258. public Hello() {
  259. super();
  260. // TODO Auto-generated constructor stub
  261. }
  262. /**
  263. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  264. */
  265. protected void doGet(HttpServletRequest request, HttpServletResponse
  266. response) throws ServletException, IOException {
  267. PrintWriter pw=response.getWriter();
  268. pw.println(""
  269. +"Buna!");
  270. }
  271. /**
  272. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  273. */
  274. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
  275. ServletException, IOException {
  276. // TODO Auto-generated method stub
  277. }
  278. }
  279. //Calcul.java
  280.  
  281. package exemplu2;
  282. import java.io.*;
  283. import javax.servlet.*;
  284. import javax.servlet.annotation.WebServlet;
  285. import javax.servlet.http.*;
  286. @WebServlet("/Calcul")
  287. public class Calcul extends HttpServlet {
  288. private static final long serialVersionUID = 1L;
  289. public Calcul() {
  290. super();
  291. }
  292. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  293. throws ServletException, IOException {
  294. String nr1=request.getParameter("nr1");
  295. String nr2=request.getParameter("nr2");
  296. int x=Integer.parseInt(nr1);
  297. int y=Integer.parseInt(nr2);
  298. int suma=x+y;
  299. PrintWriter out = response.getWriter();
  300. out.println("" );
  301. out.println("Suma numerelor este "+suma+"");
  302. }
  303. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  304. throws ServletException, IOException {
  305. }
  306. }
  307. //numere.html - var din curs
  308.  
  309. //Persoana.java
  310. package exemplu2;
  311. import java.util.Calendar;
  312. public class Persoana {
  313. private String numPrenum;
  314. private Calendar data_nasterii;
  315. private String adresa;
  316. private long telefon;
  317. public void Persona(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement