Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Pack1;
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.FlowLayout;
- import java.util.Comparator;
- import java.util.Vector;
- import javax.swing.BoxLayout;
- import javax.swing.DefaultListModel;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- class MyFrame extends JFrame
- {
- private JTextField txtTitlu;
- private JTextField txtAutor;
- private JTextField txtAn;
- private JButton btnAdaugare;
- private JButton btnAfisare;
- private JButton btnAfisareo;
- DefaultListModel<String> myModel;
- JList<String> myList;
- public MyFrame()
- {
- super("Carti");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLocation(400,400);
- setSize(470, 440);
- getContentPane().setLayout(null);
- JLabel lblTitlu=new JLabel("Titlu");
- txtTitlu=new JTextField();
- JLabel lblAutor=new JLabel("Autor");
- txtAutor=new JTextField();
- JLabel lblAn=new JLabel("An");
- txtAn=new JTextField();
- btnAdaugare=new JButton("Adaugare");
- btnAfisare=new JButton("Afisare");
- btnAfisareo=new JButton("Afisare ordonata");
- myModel=new DefaultListModel<String>();
- myList=new JList<String>();
- lblTitlu.setBounds(20,10,70,20);
- txtTitlu.setBounds(90, 10, 150, 20);
- lblAutor.setBounds(20,40,70,20);
- txtAutor.setBounds(90, 40, 150, 20);
- lblAn.setBounds(20,70,70,20);
- txtAn.setBounds(90, 70, 150, 20);
- btnAdaugare.setBounds(20, 100, 100, 20);
- btnAfisare.setBounds(140, 100, 100, 20);
- btnAfisareo.setBounds(260, 100, 130, 20);
- myList.setBounds(20,130, 360, 150);
- getContentPane(). add(myList);
- getContentPane().add(lblTitlu);
- getContentPane().add(txtTitlu);
- getContentPane().add(lblAutor);
- getContentPane().add(txtAutor);
- getContentPane().add(lblAn);
- getContentPane().add(txtAn);
- getContentPane().add(btnAdaugare);
- getContentPane().add(btnAfisare);
- getContentPane().add(btnAfisareo);
- btnAdaugare.addActionListener(new ButonApasat());
- btnAfisare.addActionListener(new ButonApasat());
- btnAfisareo.addActionListener(new ButonApasat());
- setVisible(true);
- }
- Vector<Carte>carti = new Vector<>();
- class ButonApasat implements ActionListener
- {
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- JButton source = (JButton) e.getSource();
- if (source == btnAdaugare)
- {
- String titlu = txtTitlu.getText();
- String autor = txtAutor.getText();
- int an = Integer.parseInt(txtAn.getText());
- Carte c = new Carte(titlu,autor,an);
- carti.add(c);
- System.out.println("Am reusit ");
- txtTitlu.setText("");
- txtAutor.setText("");
- txtAn.setText("");
- }
- if (source == btnAfisare)
- {myModel.clear();
- for (int i=0; i<carti.size(); i++)
- {
- Carte cr = (Carte) carti.elementAt(i);
- myModel.addElement(cr.toString());
- myList.setModel(myModel);
- }
- }
- if (source == btnAfisareo)
- {
- System.out.println("Am ajuns aici");
- myModel.clear();
- carti.sort(Comparator.comparing(Carte::getTitlu));
- for (int i=0; i<carti.size(); i++)
- {
- Carte cr = (Carte) carti.elementAt(i);
- myModel.addElement(cr.toString());
- myList.setModel(myModel);
- }
- }
- }
- public DefaultListModel<String> getModel() {
- return myModel;
- }
- }
- }
- package grafica;
- public class Carte {
- private String titlu;
- private String autor;
- private int an;
- public Carte(String titlu,String autor,int an)
- {
- this.titlu=titlu;
- this.autor=autor;
- this.an=an;
- }
- public String getTitlu() {
- return titlu;
- }
- public void setTitlu(String titlu) {
- this.titlu = titlu;
- }
- public String getAutor() {
- return autor;
- }
- public void setAutor(String autor) {
- this.autor = autor;
- }
- public int getAn() {
- return an;
- }
- public void setAn(int an) {
- this.an = an;
- }
- @Override
- public String toString() {
- return "titlu=" + getTitlu() + ", autor=" + getAutor() + ", an=" +getAn() + "]";
- }
- }
- package grafica;
- public class MainAPP {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- MyFrame frm = new MyFrame();
- frm.setVisible(true);
- }
- }
- package Subiect3;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- 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.sql.Statement;
- import java.util.Iterator;
- import java.util.Vector;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- public class Interfata extends JFrame {
- public static JTextArea txtareaAfis = new JTextArea();
- public static Vector<Restaurant> lista = new Vector<Restaurant>();
- public static JLabel lblStergere = new JLabel("Stergere");
- public static JButton btnStergere = new JButton("Sterge");
- public static JTextField txtStergere = new JTextField();
- public Interfata() throws SQLException
- {
- setSize(500,500);
- setVisible(true);
- String url = "jdbc:mysql://localhost:3306/test";
- Connection con = DriverManager.getConnection (url, "root", "root");
- Statement sql;
- sql = (Statement)con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
- ResultSet rs;
- rs = sql.executeQuery("SELECT *FROM restaurante");
- while(rs.next())
- {
- Restaurant r = new Restaurant(rs.getString("Denumire"), rs.getString("Specific"), rs.getString("Zona"));
- txtareaAfis.setText(txtareaAfis.getText()+r.toString()+"\n");
- lista.add(r);
- }
- lblStergere.setPreferredSize(new Dimension(200,20));
- txtStergere.setPreferredSize(new Dimension(100,20));
- btnStergere.setPreferredSize(new Dimension(170,30));
- txtareaAfis.setPreferredSize(new Dimension(480,300));
- getContentPane().add(txtareaAfis);
- getContentPane().add(lblStergere);
- getContentPane().add(txtStergere);
- getContentPane().add(btnStergere);
- getContentPane().setLayout(new FlowLayout());
- }
- }
- //Hello.java
- package exemplu2;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- * Servlet implementation class Hello
- */
- @WebServlet("/Hello")
- public class Hello extends HttpServlet {
- private static final long serialVersionUID = 1L;
- /**
- * @see HttpServlet#HttpServlet()
- */
- public Hello() {
- super();
- // TODO Auto-generated constructor stub
- }
- /**
- * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse
- response) throws ServletException, IOException {
- PrintWriter pw=response.getWriter();
- pw.println(""
- +"Buna!");
- }
- /**
- * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
- ServletException, IOException {
- // TODO Auto-generated method stub
- }
- }
- //Calcul.java
- package exemplu2;
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.*;
- @WebServlet("/Calcul")
- public class Calcul extends HttpServlet {
- private static final long serialVersionUID = 1L;
- public Calcul() {
- super();
- }
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- String nr1=request.getParameter("nr1");
- String nr2=request.getParameter("nr2");
- int x=Integer.parseInt(nr1);
- int y=Integer.parseInt(nr2);
- int suma=x+y;
- PrintWriter out = response.getWriter();
- out.println("" );
- out.println("Suma numerelor este "+suma+"");
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- }
- }
- //numere.html - var din curs
- //Persoana.java
- package exemplu2;
- import java.util.Calendar;
- public class Persoana {
- private String numPrenum;
- private Calendar data_nasterii;
- private String adresa;
- private long telefon;
- public void Persona(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement