Mitko_jos

Piramidalna nomce

Aug 26th, 2014
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.95 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package piramidalna;
  6.  
  7. import java.awt.BorderLayout;
  8. import java.awt.CardLayout;
  9. import java.awt.Color;
  10. import java.awt.GridLayout;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import javax.swing.JButton;
  14. import javax.swing.JComboBox;
  15. import javax.swing.JFrame;
  16. import javax.swing.JLabel;
  17. import javax.swing.JPanel;
  18. import javax.swing.JSlider;
  19. import javax.swing.JTextArea;
  20. import javax.swing.event.ChangeEvent;
  21. import javax.swing.event.ChangeListener;
  22.  
  23. /**
  24.  *
  25.  * @author Mitko
  26.  */
  27. public class Piramidalna extends JFrame implements ActionListener{
  28.  
  29.     JPanel p1,p2,home,main;
  30.     JComboBox<String> combo;
  31.     JTextArea txt;
  32.     JLabel iznos,welcome,conf;
  33.     JButton changeconf,b1,b2,b3,a1,a2,a3;
  34.     JSlider slider;
  35.     String[] s={"ASUS","ACER","Toshiba","DELL"};
  36.    
  37.    
  38.     public Piramidalna()
  39.     {
  40.         this.setSize(500, 500);
  41.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42.         this.setLayout(new BorderLayout());
  43.         this.setResizable(false);
  44.        
  45.         p1=new JPanel();
  46.         p2=new JPanel();
  47.         home=new JPanel();
  48.        
  49.         changeconf=new JButton("Change Configuration");
  50.         a1=new JButton("Previous");
  51.         a2=new JButton("Go Back to Home");
  52.         a3=new JButton("Next");
  53.        
  54.         b1=new JButton("Previous");
  55.         b2=new JButton("Go Back to Home");
  56.         b3=new JButton("Next");
  57.        
  58.         welcome=new JLabel("Welcome to our computer shop!!!",JLabel.CENTER);
  59.         conf=new JLabel("Your configuration costs 0$",JLabel.LEFT);
  60.         txt=new JTextArea(6,30);
  61.        
  62.         JPanel gore=new JPanel();
  63.         gore.setLayout(new BorderLayout());
  64.         gore.add(welcome,BorderLayout.NORTH);
  65.         gore.add(conf,BorderLayout.CENTER);
  66.        
  67.         home.setLayout(new BorderLayout());
  68.         home.add(gore,BorderLayout.NORTH);
  69.         home.add(txt,BorderLayout.CENTER);
  70.         home.add(changeconf,BorderLayout.SOUTH);
  71.        
  72.         combo=new JComboBox<String>(s);
  73.         combo.addActionListener(this);
  74.         p1.setLayout(new BorderLayout());
  75.         p1.add(combo,BorderLayout.NORTH);
  76.        
  77.         JPanel p1dole=new JPanel();
  78.         p1dole.setLayout(new GridLayout(1,3));
  79.         a1.setEnabled(false);
  80.         p1dole.add(a1);
  81.         p1dole.add(a2);
  82.         p1dole.add(a3);
  83.         p1.add(p1dole,BorderLayout.SOUTH);
  84.        
  85.         p2.setLayout(new BorderLayout());
  86.        
  87.         slider=new JSlider(JSlider.HORIZONTAL);
  88.         slider.setMinimum(1000);
  89.         slider.setMaximum(10000);
  90.        
  91.         iznos=new JLabel("1000MKD");
  92.        
  93.         iznos.setForeground(Color.BLUE);
  94.         iznos.setText(String.valueOf("1000MKD"));
  95.        
  96.         slider.addChangeListener(new ChangeListener() {
  97.  
  98.             @Override
  99.             public void stateChanged(ChangeEvent ce) {
  100.            JSlider slider=(JSlider) ce.getSource();
  101.            iznos.setText(String.valueOf(slider.getValue())+"MKD");
  102.                
  103.                
  104.             }
  105.         });
  106.        
  107.         JPanel p2dole=new JPanel();
  108.         p2dole.setLayout(new GridLayout(1,3));
  109.        
  110.         b3.setEnabled(false);
  111.         p2dole.add(b1);
  112.         p2dole.add(b2);
  113.       p2dole.add(b3);
  114.        
  115.       p2.add(slider,BorderLayout.NORTH);
  116.       p2.add(iznos,BorderLayout.CENTER);
  117.       p2.add(p2dole,BorderLayout.SOUTH);
  118.      
  119.         CardLayout crd=new CardLayout();
  120.      
  121.       crd.addLayoutComponent(home,"Home");
  122.          crd.addLayoutComponent(p1,"LapTop");
  123.        crd.addLayoutComponent(p2,"Slide");
  124.       main=new JPanel(crd);
  125.      
  126.       a2.addActionListener(new ActionListener() {
  127.  
  128.             @Override
  129.             public void actionPerformed(ActionEvent ae) {
  130.                 CardLayout crd=(CardLayout) main.getLayout();
  131.                 crd.show(main,"Home");
  132.                
  133.                
  134.             }
  135.         });
  136.      
  137.       a3.addActionListener(new ActionListener() {
  138.  
  139.             @Override
  140.             public void actionPerformed(ActionEvent ae) {
  141.                
  142.                  CardLayout crd=(CardLayout) main.getLayout();
  143.                 crd.next(main);
  144.                
  145.             }
  146.         });
  147.      
  148.       b1.addActionListener(new ActionListener() {
  149.  
  150.             @Override
  151.             public void actionPerformed(ActionEvent ae) {
  152.            
  153.                  CardLayout crd=(CardLayout) main.getLayout();
  154.                  crd.previous(main);
  155.                
  156.             }
  157.         });
  158.      
  159.      
  160.        b2.addActionListener(new ActionListener() {
  161.  
  162.             @Override
  163.             public void actionPerformed(ActionEvent ae) {
  164.            
  165.                  CardLayout crd=(CardLayout) main.getLayout();
  166.                  crd.show(main,"Home");
  167.                
  168.             }
  169.         });
  170.        
  171.        changeconf.addActionListener(new ActionListener() {
  172.  
  173.             @Override
  174.             public void actionPerformed(ActionEvent ae) {
  175.            
  176.                  CardLayout crd=(CardLayout) main.getLayout();
  177.                  crd.show(main,"LapTop");
  178.                
  179.             }
  180.         });
  181.      
  182.       main.add(home);
  183.        main.add(p1);
  184.        main.add(p2);
  185.      
  186.        this.getContentPane().add(main);
  187.      
  188.      
  189.        
  190.     }
  191.    
  192.    
  193.     public static void main(String[] args) {
  194.        Piramidalna p=new Piramidalna();
  195.        p.setVisible(true);
  196.        
  197.        
  198.     }
  199.  
  200.     @Override
  201.     public void actionPerformed(ActionEvent ae) {
  202.          
  203.         int sum=0;
  204.         String s="";
  205.         sum+=slider.getValue();
  206.         s+=combo.getSelectedItem().toString()+"\n";
  207.        
  208.             if(combo.getSelectedItem().toString().equals("ASUS")){
  209.                 sum+=11250;
  210.                
  211.             }
  212.         txt.setText(s);
  213.         conf.setText(String.format("Your configuration costs %d",sum));
  214.        
  215.     }
  216. }
Advertisement
Add Comment
Please, Sign In to add comment