Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- public class Forma1 {
- /**
- * @param args
- */
- private static final Insets insets= new Insets(0,0,5,0);
- static JLabel actual = new JLabel("Actual Price:");
- static JLabel price = new JLabel("200$");
- public static void okForma(int cena){
- JFrame ramka = new JFrame();
- Container contentPane= ramka.getContentPane();
- SpringLayout layout = new SpringLayout();
- ramka.setLayout(layout);
- ramka.setSize(600,600);
- JLabel tekst = new JLabel("IMA KOMJUTER ZA");
- tekst.setSize(600, 40);
- tekst.setHorizontalAlignment(JLabel.CENTER);
- tekst.setFont(new Font("Serif", Font.BOLD, 40));
- tekst.setForeground(Color.blue);
- JLabel tekst2 = new JLabel("TOCNO "+cena+"$");
- tekst2.setSize(600, 40);
- tekst2.setHorizontalAlignment(JLabel.CENTER);
- tekst2.setFont(new Font("Serif", Font.BOLD, 40));
- tekst2.setForeground(Color.blue);
- ramka.add(tekst);
- ramka.add(tekst2);
- layout.putConstraint(SpringLayout.NORTH, tekst, 200, SpringLayout.NORTH, contentPane);
- layout.putConstraint(SpringLayout.NORTH, tekst2, 80, SpringLayout.NORTH, tekst);
- layout.putConstraint(SpringLayout.WEST, tekst, 80, SpringLayout.WEST, contentPane);
- layout.putConstraint(SpringLayout.WEST, tekst2, 150, SpringLayout.WEST, contentPane);
- ramka.setVisible(true);
- }
- public static void nookForma(){
- JFrame ramka = new JFrame();
- Container contentPane= ramka.getContentPane();
- SpringLayout layout = new SpringLayout();
- ramka.setLayout(layout);
- ramka.setSize(600,600);
- JLabel tekst = new JLabel("NEMA KOMJUTER");
- tekst.setSize(600, 40);
- tekst.setHorizontalAlignment(JLabel.CENTER);
- tekst.setFont(new Font("Serif", Font.BOLD, 40));
- tekst.setForeground(Color.red);
- JLabel tekst2 = new JLabel("SO TAKVI BARANJA");
- tekst2.setSize(600, 40);
- tekst2.setHorizontalAlignment(JLabel.CENTER);
- tekst2.setFont(new Font("Serif", Font.BOLD, 40));
- tekst2.setForeground(Color.red);
- ramka.add(tekst);
- ramka.add(tekst2);
- layout.putConstraint(SpringLayout.NORTH, tekst, 200, SpringLayout.NORTH, contentPane);
- layout.putConstraint(SpringLayout.NORTH, tekst2, 80, SpringLayout.NORTH, tekst);
- layout.putConstraint(SpringLayout.WEST, tekst, 100, SpringLayout.WEST, contentPane);
- layout.putConstraint(SpringLayout.WEST, tekst2, 80, SpringLayout.WEST, contentPane);
- ramka.setVisible(true);
- }
- public static void orderForma(String ime, String prezime, String address){
- JFrame ramka = new JFrame();
- Container contentPane= ramka.getContentPane();
- SpringLayout layout = new SpringLayout();
- ramka.setLayout(layout);
- ramka.setSize(600,600);
- JLabel tekst = new JLabel("GO PRATIV KOMJUTEROT");
- tekst.setSize(600, 40);
- tekst.setHorizontalAlignment(JLabel.CENTER);
- tekst.setFont(new Font("Serif", Font.BOLD, 40));
- tekst.setForeground(Color.green);
- JLabel tekst2 = new JLabel("KAJ: "+ime+" "+prezime);
- tekst2.setSize(600, 40);
- tekst2.setHorizontalAlignment(JLabel.CENTER);
- tekst2.setFont(new Font("Serif", Font.BOLD, 40));
- tekst2.setForeground(Color.green);
- JLabel tekst3 = new JLabel("ADRESA: "+address);
- tekst3.setSize(600, 40);
- tekst3.setHorizontalAlignment(JLabel.CENTER);
- tekst3.setFont(new Font("Serif", Font.BOLD, 40));
- tekst3.setForeground(Color.green);
- ramka.add(tekst);
- ramka.add(tekst2);
- ramka.add(tekst3);
- layout.putConstraint(SpringLayout.NORTH, tekst, 200, SpringLayout.NORTH, contentPane);
- layout.putConstraint(SpringLayout.NORTH, tekst2, 80, SpringLayout.NORTH, tekst);
- layout.putConstraint(SpringLayout.NORTH, tekst3, 80, SpringLayout.NORTH, tekst2);
- layout.putConstraint(SpringLayout.WEST, tekst, 30, SpringLayout.WEST, contentPane);
- layout.putConstraint(SpringLayout.WEST, tekst2, Integer.valueOf((600-tekst2.getWidth())/2), SpringLayout.WEST, contentPane);
- layout.putConstraint(SpringLayout.WEST, tekst3, Integer.valueOf((600-tekst3.getWidth())/2), SpringLayout.WEST, contentPane);
- ramka.setVisible(true);
- }
- public static void NovaForma(){
- JFrame forma = new JFrame();
- forma.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- forma.setSize(400,900);
- forma.setLayout(new GridBagLayout());
- forma.setResizable(false);
- //--
- JPanel panel1 = new JPanel();
- panel1.setBorder(BorderFactory.createTitledBorder("Delivery Information"));
- SpringLayout layout = new SpringLayout();
- panel1.setLayout(new GridBagLayout());
- addComponent(panel1, new JLabel("Name"), 0, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL );
- addComponent(panel1, new JLabel("Surname"), 0, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL );
- addComponent(panel1, new JLabel("Address"), 0, 2, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL );
- final JTextField ime = new JTextField();
- final JTextField prezime = new JTextField();
- final JTextField address = new JTextField();
- addComponent(panel1, ime, 1, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL );
- addComponent(panel1, prezime, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL );
- addComponent(panel1, address, 1, 2, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL );
- addComponent(forma, panel1, 0, 0, 4, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- //--
- JPanel panel2 = new JPanel();
- panel2.setBorder(BorderFactory.createTitledBorder("CPU"));
- panel2.setLayout(new GridBagLayout());
- ButtonGroup grupa1 = new ButtonGroup();
- final JRadioButton rbtn1 = new JRadioButton("1.52 GHz");
- final JRadioButton rbtn2 = new JRadioButton("1.89 GHz");
- final JRadioButton rbtn3 = new JRadioButton("2.00 GHz");
- final JRadioButton rbtn4 = new JRadioButton("2.54 GHz");
- grupa1.add(rbtn1);
- grupa1.add(rbtn2);
- grupa1.add(rbtn3);
- grupa1.add(rbtn4);
- addComponent(panel2, rbtn1, 0, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(panel2, rbtn2, 1, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(panel2, rbtn3, 0, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(panel2, rbtn4, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(forma, panel2, 0, 1, 2, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- //--
- JPanel panel3 = new JPanel();
- panel3.setBorder(BorderFactory.createTitledBorder("RAM Memory"));
- panel3.setLayout(new GridBagLayout());
- ButtonGroup grupa2 = new ButtonGroup();
- final JRadioButton r1btn1 = new JRadioButton("512 MB");
- final JRadioButton r1btn2 = new JRadioButton("1 GB");
- final JRadioButton r1btn3 = new JRadioButton("2 GB");
- final JRadioButton r1btn4 = new JRadioButton("4 GB");
- grupa2.add(r1btn1);
- grupa2.add(r1btn2);
- grupa2.add(r1btn3);
- grupa2.add(r1btn4);
- addComponent(panel3, r1btn1, 0, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(panel3, r1btn2, 1, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(panel3, r1btn3, 0, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(panel3, r1btn4, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- addComponent(forma, panel3, 2, 1, 2, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- //--
- JPanel panel4 = new JPanel();
- panel4.setBorder(BorderFactory.createTitledBorder("Price"));
- //panel4.setLayout(new GridBagLayout());
- panel4.setLayout(layout);
- final JSlider slider = new JSlider();
- slider.setMinimum(200);
- slider.setMaximum(700);
- slider.setMajorTickSpacing(500);
- slider.setMinorTickSpacing(100);
- slider.setSnapToTicks(true);
- slider.setPaintLabels(true);
- slider.setPaintTicks(true);
- slider.setSnapToTicks(true);
- slider.setOrientation(JSlider.VERTICAL);
- slider.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent arg0) {
- if(!slider.getValueIsAdjusting()) {
- setPrice(Integer.valueOf(slider.getValue()));
- }
- }
- });
- panel4.add(slider);
- panel4.add(actual);
- panel4.add(price);
- layout.putConstraint(SpringLayout.NORTH, actual, 170, SpringLayout.NORTH, panel4);
- layout.putConstraint(SpringLayout.WEST, actual, 80, SpringLayout.WEST, slider);
- layout.putConstraint(SpringLayout.NORTH, price, 20, SpringLayout.NORTH, actual);
- layout.putConstraint(SpringLayout.WEST, price, 123, SpringLayout.WEST, slider);
- addComponent(forma, panel4, 0, 2, 3, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- //--
- JPanel panel5 = new JPanel();
- panel5.setLayout(new GridBagLayout());
- final JButton order = new JButton("Order");
- order.setEnabled(false);
- order.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- orderForma(ime.getText(), prezime.getText(), address.getText());
- }
- });
- final JButton check = new JButton("Check Configuration");
- check.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- DataBase a = new DataBase();
- a.initDatabase();
- String ram="", cpu="";
- if(r1btn1.isSelected()){ram = "512 MB";}
- if(r1btn2.isSelected()){ram = "1 GB";}
- if(r1btn3.isSelected()){ram = "2 GB";}
- if(r1btn4.isSelected()){ram = "4 GB";}
- if(rbtn1.isSelected()){cpu = "1.52 GHz";}
- if(rbtn2.isSelected()){cpu = "1.89 GHz";}
- if(r1btn3.isSelected()){cpu = "2.0 GHz";}
- if(rbtn4.isSelected()){cpu = "2.54 GHz";}
- Computer rez = a.searchComputer(cpu, ram, Integer.valueOf(slider.getValue()));
- if(rez!=null)
- {
- okForma(Integer.valueOf(slider.getValue()));
- order.setEnabled(true);}
- else {
- nookForma();
- order.setEnabled(false);
- }
- }
- });
- addComponent(panel5, check, 0, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
- addComponent(panel5, order, 1, 0, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL);
- addComponent(forma, panel5, 3, 2, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH);
- forma.setVisible(true);
- }
- public static void setPrice(int br){
- price.setText(br+"$");
- }
- public static void main(String[] args) {
- NovaForma();
- }
- private static void addComponent(Container container, Component component, int gridx, int gridy, int gridwidth, int gridheight, int anchor, int fill) {
- GridBagConstraints gbc= new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 1.0, 6.0, anchor, fill, insets, 0, 0);
- container.add(component, gbc);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement