Advertisement
Pihtija

OBP2 V8

Dec 11th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. package grafika;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ItemEvent;
  6. import java.awt.event.ItemListener;
  7.  
  8. /**
  9. * Created by urosrt4515 on 12/11/2018.
  10. */
  11. public class Prozor extends JFrame{
  12. public Prozor(){
  13. setTitle("Vezba 8");
  14. setSize(400,400);
  15. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.  
  17. Container c=getContentPane();
  18. c.setLayout(new BorderLayout());
  19. JButton btn1=new JButton("Dugme 1");
  20. c.add("North",btn1);
  21.  
  22. JPanel p=new JPanel();
  23. p.setLayout(new GridLayout(4,1));
  24. JRadioButton rb1=new JRadioButton("muski");
  25. p.add(rb1);
  26. JRadioButton rb2=new JRadioButton("muski");
  27. p.add(rb2);
  28.  
  29. ButtonGroup bgPol=new ButtonGroup();
  30. bgPol.add(rb1);
  31. bgPol.add(rb2);
  32.  
  33. JCheckBox cb1=new JCheckBox("Izbor1");
  34. p.add(cb1);
  35. JCheckBox cb2=new JCheckBox("Izbor1");
  36. p.add(cb2);
  37.  
  38. ItemListener itPol=new ItemListener() {
  39. @Override
  40. public void itemStateChanged(ItemEvent e) {
  41. if (e.getSource() instanceof JRadioButton) {
  42. if (rb1.isSelected())
  43. System.out.println("Pol muski");
  44. else if (rb2.isSelected())
  45. System.out.println("Pol zemski");
  46. } else {
  47. if(cb1.isSelected())
  48. System.out.println("Izabrana oopcija 1");
  49. if(cb2.isSelected())
  50. System.out.println("Izabrana oopcija 2");
  51. }
  52. }
  53. };
  54. rb1.addItemListener(itPol);
  55. rb2.addItemListener(itPol);
  56. cb1.addItemListener(itPol);
  57. cb2.addItemListener(itPol);
  58.  
  59.  
  60. c.add("Center", p);
  61.  
  62. JLabel lblv=new JLabel("Vreme:60");
  63. c.add("West", lblv);
  64.  
  65. new Odbrojavanje(lblv).start();
  66.  
  67.  
  68. setVisible(true);
  69.  
  70. }
  71. }
  72. -------------------------------------
  73. package glavni;
  74.  
  75. import grafika.Prozor;
  76.  
  77. /**
  78. * Created by urosrt4515 on 12/11/2018.
  79. */
  80. public class Program {
  81. public static void main(String[] args) {
  82. Prozor p=new Prozor();
  83. }
  84. }
  85. -------------------------------------
  86. package grafika;
  87.  
  88. import javax.swing.*;
  89.  
  90. /**
  91. * Created by urosrt4515 on 12/11/2018.
  92. */
  93. public class Odbrojavanje extends Thread{
  94. private JLabel lblVreme;
  95. public Odbrojavanje(JLabel lbl){
  96. this.lblVreme=lbl;
  97. }
  98.  
  99. public void run(){
  100. for (int i=60;i>=0;i--){
  101. lblVreme.setText("Vreme:"+i);
  102. try {
  103. Thread.sleep(1000);
  104. } catch (InterruptedException e) {
  105. e.printStackTrace();
  106. }
  107. }
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement