Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.io.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.util.*;
  6. import javax.swing.event.*;
  7.  
  8. public class Window extends JFrame {
  9.  
  10. JList list;
  11. JButton buttons;
  12. JComboBox<String> box;
  13. JTextField field;
  14. JPanel text;
  15. JRadioButton radioButton;
  16. private BildYta y;
  17.  
  18. public Window() {
  19. super("Inlupp 2");
  20. setLayout(new BorderLayout());
  21. setSize(600, 400);
  22.  
  23. // PLACERING
  24.  
  25. JPanel upper = new JPanel();
  26. add(upper, BorderLayout.NORTH);
  27.  
  28. JPanel leftCorner = new JPanel();
  29. leftCorner.setLayout(new BoxLayout(leftCorner, BoxLayout.Y_AXIS));
  30. upper.add(leftCorner);
  31.  
  32. JPanel rightCorner = new JPanel();
  33. rightCorner.setLayout(new BoxLayout(rightCorner, BoxLayout.Y_AXIS));
  34. add(rightCorner, BorderLayout.EAST);
  35.  
  36. JPanel lower = new JPanel();
  37. add(lower, BorderLayout.SOUTH);
  38.  
  39. // MENY + DROP DOWN
  40.  
  41. JMenuBar mbar = new JMenuBar();
  42. setJMenuBar(mbar);
  43.  
  44. JMenu archiveMenu = new JMenu("Archive");
  45. mbar.add(archiveMenu);
  46.  
  47. JMenuItem newMapItem = new JMenuItem("New Map");
  48. archiveMenu.add(newMapItem);
  49. newMapItem.addActionListener(new NewMapLyss());
  50.  
  51. JMenuItem loadPlacesItem = new JMenuItem("Load Places");
  52. archiveMenu.add(loadPlacesItem);
  53. loadPlacesItem.addActionListener(new LoadPlacesLyss());
  54.  
  55. JMenuItem saveItem = new JMenuItem("Save");
  56. archiveMenu.add(saveItem);
  57. saveItem.addActionListener(new SaveLyss());
  58.  
  59. JMenuItem exitItem = new JMenuItem("Exit");
  60. archiveMenu.add(exitItem);
  61. exitItem.addActionListener(new ExitLyss());
  62.  
  63. // RADIOKNAPPAR
  64.  
  65. radioButton = new JRadioButton("Named", true);
  66. JRadioButton describedRadioButton = new JRadioButton("Described");
  67. ButtonGroup rbg = new ButtonGroup();
  68. rbg.add(radioButton);
  69. rbg.add(describedRadioButton);
  70. leftCorner.add(radioButton);
  71. leftCorner.add(describedRadioButton);
  72.  
  73. // LABEL
  74.  
  75. JLabel categoriesLabel = new JLabel("Categories");
  76. rightCorner.add(categoriesLabel);
  77. categoriesLabel.setText("Categories");
  78.  
  79. // J-LIST
  80.  
  81. String[] communication = { "Bus", "Underground", "Train" };
  82.  
  83. JList<String> list = new JList<>(communication);
  84. rightCorner.add(list);
  85.  
  86. list.setVisibleRowCount(3);
  87.  
  88. list.setLayoutOrientation(JList.VERTICAL_WRAP);
  89. list.setFixedCellWidth(150);
  90. list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  91. //list.addListSelectionListener(new ListLyss());
  92.  
  93. // KNAPPAR
  94.  
  95. JTextField searchField = new JTextField("Search ");
  96. upper.add(searchField);
  97.  
  98. JButton searchButton = new JButton("Search");
  99. upper.add(searchButton);
  100. searchButton.addActionListener(new searchButtonLyss());
  101.  
  102. JButton hideButton = new JButton("Hide");
  103. upper.add(hideButton);
  104. hideButton.addActionListener(new hideButtonLyss());
  105.  
  106. JButton removeButton = new JButton("Remove");
  107. upper.add(removeButton);
  108. removeButton.addActionListener(new removeButtonLyss());
  109.  
  110. JButton coordinatesButton = new JButton("Coordinates");
  111. upper.add(coordinatesButton);
  112. coordinatesButton.addActionListener(new coordinatesButtonLyss());
  113.  
  114. JButton hideCategoryButton = new JButton("Hide category");
  115. rightCorner.add(hideCategoryButton);
  116. hideCategoryButton.addActionListener(new hideCategoryButtonLyss());
  117.  
  118. setDefaultCloseOperation(EXIT_ON_CLOSE);
  119. setVisible(true);
  120.  
  121. // LYSSNARE TILL KNAPPARNA
  122.  
  123. }
  124.  
  125. public class searchButtonLyss implements ActionListener {
  126. @Override
  127. public void actionPerformed(ActionEvent ave) {
  128. search();
  129. }
  130.  
  131. public void search() {
  132.  
  133. }
  134.  
  135. }
  136.  
  137. public class hideButtonLyss implements ActionListener {
  138. @Override
  139. public void actionPerformed(ActionEvent ave) {
  140. hide();
  141. }
  142.  
  143. public void hide() {
  144.  
  145. }
  146.  
  147. }
  148.  
  149. public class removeButtonLyss implements ActionListener {
  150. @Override
  151. public void actionPerformed(ActionEvent ave) {
  152. remove();
  153. }
  154.  
  155. public void remove() {
  156.  
  157. }
  158. }
  159.  
  160. public class coordinatesButtonLyss implements ActionListener {
  161. @Override
  162. public void actionPerformed(ActionEvent ave) {
  163. coordinates();
  164. }
  165.  
  166. public void coordinates() {
  167.  
  168. }
  169. }
  170.  
  171. public class hideCategoryButtonLyss implements ActionListener {
  172. @Override
  173. public void actionPerformed(ActionEvent ave) {
  174. hideCategory();
  175. }
  176.  
  177. public void hideCategory() {
  178.  
  179. }
  180. }
  181.  
  182. // LYSSNARE TILL DROP DOWN
  183.  
  184. class NewMapLyss implements ActionListener {
  185. public void actionPerformed(ActionEvent ave) {
  186.  
  187. String str = System.getProperty("user/images/skola.dir");
  188. JFileChooser jfc = new JFileChooser(str);
  189. int svar = jfc.showOpenDialog(Window.this);
  190. if (svar == JFileChooser.APPROVE_OPTION) {
  191. File file = jfc.getSelectedFile();
  192. String path = file.getAbsolutePath();
  193. y = new BildYta(path);
  194. JScrollPane scroll = new JScrollPane(y);
  195. add(scroll, BorderLayout.CENTER);
  196. validate();
  197. repaint();
  198.  
  199. }
  200. }
  201. }
  202.  
  203. // LYSSNARE TILL JLIST
  204.  
  205. // class ListLyss implements ListSelectionListener {
  206. // public void valueChanged(ListSelectionEvent lev) {
  207. // if (!lev.getValueIsAdjusting())
  208. // System.out.println(list.getSelectedValue());
  209. // }
  210. // }
  211.  
  212. class BildYta extends JLabel {
  213. private ImageIcon image;
  214.  
  215. BildYta(String path) {
  216. image = new ImageIcon(path);
  217. this.setIcon(image);
  218.  
  219. setPreferredSize(new Dimension(image.getIconWidth(), image.getIconHeight()));
  220.  
  221. }
  222.  
  223. public ImageIcon getImage() {
  224. return image;
  225. }
  226. }
  227.  
  228. class LoadPlacesLyss implements ActionListener {
  229. public void actionPerformed(ActionEvent ave) {
  230.  
  231. }
  232. }
  233.  
  234. class SaveLyss implements ActionListener {
  235. public void actionPerformed(ActionEvent ave) {
  236.  
  237. }
  238. }
  239.  
  240. class ExitLyss implements ActionListener {
  241. public void actionPerformed(ActionEvent ave) {
  242.  
  243. }
  244. }
  245.  
  246. public static void main(String[] args) {
  247. new Window();
  248. }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement