Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.32 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JPanel;
  5.  
  6. import java.awt.Color;
  7.  
  8. import javax.swing.JLabel;
  9.  
  10. import java.awt.BorderLayout;
  11.  
  12. import javax.swing.JRadioButton;
  13. import javax.swing.SwingConstants;
  14.  
  15. import java.awt.Window.Type;
  16.  
  17. import javax.swing.GroupLayout;
  18. import javax.swing.GroupLayout.Alignment;
  19. import javax.swing.ImageIcon;
  20. import javax.swing.JButton;
  21. import javax.swing.LayoutStyle.ComponentPlacement;
  22. import javax.swing.border.BevelBorder;
  23. import java.awt.event.ActionListener;
  24. import java.awt.event.ActionEvent;
  25. import javax.swing.JTextField;
  26. import java.awt.event.MouseAdapter;
  27. import java.awt.event.MouseEvent;
  28.  
  29.  
  30. public class Frame2 {
  31.  
  32. private JFrame frmGroup;
  33. private JTextField textField;
  34. private int framewidth = 1000;
  35. private int frameheight = 600;
  36. private int mapwidth = 400;
  37. private int mapheight = 400;
  38. private Object currentlySelected;
  39.  
  40. /**
  41. * Launch the application.
  42. */
  43. public static void main(String[] args) {
  44. EventQueue.invokeLater(new Runnable() {
  45. public void run() {
  46. try {
  47. Frame2 window = new Frame2();
  48. window.frmGroup.setVisible(true);
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. }
  52. }
  53. });
  54. }
  55.  
  56. /**
  57. * Create the application.
  58. */
  59. public Frame2() {
  60. initialize();
  61. }
  62.  
  63. /**
  64. * Initialize the contents of the frame.
  65. */
  66. private void initialize() {
  67. frmGroup = new JFrame();
  68. frmGroup.getContentPane().setBackground(new Color(32, 178, 170));
  69. frmGroup.getContentPane().setForeground(new Color(32, 178, 170));
  70. frmGroup.setTitle("GROUP 1");
  71. frmGroup.setBounds(100, 100, 1082, 801);
  72. frmGroup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  73.  
  74. JLabel lblMapTypes = new JLabel("FIXED MAP");
  75. lblMapTypes.setForeground(new Color(255, 0, 0));
  76.  
  77. JRadioButton rdbtnCity = new JRadioButton("City");
  78.  
  79. JRadioButton rdbtnForest = new JRadioButton("Forest");
  80.  
  81. JRadioButton rdbtnWalls = new JRadioButton("Maze");
  82.  
  83. JRadioButton rdbtnConstruct = new JRadioButton("construct");
  84.  
  85. JLabel lblEditionOptions = new JLabel("CUSTOMIZE");
  86. lblEditionOptions.setForeground(new Color(255, 0, 0));
  87.  
  88. //<<<<<<<<<<<BUTTONS HERE >>>>>>>>
  89.  
  90. JButton btnTree = new JButton(new ImageIcon(Frame2.class.getResource("finaltree.jpg")));
  91. btnTree.addMouseListener(new MouseAdapter() {
  92. @Override
  93. public void mouseClicked(MouseEvent e) {
  94. currentlySelected = new Tree();
  95. }
  96. });
  97.  
  98. JButton btnTower = new JButton(new ImageIcon(Frame2.class.getResource("Nobility.png")));
  99. btnTower.addMouseListener(new MouseAdapter() {
  100. @Override
  101. public void mouseClicked(MouseEvent e) {
  102. currentlySelected = new Tower();
  103. }
  104. });
  105.  
  106. JButton btnStart = new JButton("START");
  107.  
  108. JButton btnWall = new JButton(new ImageIcon(Frame2.class.getResource("Small_Rock_Icon.png")));
  109. btnWall.addMouseListener(new MouseAdapter() {
  110. @Override
  111. public void mouseClicked(MouseEvent e) {
  112. currentlySelected = new Wall();
  113. }
  114. });
  115.  
  116. JButton btnBuilding = new JButton(new ImageIcon(Frame2.class.getResource("building_icon.jpg")));
  117. btnBuilding.addMouseListener(new MouseAdapter() {
  118. @Override
  119. public void mouseClicked(MouseEvent e) {
  120. currentlySelected = new Building();
  121. }
  122. });
  123.  
  124. JButton btnTarget = new JButton(new ImageIcon(Frame2.class.getResource("13-target.png")));
  125. btnTarget.addMouseListener(new MouseAdapter() {
  126. @Override
  127. public void mouseClicked(MouseEvent e) {
  128. currentlySelected = new Target();
  129. }
  130. });
  131.  
  132. JButton btnHorizontalWall = new JButton(new ImageIcon(Frame2.class.getResource("Icon-small.jpg")));
  133. btnHorizontalWall.addMouseListener(new MouseAdapter() {
  134. @Override
  135. public void mouseClicked(MouseEvent arg0) {
  136. }
  137. });
  138.  
  139. JPanel panel = new JPanel();
  140. panel.addMouseListener(new MouseAdapter() {
  141. @Override
  142. public void mouseClicked(MouseEvent e) {
  143. System.out.println("Coordinates: (" + e.getX() + ", " + e.getY() + ")");
  144. if(currentlySelected != null)
  145. {
  146. //setCoordinates for currentlySelected object
  147. currentlySelected = null;
  148. }
  149. else
  150. {
  151. //check if there's an object at coordinates
  152. //delete that object from map
  153. }
  154. }
  155. });
  156. panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null,null, null, null));
  157. //panel.setSize(mapwidth, mapheight);
  158.  
  159.  
  160. JLabel lblNOfIntruders = new JLabel("N\u00BA of intruders : ");
  161.  
  162. textField = new JTextField();
  163. textField.setColumns(10);
  164.  
  165. JButton btnGuards = new JButton(new ImageIcon(Frame2.class.getResource("soldier-icon-1004184133.png")));
  166.  
  167. JLabel lblClickInThe = new JLabel("Click in the map to delete");
  168.  
  169. GroupLayout groupLayout = new GroupLayout(frmGroup.getContentPane());
  170. groupLayout.setHorizontalGroup(
  171. groupLayout.createParallelGroup(Alignment.LEADING)
  172. .addGroup(groupLayout.createSequentialGroup()
  173. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  174. .addGroup(groupLayout.createSequentialGroup()
  175. .addGap(143)
  176. .addComponent(lblNOfIntruders)
  177. .addPreferredGap(ComponentPlacement.UNRELATED)
  178. .addComponent(textField, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
  179. .addGap(59)
  180. .addComponent(btnGuards))
  181. .addGroup(groupLayout.createSequentialGroup()
  182. .addContainerGap()
  183. .addComponent(lblClickInThe))
  184. .addGroup(groupLayout.createSequentialGroup()
  185. .addContainerGap()
  186. .addComponent(panel, GroupLayout.PREFERRED_SIZE, 600, GroupLayout.PREFERRED_SIZE)))
  187. .addPreferredGap(ComponentPlacement.RELATED)
  188. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  189. .addGroup(groupLayout.createSequentialGroup()
  190. .addGap(173)
  191. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  192. .addGroup(groupLayout.createSequentialGroup()
  193. .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
  194. .addComponent(btnBuilding, GroupLayout.PREFERRED_SIZE, 84, GroupLayout.PREFERRED_SIZE)
  195. .addGroup(groupLayout.createSequentialGroup()
  196. .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
  197. .addComponent(btnStart, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  198. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  199. .addComponent(btnWall, 0, 0, Short.MAX_VALUE)
  200. .addComponent(lblEditionOptions, Alignment.TRAILING)))
  201. .addGap(30)))
  202. .addPreferredGap(ComponentPlacement.UNRELATED)
  203. .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
  204. .addComponent(btnTarget, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  205. .addComponent(btnTower, Alignment.LEADING, 0, 0, Short.MAX_VALUE)
  206. .addComponent(rdbtnForest, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  207. .addComponent(lblMapTypes, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE))
  208. .addContainerGap(113, Short.MAX_VALUE))
  209. .addGroup(groupLayout.createSequentialGroup()
  210. .addGap(80)
  211. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  212. .addGroup(groupLayout.createSequentialGroup()
  213. .addComponent(btnHorizontalWall)
  214. .addContainerGap())
  215. .addGroup(groupLayout.createSequentialGroup()
  216. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  217. .addComponent(btnTree, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
  218. .addComponent(rdbtnCity))
  219. .addGap(35)
  220. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  221. .addGroup(groupLayout.createSequentialGroup()
  222. .addComponent(rdbtnConstruct)
  223. .addContainerGap())
  224. .addGroup(groupLayout.createSequentialGroup()
  225. .addComponent(rdbtnWalls, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  226. .addGap(373))))))))
  227. );
  228. groupLayout.setVerticalGroup(
  229. groupLayout.createParallelGroup(Alignment.LEADING)
  230. .addGroup(groupLayout.createSequentialGroup()
  231. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  232. .addGroup(groupLayout.createSequentialGroup()
  233. .addGap(31)
  234. .addComponent(lblMapTypes)
  235. .addGap(18)
  236. .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
  237. .addComponent(rdbtnWalls)
  238. .addComponent(rdbtnForest))
  239. .addGap(26)
  240. .addComponent(rdbtnConstruct)
  241. .addGap(18)
  242. .addComponent(lblEditionOptions)
  243. .addPreferredGap(ComponentPlacement.RELATED)
  244. .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
  245. .addComponent(btnTower, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
  246. .addComponent(btnWall, 0, 0, Short.MAX_VALUE))
  247. .addGap(132)
  248. .addComponent(btnTree, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
  249. .addGap(7)
  250. .addGap(41)
  251. .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
  252. .addComponent(btnTarget, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  253. .addComponent(btnBuilding, 0, 0, Short.MAX_VALUE)
  254. .addComponent(btnHorizontalWall, GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE))
  255. .addGap(43)
  256. .addComponent(btnStart)
  257. .addGap(85))
  258. .addGroup(groupLayout.createSequentialGroup()
  259. .addGap(17)
  260. .addComponent(lblClickInThe)
  261. .addGap(18)
  262. .addComponent(panel, GroupLayout.PREFERRED_SIZE, 600, GroupLayout.PREFERRED_SIZE)
  263. .addPreferredGap(ComponentPlacement.RELATED)))
  264. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  265. .addGroup(groupLayout.createSequentialGroup()
  266. .addGap(16)
  267. .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
  268. .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  269. .addComponent(lblNOfIntruders)))
  270. .addGroup(groupLayout.createSequentialGroup()
  271. .addGap(18)
  272. .addComponent(btnGuards)))
  273. .addGap(19))
  274. .addGroup(groupLayout.createSequentialGroup()
  275. .addGap(65)
  276. .addComponent(rdbtnCity)
  277. .addContainerGap(476, Short.MAX_VALUE))
  278. );
  279. frmGroup.getContentPane().setLayout(groupLayout);
  280. }
  281. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement