Advertisement
MusicFreak

Urosevic 27.11.2015

Nov 27th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.96 KB | None | 0 0
  1. VINDOUZ APLIKACIJE
  2.  
  3.  
  4. ====================
  5. import javax.swing.*;
  6. public class Win1 extends JFrame{
  7.     public Win1(){
  8.         super("Nasa prva Win app");
  9.         setSize(300, 100);
  10.     }
  11.     public static void main(String[] args) {
  12.         Win1 w1;
  13.         w1 = new Win1();
  14.         w1.show();
  15.     }
  16.  
  17. }
  18.  
  19. ====================
  20. import javax.swing.*;
  21. import java.awt.*;
  22. import java.awt.event.*;
  23. public class Win2 extends JFrame{
  24.     JButton btRadi;
  25.     class RadiListener implements ActionListener{
  26.         public void actionPerformed(ActionEvent e){
  27.             e.getSource();
  28.             System.out.println("STOP IT!");
  29.         }
  30.     }
  31.     public Win2(){
  32.         super("App with one pointless button.");
  33.         setSize(400, 100);
  34.         Container cp = this.getContentPane();
  35.         cp.setLayout(new FlowLayout());
  36.         btRadi = new JButton("Radi");
  37.         btRadi.addActionListener(new RadiListener());
  38.         cp.add(btRadi);
  39.         //Drugi nacin cp.add(btRadi = new JButton("Radi"));
  40.     }
  41.     public static void main(String args[]){
  42.         Win2 w2 = new Win2();
  43.         w2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44.         w2.show();
  45.     }
  46. }
  47.  
  48. ===================
  49. import javax.swing.*;
  50. import java.awt.*;
  51. import java.awt.event.*;
  52. public class Win3 extends JFrame implements ActionListener{
  53.     JButton btRadi1, btRadi2, btRadi3;
  54.     public Win3(){
  55.         super("Win3");
  56.         setSize(420, 200);
  57.         Container cp = this.getContentPane();
  58.         cp.setLayout(new FlowLayout());
  59.         cp.add(btRadi1 = new JButton("Radi 1"));
  60.         btRadi1.addActionListener(this);
  61.         cp.add(btRadi2 = new JButton("Radi 2"));
  62.         btRadi2.addActionListener(this);
  63.         cp.add(btRadi3 = new JButton("Radi 3"));
  64.         btRadi3.addActionListener(this);
  65.     }
  66.     public void actionPerformed(ActionEvent e){
  67.         System.out.println("Pritisnuto je dumge "+e.getActionCommand());
  68.     }
  69.     public static void main(String[] args) {
  70.         Win3 w3 = new Win3();
  71.         w3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  72.         w3.show();
  73.     }
  74.  
  75. }
  76.  
  77. =================
  78. import javax.swing.*;
  79.  
  80. import java.awt.*;
  81. import java.awt.event.*;
  82. public class Win4 extends JFrame implements ActionListener{
  83.     private JLabel lb1, lb2, lbRez;
  84.     private JTextField tf1, tf2, tfRez;
  85.     private JButton btSaberi, btOduzmi;
  86.     public Win4(){
  87.         super("Sabirac/Oduzimac");
  88.         setSize(200, 420);
  89.         Container cp = this.getContentPane();
  90.         //cp.setLayout(new FlowLayout());
  91.         cp.setLayout(new GridLayout(4,2));
  92.         cp.add(lb1 = new JLabel("Broj 1: "));
  93.         cp.add(tf1 = new JTextField(15));
  94.         cp.add(lb2 = new JLabel("Broj 2: "));
  95.         cp.add(tf2 = new JTextField(15));
  96.         cp.add(lbRez = new JLabel("Rezultat: "));
  97.         cp.add(tfRez = new JTextField(15));
  98.         tfRez.setEditable(false);
  99.         cp.add(btSaberi = new JButton("Saberi"));
  100.         btSaberi.addActionListener(this);
  101.         cp.add(btOduzmi = new JButton("Oduzmi"));
  102.         btOduzmi.addActionListener(this);
  103.     }
  104.     public void actionPerformed(ActionEvent e){
  105.         double broj1, broj2, rez;
  106.         String str;
  107.         try{
  108.         str = tf1.getText();
  109.         broj1 = Double.parseDouble(str);
  110.         str = tf2.getText();
  111.         broj2 = Double.parseDouble(str);
  112.         //if (e.getActionCommand().equals("Saberi"))
  113.         //  rez  = broj1 + broj2;
  114.         //else
  115.         //  rez = broj1 - broj2;
  116.         if (e.getSource() == btSaberi)
  117.             rez = broj1 + broj2;
  118.         else
  119.             rez = broj1 - broj2;
  120.         tfRez.setText(Double.toString(rez));
  121.         }catch (Exception ee){
  122.             tfRez.setText("Nepravilno zadat neki broj!");
  123.         }
  124.     }
  125.     public static void main(String[] args) {
  126.         Win4 w4 = new Win4();
  127.         w4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  128.         w4.show();
  129.     }
  130.  
  131. }
  132.  
  133. ===================
  134. import javax.swing.*;
  135.  
  136. import java.awt.*;
  137. import java.awt.event.*;
  138. public class Win5 extends JFrame{
  139.     JComboBox cb;
  140.     public Win5(){
  141.         super("Qwerty");
  142.         String imena[]= {"Marko", "Pera", "Laza", "Zika", "Mika"};
  143.         setSize(120, 100);
  144.         Container cp = this.getContentPane();
  145.         cp.setLayout(new FlowLayout());
  146.         cb = new JComboBox();
  147.         for (int k = 0; k < imena.length; k++)
  148.             cb.addItem(imena[k]);
  149.         cp.add(cb);    
  150.     }
  151.     public static void main(String[] args) {
  152.         Win5 w5 = new Win5();
  153.         w5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  154.         w5.show();     
  155.     }
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement