1. import java.awt.BorderLayout;
  2. public class NewExample {
  3. private JFrame frame;
  4. JTabbedPane mainTab;
  5. DefaultMutableTreeNode treeNode1,treeNode2,treeNode3,
  6. treeNode4,treeNode5,treeNode6,treeNode7,treeNode8,treeNode9,
  7. treeNode10,treeNode11,treeNode12,treeNode13,treeNode14,treeNode15,
  8. treeNode16,treeNode17,treeNode18,treeNode19,School,Schools,Uni,nNode,node;
  9. DefaultTreeModel model;
  10. TreePath path;
  11. private JTextField textField;
  12. Image image;
  13. JLabel label,MapLabel;
  14. ImageIcon icon;
  15. /**
  16. * Launch the application.
  17. */
  18. public static void main(String[] args) {
  19. EventQueue.invokeLater(new Runnable() {
  20. public void run() {
  21. try {
  22. NewExample window = new NewExample();
  23. window.frame.setVisible(true);
  24. } catch (Exception e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. });
  29. }
  30. /**
  31. * Create the application.
  32. */
  33. public NewExample() {
  34. initialize();
  35. }
  36. private void initialize() {
  37. frame = new JFrame();
  38. frame.setBounds(100, 100, 949, 443);
  39. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  40. JMenuBar menuBar = new JMenuBar();
  41. frame.setJMenuBar(menuBar);
  42. JMenu System = new JMenu("System");
  43. menuBar.add(System);
  44. JMenu Simulation = new JMenu("Simulation");
  45. menuBar.add(Simulation);
  46. JMenu Help = new JMenu("Help");
  47. menuBar.add(Help);
  48. JMenuItem AbotUs = new JMenuItem("Abot Us");
  49. AbotUs.addActionListener(new ActionListener() {
  50. public void actionPerformed(ActionEvent arg0) {
  51. JOptionPane.showMessageDialog (null, "This prototype was created by T.I.T.T.S " +"\n" +
  52. "Stepanka Boudova" + "\n" +
  53. "Andrei Frumusanu" + "\n" +
  54. "Vicktor Tiransky" + "\n" +
  55. "proud Students of Uni.lu ", "About us", JOptionPane.INFORMATION_MESSAGE);
  56. }
  57. });
  58. Help.add(AbotUs);
  59. JMenuItem Version = new JMenuItem("Version");
  60. Help.add(Version);
  61. Version.addActionListener(new ActionListener() {
  62. public void actionPerformed(ActionEvent arg0) {
  63. JOptionPane.showMessageDialog (null, " Version 0.6 " , "About us", JOptionPane.INFORMATION_MESSAGE);
  64. }
  65. });
  66. mainTab = new JTabbedPane(JTabbedPane.TOP);
  67. mainTab.setBackground(Color.LIGHT_GRAY);
  68. frame.getContentPane().add(mainTab, BorderLayout.CENTER);
  69. JPanel panel = new JPanel();
  70. mainTab.addTab("New tab", null, panel, null);
  71. mainTab.setBackgroundAt(0, Color.WHITE);
  72. JScrollPane scrollPane = new JScrollPane(mainTab);
  73. frame.getContentPane().add(scrollPane);
  74. Container cp = new Container();
  75. panel.add(cp);
  76. Schools = new DefaultMutableTreeNode("Schools",true);
  77. model = new DefaultTreeModel(Schools);
  78. //model.addTreeModelListener(new MyTreeModelListener());
  79. School = new DefaultMutableTreeNode("European School of Luxembourg",true);
  80. Schools.add(School);
  81. treeNode2 = new DefaultMutableTreeNode("Building A");
  82. School.add(treeNode2);
  83. treeNode3 =new DefaultMutableTreeNode("Room A1");
  84. treeNode2.add(treeNode3);
  85. treeNode4 = new DefaultMutableTreeNode("Room A2");
  86. treeNode2.add(treeNode4);
  87. treeNode5 = new DefaultMutableTreeNode("Room A3");
  88. treeNode2.add(treeNode5);
  89. /*DefaultMutableTreeNode for Uni */
  90. Uni = new DefaultMutableTreeNode("Uni",true);
  91. treeNode2 = new DefaultMutableTreeNode("Building A");
  92. Uni.add(treeNode2);
  93. treeNode3 =new DefaultMutableTreeNode("Room A1");
  94. treeNode2.add(treeNode3);
  95. treeNode4 = new DefaultMutableTreeNode("Room A2");
  96. treeNode2.add(treeNode4);
  97. Schools.add(Uni);
  98. /* JTree */
  99. final JTree tree = new JTree(model);
  100. tree.setAutoscrolls(true);
  101. tree.setEditable(true);
  102. tree.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 11));
  103. tree.setBorder(UIManager.getBorder("Tree.editorBorder"));
  104. /*JScrollPane*/
  105. JScrollPane treePane = new JScrollPane(tree);
  106. treePane.setBounds(271, 11, 19, 154);
  107. //JPanel pan = new JPanel();
  108. //panel.add(pan,tree);
  109. //pan.add(treePane);
  110. treePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  111. treePane.setViewportView(tree);
  112. cp.add(treePane, BorderLayout.CENTER);
  113. /*Listener for JTree to show what is selected*/
  114. /*JButtons for Add and Remove new School*/
  115. final JButton btnAddNewSchool = new JButton("Add new School");
  116. btnAddNewSchool.addActionListener(new ActionListener() {
  117. public void actionPerformed(ActionEvent event) {
  118. if(event.getSource().equals(btnAddNewSchool)){
  119. //System.out.println("but was clicked");
  120. DefaultMutableTreeNode selNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
  121. if(selNode != null){
  122. DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New Node");
  123. model.insertNodeInto(newNode, selNode, selNode.getChildCount());
  124. TreeNode [] nodes = model.getPathToRoot(newNode);
  125. path = new TreePath(nodes);
  126. tree.scrollPathToVisible(path);
  127. tree.setSelectionPath(path);
  128. tree.startEditingAtPath(path);
  129. }
  130. }
  131. }
  132. });
  133. JButton btnRemoveSchool = new JButton("Remove School");
  134. btnRemoveSchool.addActionListener(new ActionListener() {
  135. public void actionPerformed(ActionEvent arg0) {
  136. }
  137. });
  138. /*JBUttons for Trigger Alarm + Listener */
  139. JButton TriggerAlarm = new JButton("Trigger Alarm");
  140. TriggerAlarm.addActionListener(new ActionListener() {
  141. public void actionPerformed(ActionEvent arg0) {
  142. JOptionPane.showMessageDialog (null, " Alarm was triggered, Message is being send to the nearest Fire Station " , "About us", JOptionPane.INFORMATION_MESSAGE);
  143. }
  144. });
  145. GroupLayout gl_panel = new GroupLayout(panel);
  146. gl_panel.setHorizontalGroup(
  147. gl_panel.createParallelGroup(Alignment.LEADING)
  148. .addGroup(gl_panel.createSequentialGroup()
  149. .addContainerGap()
  150. .addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
  151. .addGroup(gl_panel.createSequentialGroup()
  152. .addComponent(btnAddNewSchool, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE)
  153. .addGap(32)
  154. .addComponent(btnRemoveSchool, 0, 0, Short.MAX_VALUE))
  155. .addComponent(tree, GroupLayout.PREFERRED_SIZE, 228, GroupLayout.PREFERRED_SIZE))
  156. .addGap(33)
  157. .addComponent(treePane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  158. .addGap(18)
  159. .addComponent(TriggerAlarm)
  160. .addContainerGap(648, Short.MAX_VALUE))
  161. );
  162. gl_panel.setVerticalGroup(
  163. gl_panel.createParallelGroup(Alignment.LEADING)
  164. .addGroup(gl_panel.createSequentialGroup()
  165. .addGap(11)
  166. .addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
  167. .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
  168. .addComponent(tree, GroupLayout.PREFERRED_SIZE, 301, GroupLayout.PREFERRED_SIZE)
  169. .addComponent(TriggerAlarm))
  170. .addComponent(treePane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  171. .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  172. .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
  173. .addComponent(btnAddNewSchool)
  174. .addComponent(btnRemoveSchool))
  175. .addContainerGap())
  176. );
  177. panel.setLayout(gl_panel);
  178. panel.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{tree, TriggerAlarm}));
  179. JPanel cri = new JPanel();
  180. mainTab.addTab("Crysis Management", null, cri, null);
  181. cri.setLayout(new BoxLayout(cri, BoxLayout.X_AXIS));
  182. JPanel main = new JPanel();
  183. mainTab.addTab("Maintaince", null, main, null);
  184. GroupLayout gl_main = new GroupLayout(main);
  185. gl_main.setHorizontalGroup(
  186. gl_main.createParallelGroup(Alignment.LEADING)
  187. .addGroup(gl_main.createSequentialGroup()
  188. .addContainerGap()
  189. .addComponent(tree_2, GroupLayout.PREFERRED_SIZE, 92, GroupLayout.PREFERRED_SIZE)
  190. .addGap(18)
  191. .addGroup(gl_main.createParallelGroup(Alignment.LEADING)
  192. .addComponent(btnTrigger)
  193. .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  194. .addContainerGap(826, Short.MAX_VALUE))
  195. );
  196. gl_main.setVerticalGroup(
  197. gl_main.createParallelGroup(Alignment.LEADING)
  198. .addGroup(gl_main.createSequentialGroup()
  199. .addContainerGap()
  200. .addGroup(gl_main.createParallelGroup(Alignment.BASELINE)
  201. .addComponent(tree_2, GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
  202. .addGroup(gl_main.createSequentialGroup()
  203. .addComponent(btnTrigger)
  204. .addGap(11)
  205. .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
  206. .addContainerGap())
  207. );
  208. main.setLayout(gl_main);
  209. }
  210. }
Comments powered by Disqus