Advertisement
Pihtija

OBP V7

Dec 4th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. package grafika;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.WindowAdapter;
  7. import java.awt.event.WindowEvent;
  8.  
  9. /**
  10. * Created by korisnik on 4.12.2018..
  11. */
  12. public class Prozor extends Frame{
  13. MojDijalog md=new MojDijalog(this);
  14. public Prozor(String naslov){
  15. super(naslov);
  16. setSize(400,400);
  17. setLayout(new BorderLayout());
  18. Label l1=new Label("L1");
  19. Label l2=new Label("L2");
  20. Label l3=new Label("L3");
  21. Label l4=new Label("L4");
  22. addWindowListener(new WindowAdapter() {
  23. @Override
  24. public void windowClosing(WindowEvent e) {
  25. md.prikazi();
  26. }
  27. });
  28. add("North", l1);
  29. add("East", l2);
  30. add("Center", l3);
  31. add("South", l4);
  32.  
  33. Panel p=new Panel();
  34. p.setLayout(new GridLayout(2,2));
  35. p.add(new Button ("B1"));
  36. p.add(new Button ("B2"));
  37. p.add(new Button ("B3"));
  38. p.add(new Button ("B4"));
  39. add("Center", p);
  40. dodajMenu();
  41. setVisible(true);
  42. }
  43.  
  44. private void dodajMenu(){
  45. MenuBar mb=new MenuBar();
  46.  
  47. Menu m1=new Menu("File");
  48. m1.add("New");
  49. m1.add("Save");
  50. m1.add("Save as");
  51. m1.addSeparator();
  52. m1.add("Exit");
  53. m1.addActionListener(new ActionListener() {
  54. @Override
  55. public void actionPerformed(ActionEvent e) {
  56. System.out.println(e.getActionCommand());
  57.  
  58. }
  59. });
  60. mb.add(m1);
  61. Menu m2=new Menu("Edit");
  62. m2.add("Undo");
  63. Menu m3=new Menu("vise");
  64. m3.add("Podopcija 1");
  65. m2.add(m3);
  66. mb.add(m2);
  67. setMenuBar(mb);
  68.  
  69. }
  70.  
  71.  
  72. }
  73. ---------------------------------------
  74. package grafika;
  75.  
  76. import java.awt.*;
  77. import java.awt.event.ActionEvent;
  78. import java.awt.event.ActionListener;
  79.  
  80. /**
  81. * Created by korisnik on 4.12.2018..
  82. */
  83. public class MojDijalog extends Dialog{
  84. public MojDijalog(Frame roditelj) {
  85. super(roditelj, "Da li ste sigurni?", true);
  86. setSize(200,200);
  87. setLayout(new FlowLayout());
  88. Button b1=new Button("Da");
  89. b1.setActionCommand("11");
  90. b1.addActionListener(new ActionListener() {
  91. @Override
  92. public void actionPerformed(ActionEvent e) {
  93. System.out.println(e.getActionCommand());
  94. System.exit(1);
  95. }
  96. });
  97. add(b1);
  98.  
  99. }
  100.  
  101. public void prikazi(){
  102. setVisible(true);
  103. }
  104. }
  105. --------------------------------------------
  106. package glavni;
  107.  
  108. import Samostalni.ProzorKalkulatora;
  109. import grafika.Prozor;
  110.  
  111. /**
  112. * Created by korisnik on 4.12.2018..
  113. */
  114. public class Program {
  115. public static void main(String[] args) {
  116. // Prozor p=new Prozor("Vezba 7");
  117.  
  118. ProzorKalkulatora p= new ProzorKalkulatora("Kalkulator");
  119. }
  120. }
  121. ------------------------------------------------
  122. package Samostalni;
  123.  
  124. import sun.swing.MenuItemLayoutHelper;
  125.  
  126. import javax.swing.plaf.basic.BasicOptionPaneUI;
  127. import java.awt.*;
  128.  
  129. /**
  130. * Created by korisnik on 4.12.2018..
  131. */
  132. public class ProzorKalkulatora extends Frame{
  133. private String prvi="l1";
  134. private String drugi="l2";
  135. private String treci="l3";
  136.  
  137. public ProzorKalkulatora (String naslov){
  138. super(naslov);
  139. setSize(600,600);
  140. setLayout(new BorderLayout());
  141. Label l1=new Label(prvi);
  142. Label l2=new Label(drugi);
  143. Label l3=new Label(treci);
  144. add("North", l1);
  145. add("North", l2);
  146. add("North", l3);
  147. Panel p=new Panel();
  148. p.setLayout(new GridLayout(3,3));
  149. p.add(new Button ("1"));
  150. p.add(new Button ("2"));
  151. p.add(new Button ("3"));
  152.  
  153. p.add(new Button ("4"));
  154. p.add(new Button ("5"));
  155. p.add(new Button ("6"));
  156.  
  157. p.add(new Button ("7"));
  158. p.add(new Button ("8"));
  159. p.add(new Button ("9"));
  160.  
  161. p.add(new Button ("."));
  162. p.add(new Button ("0"));
  163. Panel d=new Panel();
  164. d.setLayout(new GridLayout(1,3));
  165. add("West", d);
  166. d.add( new Button ("="));
  167.  
  168.  
  169. add("Center", p);
  170.  
  171. setVisible(true);
  172. }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement