Mitko_jos

lab04_ia verzija moja

Nov 20th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.50 KB | None | 0 0
  1.  
  2. //prethodno stavi gi klasite book i database
  3.  
  4. /*
  5.  * To change this template, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8. package ia_lab4;
  9.  
  10. import java.awt.BorderLayout;
  11. import java.awt.GridLayout;
  12. import java.awt.Image;
  13. import javax.swing.ImageIcon;
  14. import javax.swing.JFrame;
  15. import javax.swing.JLabel;
  16. import javax.swing.JList;
  17. import javax.swing.JPanel;
  18. import javax.swing.JTextField;
  19. import javax.swing.border.TitledBorder;
  20. import javax.swing.event.ListSelectionEvent;
  21. import javax.swing.event.ListSelectionListener;
  22.  
  23. /**
  24.  *
  25.  * @author Mitko
  26.  */
  27. public class IA_lab4 {
  28.  
  29.     JFrame ramka;
  30.     JPanel p1,p2,p3,p4;
  31.     JList list;
  32.     JTextField f1;
  33.     JTextField f2;
  34.     JTextField f3;
  35.     JTextField f4;
  36.     JTextField f5;
  37.     JLabel lb21;
  38.     JPanel pn22;
  39.     JLabel l1;
  40.     JLabel l2;
  41.     JLabel l3;
  42.     JLabel l4;
  43.     JLabel l5;
  44.     JPanel pn2;
  45.    
  46.    
  47.    
  48.     public IA_lab4()
  49.     {
  50.     ramka=new JFrame();
  51.         ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  52.         ramka.setLayout(new BorderLayout());
  53.        ramka.setSize(250,250);
  54.    
  55.    
  56.         Database[] pcs=(Book)Database.initDatabase();
  57.         Book[] x=Database.getBooks();
  58.       list=new JList(x);
  59.       list.setBorder(new TitledBorder("Book List: "));
  60.       list.addListSelectionListener(new ListSelectionListener() {
  61.  
  62.             @Override
  63.             public void valueChanged(ListSelectionEvent e) {
  64.                 Book pc=(Book) list.getSelectedValue();
  65.         ImageIcon ic=new ImageIcon(pc.getPicture());
  66.         Image im=ic.getImage();
  67.         im=im.getScaledInstance(200,200,Image.SCALE_SMOOTH);
  68.        
  69.         ic=new ImageIcon(im);
  70.         lb21.setIcon(ic);
  71.         f1.setText(pc.getTitle());
  72.         f2.setText(pc.getISBN());
  73.         //f3.setText(pc.getYear());
  74.         f4.setText(pc.getPublisher());
  75.        // f5.setText(pc.getCena());
  76.             }
  77.  
  78.            
  79.         });
  80.      
  81.       pn2=new JPanel(new GridLayout(2,1));
  82.      
  83.       pn22=new JPanel(new GridLayout(10,1));
  84.       l1=new JLabel("Title: ");
  85.       l2=new JLabel("ISBN: ");
  86.       l3=new JLabel("Year: ");
  87.       l4=new JLabel("Publisher: ");
  88.      // l5=new JLabel("Price: ");
  89.       f1=new JTextField();
  90.       f2=new JTextField();
  91.       f3=new JTextField();
  92.       f4=new JTextField();
  93.      // f5=new JTextField();
  94.       pn22.add(l1);
  95.       pn22.add(f1);
  96.       pn22.add(l2);
  97.       pn22.add(f2);
  98.       pn22.add(l3);
  99.       pn22.add(f3);
  100.       pn22.add(l4);
  101.       pn22.add(f4);
  102.       pn22.add(l5);
  103.       pn22.add(f5);
  104.      
  105.       lb21=new JLabel();
  106.      
  107.      
  108.      
  109.      
  110.  
  111.        
  112.        
  113.        pn2.add(lb21);
  114.        pn2.add(pn22);
  115.       ramka.getContentPane().add(list);
  116.        ramka.getContentPane().add(pn2);
  117.        
  118.        
  119.        
  120.        
  121.        
  122.        
  123.        
  124.        
  125.        
  126.        
  127.        
  128.        
  129.        
  130.        
  131.        
  132.        
  133.        
  134.        
  135.        
  136.        
  137.        
  138.        
  139.        
  140.        
  141.        
  142.        
  143.        
  144.        
  145.        
  146.        
  147.        
  148.        
  149.        
  150.        
  151.        
  152.        
  153.        
  154.        
  155.        
  156.        
  157.        
  158.        
  159.        
  160.        
  161.        
  162.        
  163.        
  164.         ramka.setVisible(true);
  165.        
  166.     }
  167.    
  168.    
  169.    
  170.    
  171.    
  172.    
  173.    
  174.    
  175.    
  176.    
  177.    
  178.    
  179.    
  180.    
  181.    
  182.    
  183.    
  184.     public static void main(String[] args) {
  185.         // TODO code application logic here
  186.         IA_lab4 ramka=new IA_lab4();
  187.        
  188.     }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment