Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.18 KB | None | 0 0
  1.  
  2. import javax.swing.border.EmptyBorder;
  3.  
  4. import java.awt.event.*;
  5. import java.awt.*;
  6. import javax.swing.*;
  7. import javax.swing.border.EtchedBorder;
  8. import javax.swing.border.TitledBorder;
  9. import java.awt.image.BufferedImage;
  10. import java.util.ArrayList;
  11.  
  12.  
  13. public class LandingPage extends JFrame {
  14.  
  15. public boolean verify = false;
  16. Profile user = new Profile();
  17. database newUser = new database();
  18. //registrationPage register = new registrationPage();
  19.  
  20. //These variables keep the latest X and Y event locations.
  21. int lastClickX;
  22. int lastClickY;
  23. String coordinates;
  24.  
  25. //This label is going to represent the map
  26. JLabel label;
  27. aboutPage aboutP;
  28. //this contentPane represents the top bar in the code
  29. private JPanel contentPane;
  30. //This is a textField for usernames
  31. private JTextField txtUser;
  32. //this is a textField for passwords
  33. private JTextField txtPass;
  34.  
  35.  
  36.  
  37. //This is going to represent the popup menu on right click
  38. JPopupMenu popupMenu;
  39. //These are the control options for that popup menu
  40. private JMenuItem makeReport, viewInfo, deleteMarker,getAll;
  41.  
  42. //This complaints window represents the window that pops up when you click add a problem
  43. Complaints complaints;
  44.  
  45. //This points at an object instantiated by the complaints window
  46. ArrayList<Issue> issues;
  47.  
  48. //This is used for drawing
  49. MapComponent mapComponent;
  50.  
  51. JButton btnLogin, btnRegister, btnAbout;
  52.  
  53. JSeparator separator;
  54. Color clickLocation;
  55. //int colorRange[] = new int[6];
  56. int colorRange[] = {238,245,239,242,238,245};
  57. int mapPixels[];
  58. ImageIcon map;
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. /**
  67. * Create the frame.
  68. */
  69. public LandingPage() {
  70.  
  71. instantiate();
  72. addAttributes();
  73. addPopup(mapComponent, popupMenu);
  74.  
  75.  
  76. // Image img = new ImageIcon(this.getClass().getResource("/map.png")).getImage();
  77. }
  78.  
  79. public int instantiate(){
  80. //Instantiate variables to 0 at first
  81. lastClickX = 0;
  82. lastClickY = 0;
  83. //Instantiate a complaints window; should only have one of this object
  84. complaints = new Complaints(lastClickX, lastClickY);
  85. //Makes the issues variable of this class point to the ArrayList created by the Complaints class
  86. issues = complaints.getIssues();
  87.  
  88. //Instantiate popup menu and add items to it
  89. popupMenu = new JPopupMenu();
  90. makeReport = new JMenuItem("Make A Report");
  91. viewInfo = new JMenuItem("View Info");
  92. deleteMarker = new JMenuItem("Delete Marker");
  93. getAll = new JMenuItem("Get All Issues");
  94.  
  95. mapComponent = new MapComponent();
  96.  
  97. label = new JLabel("AAAAAAA");
  98.  
  99. contentPane = new JPanel();
  100.  
  101. //Make a new text field for the user stuff
  102. txtUser = new JTextField();
  103. txtUser.setText("enter username");
  104. txtUser.setBounds(830, 13, 130, 26);
  105. txtUser.setColumns(10);
  106. //contentPane.add(txtUser);
  107. aboutP = new aboutPage();
  108. btnLogin = new JButton("Login");
  109. btnRegister = new JButton("Register");
  110. btnAbout = new JButton("About");
  111.  
  112. separator = new JSeparator();
  113. txtPass = new JTextField();
  114.  
  115. return 1;
  116.  
  117. }
  118.  
  119. public int addAttributes() {
  120.  
  121. popupMenu.add(makeReport);
  122. popupMenu.add(viewInfo);
  123. popupMenu.add(deleteMarker);
  124. popupMenu.add(getAll);
  125.  
  126. mapComponent.add(popupMenu);
  127.  
  128. label.addMouseListener(new MouseAdapter() {
  129. @Override
  130. public void mouseClicked(MouseEvent e) {
  131.  
  132. }
  133. });
  134. label.setBounds(23, 51, 1216, 674);
  135.  
  136. mapComponent.addMouseListener(new MouseAdapter(){
  137. @Override
  138. public void mouseClicked(MouseEvent e) {}
  139. });
  140. mapComponent.setBounds(23,51,1216,674);
  141.  
  142. //Make a JPanel, add a border around it, and add the label to it.
  143. //contentPane = new JPanel();
  144. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  145. contentPane.setLayout(null);
  146. //contentPane.add(label);
  147.  
  148. //Add the JPanel above to this frame, set its close operation, and bounds
  149. this.setContentPane(contentPane);
  150. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  151. this.setBounds(100, 100, 1262,753);
  152.  
  153. this.add(mapComponent, BorderLayout.CENTER);
  154.  
  155. map = new ImageIcon("/Users/Hamza/Desktop/map.png");
  156. label.setIcon(map);
  157.  
  158. makeReport.addActionListener(new ActionListener() {
  159. public void actionPerformed(ActionEvent e) {
  160. //JFrame complaint = new complaints().setVisible(true);
  161.  
  162. //Makes a new popup window of complaints, and logs the clicked X and Y locations
  163. //complaints = new Complaints(lastClickX, lastClickY);
  164. if(verify == true){
  165. complaints.setCoords(lastClickX,lastClickY);
  166. complaints.setVisible(true);
  167. }else{
  168.  
  169. }
  170.  
  171. }
  172. });
  173.  
  174. getAll.addActionListener(new ActionListener() {
  175. public void actionPerformed(ActionEvent e) {
  176. for(int i = 0; i < issues.size(); i++) {
  177. System.out.println(issues.get(i).getDescrip() + "\n");
  178. complaints.repaint();
  179.  
  180. }
  181. }
  182. });
  183.  
  184. JButton btnAbout = new JButton("About");
  185. btnAbout.setBounds(453, 13, 117, 29);
  186.  
  187. separator.setBounds(23, 38, 1215, 12);
  188.  
  189. txtPass.setText("enter password");
  190. txtPass.setBounds(980, 13, 130, 26);
  191. //contentPane.add(txtPass);
  192. txtPass.setColumns(10);
  193.  
  194. JTextField txtNewName = new JTextField();
  195. txtNewName.setText("Enter New User");
  196. txtNewName.setBounds(152, 10, 130, 26);
  197. txtNewName.setColumns(10);
  198.  
  199. JTextField txtNewPass = new JTextField();
  200. txtNewPass.setText("Enter New Pass");
  201. txtNewPass.setBounds(294, 10, 130, 26);
  202. txtNewPass.setColumns(10);
  203.  
  204. btnLogin.addActionListener(new ActionListener() {
  205. public void actionPerformed(ActionEvent e) {
  206. if(newUser.checkLogin(txtUser.getText(), txtPass.getText())){
  207. JOptionPane.showMessageDialog(null, "Login Success");
  208. verify = true;
  209. }else{
  210. JOptionPane.showMessageDialog(null, "Login Failed");
  211. verify = false;
  212. }
  213. }
  214. });
  215. btnLogin.setBounds(1122, 13, 117, 29);
  216.  
  217.  
  218. btnRegister.addActionListener(new ActionListener() {
  219. public void actionPerformed(ActionEvent e) {
  220. newUser.addUser(txtNewName.getText(), txtNewPass.getText());
  221. JOptionPane.showMessageDialog(null, "Successfully Registered");
  222. txtNewName.setText("");
  223. txtNewPass.setText("");
  224. }
  225. });
  226. btnAbout.addActionListener(new ActionListener() {
  227. public void actionPerformed(ActionEvent e) {
  228. aboutP.setVisible(true);
  229. }
  230. });
  231. btnRegister.setBounds(23, 10, 117, 29);
  232.  
  233. contentPane.add(label);
  234. contentPane.add(txtNewName);
  235. contentPane.add(txtNewPass);
  236. contentPane.add(txtUser);
  237. contentPane.add(btnLogin);
  238. contentPane.add(btnRegister);
  239. contentPane.add(btnAbout);
  240. contentPane.add(separator);
  241. contentPane.add(txtPass);
  242.  
  243.  
  244. return 0;
  245.  
  246. }
  247.  
  248. private void addPopup(Component component, final JPopupMenu popup) {
  249.  
  250. //Adds a listener to the Label. If clicked, open the menu
  251. component.addMouseListener(new MouseAdapter() {
  252. public void mousePressed(MouseEvent e) {
  253. if (e.isPopupTrigger() && SwingUtilities.isRightMouseButton(e)) {
  254. showMenu(e);
  255. }
  256. }
  257. public void mouseReleased(MouseEvent e) {
  258. if (e.isPopupTrigger() && SwingUtilities.isRightMouseButton(e)) {
  259. //Image imgMap = (BufferedImage) map;
  260.  
  261.  
  262. //clickLocation =
  263. showMenu(e);
  264. }
  265. }
  266. private void showMenu(MouseEvent e) {
  267. lastClickX = e.getX();
  268. lastClickY = e.getY();
  269. coordinates = "{" + lastClickX +"," + lastClickY +"}";
  270. System.out.println(coordinates);
  271. //Shows the popup at x, y of the MapComponent
  272. popup.show(e.getComponent(), e.getX(), e.getY());
  273. }
  274. });
  275. }
  276.  
  277.  
  278.  
  279. class MapComponent extends JComponent {
  280.  
  281. public MapComponent(){
  282. super();
  283. class MouseClickListener implements MouseListener
  284. {
  285. public void mousePressed(MouseEvent e){
  286. if(SwingUtilities.isRightMouseButton(e))
  287. {}
  288.  
  289. //repaint();
  290. }
  291. public void mouseClicked(MouseEvent e){
  292. repaint();
  293. }
  294. public void mouseReleased(MouseEvent e){}
  295. public void mouseEntered(MouseEvent e){}
  296. public void mouseExited(MouseEvent e){}
  297. }
  298. MouseListener clickListener = new MouseClickListener();
  299. this.addMouseListener(clickListener);
  300. }
  301.  
  302. public void paintComponent(Graphics g) {
  303. for(int i = 0; i < issues.size(); i++) {
  304. Graphics2D g2 = (Graphics2D) g;
  305. //System.out.println(issues.get(i).getIcon().toString());
  306. issues.get(i).getIcon().draw(g2);
  307. }
  308. }
  309. }
  310.  
  311.  
  312.  
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement