Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package piramidalna;
- import java.awt.BorderLayout;
- import java.awt.CardLayout;
- import java.awt.Color;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JSlider;
- import javax.swing.JTextArea;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- /**
- *
- * @author Mitko
- */
- public class Piramidalna extends JFrame implements ActionListener{
- JPanel p1,p2,home,main;
- JComboBox<String> combo;
- JTextArea txt;
- JLabel iznos,welcome,conf;
- JButton changeconf,b1,b2,b3,a1,a2,a3;
- JSlider slider;
- String[] s={"ASUS","ACER","Toshiba","DELL"};
- public Piramidalna()
- {
- this.setSize(500, 500);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setLayout(new BorderLayout());
- this.setResizable(false);
- p1=new JPanel();
- p2=new JPanel();
- home=new JPanel();
- changeconf=new JButton("Change Configuration");
- a1=new JButton("Previous");
- a2=new JButton("Go Back to Home");
- a3=new JButton("Next");
- b1=new JButton("Previous");
- b2=new JButton("Go Back to Home");
- b3=new JButton("Next");
- welcome=new JLabel("Welcome to our computer shop!!!",JLabel.CENTER);
- conf=new JLabel("Your configuration costs 0$",JLabel.LEFT);
- txt=new JTextArea(6,30);
- JPanel gore=new JPanel();
- gore.setLayout(new BorderLayout());
- gore.add(welcome,BorderLayout.NORTH);
- gore.add(conf,BorderLayout.CENTER);
- home.setLayout(new BorderLayout());
- home.add(gore,BorderLayout.NORTH);
- home.add(txt,BorderLayout.CENTER);
- home.add(changeconf,BorderLayout.SOUTH);
- combo=new JComboBox<String>(s);
- combo.addActionListener(this);
- p1.setLayout(new BorderLayout());
- p1.add(combo,BorderLayout.NORTH);
- JPanel p1dole=new JPanel();
- p1dole.setLayout(new GridLayout(1,3));
- a1.setEnabled(false);
- p1dole.add(a1);
- p1dole.add(a2);
- p1dole.add(a3);
- p1.add(p1dole,BorderLayout.SOUTH);
- p2.setLayout(new BorderLayout());
- slider=new JSlider(JSlider.HORIZONTAL);
- slider.setMinimum(1000);
- slider.setMaximum(10000);
- iznos=new JLabel("1000MKD");
- iznos.setForeground(Color.BLUE);
- iznos.setText(String.valueOf("1000MKD"));
- slider.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent ce) {
- JSlider slider=(JSlider) ce.getSource();
- iznos.setText(String.valueOf(slider.getValue())+"MKD");
- }
- });
- JPanel p2dole=new JPanel();
- p2dole.setLayout(new GridLayout(1,3));
- b3.setEnabled(false);
- p2dole.add(b1);
- p2dole.add(b2);
- p2dole.add(b3);
- p2.add(slider,BorderLayout.NORTH);
- p2.add(iznos,BorderLayout.CENTER);
- p2.add(p2dole,BorderLayout.SOUTH);
- CardLayout crd=new CardLayout();
- crd.addLayoutComponent(home,"Home");
- crd.addLayoutComponent(p1,"LapTop");
- crd.addLayoutComponent(p2,"Slide");
- main=new JPanel(crd);
- a2.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent ae) {
- CardLayout crd=(CardLayout) main.getLayout();
- crd.show(main,"Home");
- }
- });
- a3.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent ae) {
- CardLayout crd=(CardLayout) main.getLayout();
- crd.next(main);
- }
- });
- b1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent ae) {
- CardLayout crd=(CardLayout) main.getLayout();
- crd.previous(main);
- }
- });
- b2.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent ae) {
- CardLayout crd=(CardLayout) main.getLayout();
- crd.show(main,"Home");
- }
- });
- changeconf.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent ae) {
- CardLayout crd=(CardLayout) main.getLayout();
- crd.show(main,"LapTop");
- }
- });
- main.add(home);
- main.add(p1);
- main.add(p2);
- this.getContentPane().add(main);
- }
- public static void main(String[] args) {
- Piramidalna p=new Piramidalna();
- p.setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent ae) {
- int sum=0;
- String s="";
- sum+=slider.getValue();
- s+=combo.getSelectedItem().toString()+"\n";
- if(combo.getSelectedItem().toString().equals("ASUS")){
- sum+=11250;
- }
- txt.setText(s);
- conf.setText(String.format("Your configuration costs %d",sum));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment